@name Chess Sim
@inputs P1:wirelink P2:wirelink V1:entity V2:entity
@outputs DWP
@persist Up Down Left Right Cancel Select Selected  
@persist PosVal Pval PreVal Board:array Pos:array Spawn1 DWI DWA DBI DBA
@persist Spawn Player End Del
@persist 
@trigger all

interval(100)


if(first()) {
entity():setColor(vec(),0)
PosVal = 1
Player = 1
DWI = 200
DBI = 200
DWA = 1
DBA = 1

#Settin up board
Board[1,vector]=vec(114,113,0)
Board[2,vector]=vec(81,113,0)
Board[3,vector]=vec(48,113,0)
Board[4,vector]=vec(16,113,0)
Board[5,vector]=vec(-16,113,0)
Board[6,vector]=vec(-48,113,0)
Board[7,vector]=vec(-81,113,0)
Board[8,vector]=vec(-114,113,0)
Board[9,vector]=vec(114,81,0)
Board[10,vector]=vec(81,81,0)
Board[11,vector]=vec(48,81,0)
Board[12,vector]=vec(16,81,0)
Board[13,vector]=vec(-16,81,0)
Board[14,vector]=vec(-48,81,0)
Board[15,vector]=vec(-81,81,0)
Board[16,vector]=vec(-114,81,0)
Board[17,vector]=vec(114,48,0)
Board[18,vector]=vec(81,48,0)
Board[19,vector]=vec(48,48,0)
Board[20,vector]=vec(16,48,0)
Board[21,vector]=vec(-16,48,0)
Board[22,vector]=vec(-48,48,0)
Board[23,vector]=vec(-81,48,0)
Board[24,vector]=vec(-114,48,0)
Board[25,vector]=vec(114,16,0)
Board[26,vector]=vec(81,16,0)
Board[27,vector]=vec(48,16,0)
Board[28,vector]=vec(16,16,0)
Board[29,vector]=vec(-16,16,0)
Board[30,vector]=vec(-48,16,0)
Board[31,vector]=vec(-81,16,0)
Board[32,vector]=vec(-114,16,0)
Board[33,vector]=vec(114,-16,0)
Board[34,vector]=vec(81,-16,0)
Board[35,vector]=vec(48,-16,0)
Board[36,vector]=vec(16,-16,0)
Board[37,vector]=vec(-16,-16,0)
Board[38,vector]=vec(-48,-16,0)
Board[39,vector]=vec(-81,-16,0)
Board[40,vector]=vec(-114,-16,0)
Board[41,vector]=vec(114,-48,0)
Board[42,vector]=vec(81,-48,0)
Board[43,vector]=vec(48,-48,0)
Board[44,vector]=vec(16,-48,0)
Board[45,vector]=vec(-16,-48,0)
Board[46,vector]=vec(-48,-48,0)
Board[47,vector]=vec(-81,-48,0)
Board[48,vector]=vec(-114,-48,0)
Board[49,vector]=vec(114,-81,0)
Board[50,vector]=vec(81,-81,0)
Board[51,vector]=vec(48,-81,0)
Board[52,vector]=vec(16,-81,0)
Board[53,vector]=vec(-16,-81,0)
Board[54,vector]=vec(-48,-81,0)
Board[55,vector]=vec(-81,-81,0)
Board[56,vector]=vec(-114,-81,0)
Board[57,vector]=vec(114,-113,0)
Board[58,vector]=vec(81,-113,0)
Board[59,vector]=vec(48,-113,0)
Board[60,vector]=vec(16,-113,0)
Board[61,vector]=vec(-16,-113,0)
Board[62,vector]=vec(-48,-113,0)
Board[63,vector]=vec(-81,-113,0)
Board[64,vector]=vec(-114,-113,0)

Pos[1,number]=1
Pos[2,number]=2
Pos[3,number]=3
Pos[4,number]=4
Pos[5,number]=5
Pos[6,number]=6
Pos[7,number]=7
Pos[8,number]=8
Pos[9,number]=9
Pos[10,number]=10
Pos[11,number]=11
Pos[12,number]=12
Pos[13,number]=13
Pos[14,number]=14
Pos[15,number]=15
Pos[16,number]=16
Pos[17,number]=-1
Pos[18,number]=-1
Pos[19,number]=-1
Pos[20,number]=-1
Pos[21,number]=-1
Pos[22,number]=-1
Pos[23,number]=-1
Pos[24,number]=-1
Pos[25,number]=-1
Pos[26,number]=-1
Pos[27,number]=-1
Pos[28,number]=-1
Pos[29,number]=-1
Pos[30,number]=-1
Pos[31,number]=-1
Pos[32,number]=-1
Pos[33,number]=-1
Pos[34,number]=-1
Pos[35,number]=-1
Pos[36,number]=-1
Pos[37,number]=-1
Pos[38,number]=-1
Pos[39,number]=-1
Pos[40,number]=-1
Pos[41,number]=-1
Pos[42,number]=-1
Pos[43,number]=-1
Pos[44,number]=-1
Pos[45,number]=-1
Pos[46,number]=-1
Pos[47,number]=-1
Pos[48,number]=-1
Pos[49,number]=49
Pos[50,number]=50
Pos[51,number]=51
Pos[52,number]=52
Pos[53,number]=53
Pos[54,number]=54
Pos[55,number]=55
Pos[56,number]=56
Pos[57,number]=57
Pos[58,number]=58
Pos[59,number]=59
Pos[61,number]=61
Pos[60,number]=60
Pos[62,number]=62
Pos[63,number]=63
Pos[64,number]=64

#Classes

holoCreate(100)
holoCreate(101)
holoModel(100,"hqcylinder2")
holoModel(101,"hqcylinder2")
timer("Spawn",5000)
}

if(clk("Spawn")) {
holoScale(100,vec(2,2,0.1))
holoScale(101,vec(2,2,0.1))
holoColor(100,vec(0,255,0),150)
holoColor(101,vec(0,0,255),150)
}

# SPAWNING THE BOARD
#White
#
# 1: Rook
# 2: Knight
# 3: Bishop
# 4: Queen
# 5: King
# 6: Bishop
# 7: Knight
# 8: Rook
# 9 - 16: Pawns
#
#Black
#
# 57: Rook
# 58: Knight
# 59: Bishop
# 61: King
# 60: Queen
# 62: Bishop
# 63: Knight
# 64: Rook
# 49 - 56: Pawns
#


#Setting up Peices
if(Spawn <= 64) {Spawn++
if(Spawn == 18) {Spawn = 49}
holoCreate(Spawn,entity():pos()+Board:vector(Spawn))
holoDelete(65)
holoDelete(17)
holoDelete(65)
}
Spawn1 = Spawn - 1
if(Spawn >= 49) {holoColor(Spawn1,vec(0,0,0))}
if(Spawn1 >= 9 & Spawn1 <= 56) {holoModel(Spawn1,"hqcone") , holoScale(Spawn1,vec(2,2,3))}
if(Spawn1 == 1 | Spawn1 == 8 | Spawn1 == 57 | Spawn1 == 64) {holoModel(Spawn1,"hqcylinder2"),holoScale(Spawn1,vec(1,1,3))}
if(Spawn1 == 2 | Spawn1 == 7 | Spawn1 == 58 | Spawn1 == 63) {holoModel(Spawn1,"hqcube"),holoScale(Spawn1,vec(0.5,1.5,3.5)),if(Spawn1==2 | Spawn1 == 7) {holoAng(Spawn1,ang(0,0,0))}, if(Spawn1 == 58| Spawn1 == 63) {holoAng(Spawn1,ang(0,0,0))}}
if(Spawn1 == 3 | Spawn1 == 6 | Spawn1 == 59 | Spawn1 == 62) {holoModel(Spawn1,"hqcylinder2"),holoScale(Spawn1,vec(0.5,0.5,4))}
if(Spawn1 == 4 | Spawn1 == 60) {holoModel(Spawn1,"pyramid"), holoScale(Spawn1,vec(2,2,7))}
if(Spawn1 == 5 | Spawn1 == 61) {holoModel(Spawn1,"hqtorus"), holoScale(Spawn1,vec(1,1,25))}

# Select
if(Player == 1) {
Up = P1:number("W")
Down = P1:number("S")
Left = P1:number("A")
Right = P1:number("D")
Select = P1:number("Mouse1")
Cancel = P1:number("Mouse2")
PMI = 9
PMMA = 16
K1 = 2
K2 = 7
B1 = 3
B2 = 6
R1 = 1
R2 = 8 
Q = 4
K = 5 
PMM = 1
PPMi = 1
PPMa = 16
OPPMi = 49
OPPMa = 64
} else {
Up = P2:number("W")
Down = P2:number("S")
Left = P2:number("A")
Right = P2:number("D")
Select = P2:number("Mouse1")
Cancel = P2:number("Mouse2")
PMI = 48
PMMA = 56
K1 = 58
K2 = 63
B1 = 59
B2 = 62
R1 = 57
R2 = 64
R3 = 60
K = 61
Q = 60
PMM = -1
PPMi = 49
PPMa = 64
OPPMi = 1
OPPMa = 16
}

if(End) {
interval(0)
if(Pos:number(PosVal)==-1){Del = 0} else {Del = Pos:number(PosVal)
if(Pos:number(PosVal) > 9 & Pos:number(PosVal) < 16) {DWP = 1}
if(Pos:number(PosVal) > 49 & Pos:number(PosVal) < 56) {DBP = 1}
if(Pos:number(PosVal) == 1 | Pos:number(PosVal) == 8) {DWR = 1}
if(Pos:number(PosVal) == 57 | Pos:number(PosVal) == 64) {DBR = 1}
if(Pos:number(PosVal) == 3 | Pos:number(PosVal) == 6) {DWB = 1}
if(Pos:number(PosVal) == 52 | Pos:number(PosVal) == 59) {DBB = 1}
if(Pos:number(PosVal) == 2 | Pos:number(PosVal) == 7) {DWKN = 1}
if(Pos:number(PosVal) == 58 | Pos:number(PosVal) == 63) {DBKN = 1}
if(Pos:number(PosVal) == 5) {DWK = 1}
if(Pos:number(PosVal) == 4) {DWQ = 1}
if(Pos:number(PosVal) == 61) {DBK = 1}
if(Pos:number(PosVal) == 60) {DBQ = 1}
}
holoPos(Pval,entity():pos()+Board:vector(PosVal)),holoDelete(Del)
Pos[PreVal,number]=-1
Pos[PosVal,number]=Pval
Selected = 0
Player++ 
if(Player > 2) {Player = 1, V1:hintDriver("Your Turn",2),V1:soundPlay(1,0,"ambient/water/drip3.wav")}
if(Player == 2) {V2:hintDriver("Your Turn",2),V2:soundPlay(1,0,"ambient/water/drip3.wav")}
    End = 0
}

# Select Movement
if(Player == 1) {
if(!Selected) {
holoPos(100,entity():pos()+Board:vector(PosVal))
}
holoPos(101,entity():pos()+Board:vector(PosVal)+vec(0,0,1))
if(PosVal >=1 | PosVal <= 64) {
if(Up & $Up & (PosVal + 8) <= 64) {PosVal = PosVal + (8*PMM)}
if(Down & $Down & (PosVal - 8) > 0) {PosVal = PosVal - (8*PMM)}
if(Left & $Left & (PosVal - 1) > 0) {PosVal = PosVal - (1*PMM)}
if(Right & $Right & (PosVal + 1) <= 64) {PosVal = PosVal + (1*PMM)}
}}

if(Player == 2) {
if(!Selected) {
holoPos(100,entity():pos()+Board:vector(PosVal))
}
holoPos(101,entity():pos()+Board:vector(PosVal)+vec(0,0,1))
if(PosVal >=1 | PosVal <= 64) {
if(Up & $Up & (PosVal - 8) > 0) {PosVal = PosVal - 8}
if(Down & $Down & (PosVal + 8) <= 64) {PosVal = PosVal + 8}
if(Left & $Left & (PosVal + 1) <= 64) {PosVal = PosVal + 1}
if(Right & $Right & (PosVal - 1) > 0) {PosVal = PosVal - 1}
}}

if(Select & $Select & inrange(Pos:number(PosVal),PPMi,PPMa)) {Selected = 1,
Pval = Pos:number(PosVal)
PreVal = PosVal}



if(Selected) {
if(Cancel & $Cancel) {Selected = 0}

#Pawn Movement
if(inrange(Pval,PMI,PMMA)) {
if(Pos:number(PreVal+(8*PMM))== -1) {
    holoCreate(150,entity():pos()+Board:vector(PreVal+(8*PMM)),vec(2,2,0.1))
    holoModel(150,"hqcylinder2")
    holoColor(150,vec(255,255,0),150)
    if(Select & $Select & PosVal == PreVal + (8*PMM)) {End =1,holoDelete(150)}
    }
if(inrange(PreVal,PMI,PMMA)&Pos:number(PreVal+(8*PMM)) == -1) {
   holoCreate(151,entity():pos()+Board:vector(PreVal+(16*PMM)),vec(2,2,0.1))
   holoModel(151,"hqcylinder2")
   holoColor(151,vec(255,255,0),150)
   if(Select & $Select & PosVal == PreVal+ (16*PMM)) {End =1,holoDelete(150),holoDelete(151)}
    }


    #Pawn Attack
if(Player == 1) {
    if(Pos:number(PreVal+9) >= 49) {
    holoCreate(152,entity():pos()+Board:vector(PreVal+9),vec(2,2,0.1))
    holoModel(152,"hqcylinder2")
    if(holoEntity(Pval):pos():distance(holoEntity(152):pos()) > 70) {holoColor(152,vec(),0)} else {
    holoColor(152,vec(255,0,0),200)}
    if(Select & $Select & PosVal == PreVal+ 9) {End =1,holoDelete(152)}
    }
    
    if(Pos:number(PreVal+7) >= 49) {
    holoCreate(153,entity():pos()+Board:vector(PreVal+7),vec(2,2,0.1))
    holoModel(153,"hqcylinder2")
    if(holoEntity(Pval):pos():distance(holoEntity(153):pos()) > 70) {holoColor(153,vec(),0)} else {
    holoColor(153,vec(255,0,0),200)}
    if(Select & $Select & PosVal == PreVal+7) {End =1,holoDelete(Pos:number(PreVal+7)),holoDelete(152)}
    }
}# End PWN PLR 1
if(Player == 2) {
    if(Pos:number(PreVal-9) <= 18 & Pos:number(PreVal-9) > 0) {
    holoCreate(152,entity():pos()+Board:vector(PreVal-9),vec(2,2,0.1))
    holoModel(152,"hqcylinder2")
    if(holoEntity(Pval):pos():distance(holoEntity(152):pos()) > 70) {holoColor(152,vec(),0)} else {
    holoColor(152,vec(255,0,0),200)}
    if(Select & $Select & PosVal == PreVal- 9) {End =1,holoDelete(152)}
    }
    
    if(Pos:number(PreVal-7) <= 18 & Pos:number(PreVal-7) > 0) {
    holoCreate(153,entity():pos()+Board:vector(PreVal-7),vec(2,2,0.1))
    holoModel(153,"hqcylinder2")
    if(holoEntity(Pval):pos():distance(holoEntity(153):pos()) > 70) {holoColor(153,vec(),0)} else {
    holoColor(153,vec(255,0,0),200)}
    if(Select & $Select & PosVal == PreVal-7) {End =1,holoDelete(Pos:number(PreVal+7)),holoDelete(152)}
    }
}# End PWN PLR 2
}# End Pawn

#Knight Movement
if(Pval == K1 | Pval == K2) {
    if(Pos:number(PreVal+17) == -1 | inrange(Pos:number(PreVal+17),OPPMi,OPPMa)) {
    holoCreate(150,entity():pos()+Board:vector(PreVal+17),vec(2,2,0.1))
    holoModel(150,"hqcylinder2")
if(holoEntity(Pval):pos():distance(holoEntity(150):pos()) > 100) {holoColor(150,vec(),0)} else {
if(inrange(Pos:number(PreVal+17),OPPMi,OPPMa)) {holoColor(150,vec(255,0,0),200)} else {holoColor(150,vec(255,255,0),150)}}}

    if(Pos:number(PreVal+15) == -1 | inrange(Pos:number(PreVal+15),OPPMi,OPPMa)) {
    holoCreate(151,entity():pos()+Board:vector(PreVal+15),vec(2,2,0.1))
    holoModel(151,"hqcylinder2")
if(holoEntity(Pval):pos():distance(holoEntity(151):pos()) > 100) {holoColor(151,vec(),0)} else {
if(inrange(Pos:number(PreVal+15),OPPMi,OPPMa)) {holoColor(151,vec(255,0,0),200)} else {holoColor(151,vec(255,255,0),150)}}}

    if(Pos:number(PreVal+6) == -1 | inrange(Pos:number(PreVal+6),OPPMi,OPPMa)) {
    holoCreate(152,entity():pos()+Board:vector(PreVal+6),vec(2,2,0.1))
    holoModel(152,"hqcylinder2")
if(holoEntity(Pval):pos():distance(holoEntity(152):pos()) > 100) {holoColor(152,vec(),0)} else {
if(inrange(Pos:number(PreVal+6),OPPMi,OPPMa)) {holoColor(152,vec(255,0,0),200)} else {holoColor(152,vec(255,255,0),150)}}}

    if(Pos:number(PreVal+10) == -1 | inrange(Pos:number(PreVal+10),OPPMi,OPPMa)) {
    holoCreate(153,entity():pos()+Board:vector(PreVal+10),vec(2,2,0.1))
    holoModel(153,"hqcylinder2")
if(holoEntity(Pval):pos():distance(holoEntity(153):pos()) > 100) {holoColor(153,vec(),0)} else {
if(inrange(Pos:number(PreVal+10),OPPMi,OPPMa)) {holoColor(153,vec(255,0,0),200)} else {holoColor(153,vec(255,255,0),150)}}}

    if(Pos:number(PreVal-17) == -1 | inrange(Pos:number(PreVal-17),OPPMi,OPPMa)) {
    holoCreate(154,entity():pos()+Board:vector(PreVal-17),vec(2,2,0.1))
    holoModel(154,"hqcylinder2")
if(holoEntity(Pval):pos():distance(holoEntity(154):pos()) > 100) {holoColor(154,vec(),0)} else {
if(inrange(Pos:number(PreVal-17),OPPMi,OPPMa)) {holoColor(154,vec(255,0,0),200)} else {holoColor(154,vec(255,255,0),150)}}}

    if(Pos:number(PreVal-15) == -1 | inrange(Pos:number(PreVal-15),OPPMi,OPPMa)) {
    holoCreate(155,entity():pos()+Board:vector(PreVal-15),vec(2,2,0.1))
    holoModel(155,"hqcylinder2")
if(holoEntity(Pval):pos():distance(holoEntity(155):pos()) > 100) {holoColor(155,vec(),0)} else {
if(inrange(Pos:number(PreVal-15),OPPMi,OPPMa)) {holoColor(155,vec(255,0,0),200)} else {holoColor(155,vec(255,255,0),150)}}}

    if(Pos:number(PreVal-6) == -1 | inrange(Pos:number(PreVal-6),OPPMi,OPPMa)) {
    holoCreate(156,entity():pos()+Board:vector(PreVal-6),vec(2,2,0.1))
    holoModel(156,"hqcylinder2")
if(holoEntity(Pval):pos():distance(holoEntity(156):pos()) > 100) {holoColor(156,vec(),0)} else {
if(inrange(Pos:number(PreVal-6),OPPMi,OPPMa)) {holoColor(156,vec(255,0,0),200)} else {holoColor(156,vec(255,255,0),150)}}}
    if(Pos:number(PreVal-10) == -1 | inrange(Pos:number(PreVal-10),OPPMi,OPPMa)) {
    holoCreate(157,entity():pos()+Board:vector(PreVal-10),vec(2,2,0.1))
    holoModel(157,"hqcylinder2")
if(holoEntity(Pval):pos():distance(holoEntity(157):pos()) > 100) {holoColor(157,vec(),0)} else {
if(inrange(Pos:number(PreVal-10),OPPMi,OPPMa)) {holoColor(157,vec(255,0,0),200)} else {holoColor(157,vec(255,255,0),150)}}}

   if(Select & $Select & PosVal == PreVal+ 17) {End =1}
   if(Select & $Select & PosVal == PreVal+ 15) {End =1}
   if(Select & $Select & PosVal == PreVal+ 6) {End =1}
   if(Select & $Select & PosVal == PreVal+ 10) {End =1}
   if(Select & $Select & PosVal == PreVal- 17) {End =1}
   if(Select & $Select & PosVal == PreVal- 15) {End =1}
   if(Select & $Select & PosVal == PreVal- 6) {End =1}
   if(Select & $Select & PosVal == PreVal- 10) {End =1}
    }
#King Movement
if(Pval == K) {
    if(Pos:number(PreVal+8) == -1 | inrange(Pos:number(PreVal+8),OPPMi,OPPMa)) {
    holoCreate(150,entity():pos()+Board:vector(PreVal+8),vec(2,2,0.1))
    holoModel(150,"hqcylinder2")
    if(holoEntity(Pval):pos():distance(holoEntity(150):pos()) > 70) {holoColor(150,vec(),0)} else {
    if(inrange(Pos:number(PreVal+8),OPPMi,OPPMa)) {holoColor(150,vec(255,0,0),200)} else {holoColor(150,vec(255,255,0),150)}}}
    
    if(Pos:number(PreVal+7) == -1 | inrange(Pos:number(PreVal+7),OPPMi,OPPMa)) {
    holoCreate(151,entity():pos()+Board:vector(PreVal+7),vec(2,2,0.1))
    holoModel(151,"hqcylinder2")
    if(holoEntity(Pval):pos():distance(holoEntity(151):pos()) > 70) {holoColor(151,vec(),0)} else {
    if(inrange(Pos:number(PreVal+7),OPPMi,OPPMa)) {holoColor(151,vec(255,0,0),200)} else {holoColor(151,vec(255,255,0),150)}}}
    
    if(Pos:number(PreVal+9) == -1 | inrange(Pos:number(PreVal+9),OPPMi,OPPMa)) {
    holoCreate(152,entity():pos()+Board:vector(PreVal+9),vec(2,2,0.1))
    holoModel(152,"hqcylinder2")
    if(holoEntity(Pval):pos():distance(holoEntity(152):pos()) > 70) {holoColor(152,vec(),0)} else {
    if(inrange(Pos:number(PreVal+9),OPPMi,OPPMa)) {holoColor(152,vec(255,0,0),200)} else {holoColor(152,vec(255,255,0),150)}}}
    
    if(Pos:number(PreVal+1) == -1 | inrange(Pos:number(PreVal+1),OPPMi,OPPMa)) {
    holoCreate(153,entity():pos()+Board:vector(PreVal+1),vec(2,2,0.1))
    holoModel(153,"hqcylinder2")
    if(holoEntity(Pval):pos():distance(holoEntity(153):pos()) > 70) {holoColor(153,vec(),0)} else {
    if(inrange(Pos:number(PreVal+1),OPPMi,OPPMa)) {holoColor(153,vec(255,0,0),200)} else {holoColor(153,vec(255,255,0),150)}}}
    
    if(Pos:number(PreVal-1) == -1 | inrange(Pos:number(PreVal-1),OPPMi,OPPMa)) {
    holoCreate(154,entity():pos()+Board:vector(PreVal-1),vec(2,2,0.1))
    holoModel(154,"hqcylinder2")
    if(holoEntity(Pval):pos():distance(holoEntity(154):pos()) > 70) {holoColor(154,vec(),0)} else {
    if(inrange(Pos:number(PreVal-1),OPPMi,OPPMa)) {holoColor(154,vec(255,0,0),200)} else {holoColor(154,vec(255,255,0),150)}}}
    
    if(Pos:number(PreVal-8) == -1 | inrange(Pos:number(PreVal-8),OPPMi,OPPMa)) {
    holoCreate(155,entity():pos()+Board:vector(PreVal-8),vec(2,2,0.1))
    holoModel(155,"hqcylinder2")
    if(holoEntity(Pval):pos():distance(holoEntity(155):pos()) > 70) {holoColor(155,vec(),0)} else {
    if(inrange(Pos:number(PreVal-8),OPPMi,OPPMa)) {holoColor(155,vec(255,0,0),200)} else {holoColor(155,vec(255,255,0),150)}}}
    
    if(Pos:number(PreVal-7) == -1 | inrange(Pos:number(PreVal-7),OPPMi,OPPMa)) {
    holoCreate(156,entity():pos()+Board:vector(PreVal-7),vec(2,2,0.1))
    holoModel(156,"hqcylinder2")
    if(holoEntity(Pval):pos():distance(holoEntity(156):pos()) > 70) {holoColor(156,vec(),0)} else {
    if(inrange(Pos:number(PreVal-7),OPPMi,OPPMa)) {holoColor(156,vec(255,0,0),200)} else {holoColor(156,vec(255,255,0),150)}}}
    
    if(Pos:number(PreVal-9) == -1 | inrange(Pos:number(PreVal-9),OPPMi,OPPMa)) {
    holoCreate(157,entity():pos()+Board:vector(PreVal-9),vec(2,2,0.1))
    holoModel(157,"hqcylinder2")
    if(holoEntity(Pval):pos():distance(holoEntity(157):pos()) > 70) {holoColor(157,vec(),0)} else {
    if(inrange(Pos:number(PreVal-9),OPPMi,OPPMa)) {holoColor(157,vec(255,0,0),200)} else {holoColor(157,vec(255,255,0),150)}}}
   
   if(Select & $Select & PosVal == PreVal+ 8) {End =1}
   if(Select & $Select & PosVal == PreVal+7) {End =1}
   if(Select & $Select & PosVal == PreVal+9) {End =1}
   if(Select & $Select & PosVal == PreVal+1) {End =1}
   if(Select & $Select & PosVal == PreVal-1) {End =1}
   if(Select & $Select & PosVal == PreVal- 8) {End =1}
   if(Select & $Select & PosVal == PreVal- 9) {End =1}
   if(Select & $Select & PosVal == PreVal-7) {End =1}

    #Castling
    if(Player == 1) {
    if(Pos:number(Pval+1) == -1 & Pos:number(Pval+2) == -1 & Pos:number(Pval+3) == 8) {
    holoCreate(158,entity():pos()+Board:vector(PreVal+2),vec(2,2,0.1))
    holoModel(158,"hqcylinder2")
    holoColor(158,vec(255,255,0),200)
    if(Select & $Select & PosVal == PreVal+2) {
        Pos[6,number]=8
        Pos[8,number]=-1
        holoPos(8,entity():pos()+Board:vector(6))
        End= 1}
    }
    }
    
    if(Player == 2) {
    if(Pos:number(Pval+1) == -1 & Pos:number(Pval+2) == -1 & Pos:number(Pval+3) == 64) {
    holoCreate(158,entity():pos()+Board:vector(PreVal+2),vec(2,2,0.1))
    holoModel(158,"hqcylinder2")
    holoColor(158,vec(255,255,0),200)
    if(Select & $Select & PosVal == PreVal+2) {
        Pos[62,number]=64
        Pos[64,number]=-1
        holoPos(64,entity():pos()+Board:vector(62))
        End= 1}
    }
    }


}# End If King
#Bishop
if(Pval == B1 | Pval == B2) {
        
    if(Select & $Select & PosVal == PreVal + 9) {End =1}
    if(Select & $Select & PosVal == PreVal + 18 & Pos:number(PreVal+9) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal + 27 & Pos:number(PreVal+9) == -1 & Pos:number(PreVal+18) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal + 36 & Pos:number(PreVal+9) == -1 & Pos:number(PreVal+18) == -1 & Pos:number(PreVal+27) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal + 45 & Pos:number(PreVal+9) == -1 & Pos:number(PreVal+18) == -1 & Pos:number(PreVal+27) == -1 & Pos:number(PreVal+36) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal + 54 & Pos:number(PreVal+9) == -1 & Pos:number(PreVal+18) == -1 & Pos:number(PreVal+27) == -1 & Pos:number(PreVal+36) == -1 & Pos:number(PreVal+ 45) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal + 63 & Pos:number(PreVal+9) == -1 & Pos:number(PreVal+18) == -1 & Pos:number(PreVal+27) == -1 & Pos:number(PreVal+36) == -1 & Pos:number(PreVal+ 45) == -1 & Pos:number(PreVal+ 54) == -1) {End =1}

    if(Select & $Select & PosVal == PreVal - 9) {End =1}
    if(Select & $Select & PosVal == PreVal - 18 & Pos:number(PreVal-9) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal - 27 & Pos:number(PreVal-9) == -1 & Pos:number(PreVal-18) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal - 36 & Pos:number(PreVal-9) == -1 & Pos:number(PreVal-18) == -1 & Pos:number(PreVal-27) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal - 45 & Pos:number(PreVal-9) == -1 & Pos:number(PreVal-18) == -1 & Pos:number(PreVal-27) == -1 & Pos:number(PreVal-36) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal - 54 & Pos:number(PreVal-9) == -1 & Pos:number(PreVal-18) == -1 & Pos:number(PreVal-27) == -1 & Pos:number(PreVal-36) == -1 & Pos:number(PreVal- 45) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal - 63 & Pos:number(PreVal-9) == -1 & Pos:number(PreVal-18) == -1 & Pos:number(PreVal-27) == -1 & Pos:number(PreVal-36) == -1 & Pos:number(PreVal- 45) == -1 & Pos:number(PreVal- 54) == -1) {End =1}

    if(Select & $Select & PosVal == PreVal + 7) {End =1}
    if(Select & $Select & PosVal == PreVal + 14 & Pos:number(PreVal+7) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal + 21 & Pos:number(PreVal+7) == -1 & Pos:number(PreVal+14) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal + 28 & Pos:number(PreVal+7) == -1 & Pos:number(PreVal+14) == -1 & Pos:number(PreVal+21) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal + 35 & Pos:number(PreVal+7) == -1 & Pos:number(PreVal+14) == -1 & Pos:number(PreVal+21) == -1 & Pos:number(PreVal+28) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal + 42 & Pos:number(PreVal+7) == -1 & Pos:number(PreVal+14) == -1 & Pos:number(PreVal+21) == -1 & Pos:number(PreVal+28) == -1 & Pos:number(PreVal+ 35) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal + 49 & Pos:number(PreVal+7) == -1 & Pos:number(PreVal+14) == -1 & Pos:number(PreVal+21) == -1 & Pos:number(PreVal+28) == -1 & Pos:number(PreVal+ 35) == -1 & Pos:number(PreVal+42) == -1) {End =1}

    if(Select & $Select & PosVal == PreVal - 7) {End =1}
    if(Select & $Select & PosVal == PreVal - 14 & Pos:number(PreVal-7) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal - 21 & Pos:number(PreVal-7) == -1 & Pos:number(PreVal-14) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal - 28 & Pos:number(PreVal-7) == -1 & Pos:number(PreVal-14) == -1 & Pos:number(PreVal-21) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal - 35 & Pos:number(PreVal-7) == -1 & Pos:number(PreVal-14) == -1 & Pos:number(PreVal-21) == -1 & Pos:number(PreVal-28) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal - 42 & Pos:number(PreVal-7) == -1 & Pos:number(PreVal-14) == -1 & Pos:number(PreVal-21) == -1 & Pos:number(PreVal-28) == -1 & Pos:number(PreVal- 35) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal - 49 & Pos:number(PreVal-7) == -1 & Pos:number(PreVal-14) == -1 & Pos:number(PreVal-21) == -1 & Pos:number(PreVal-28) == -1 & Pos:number(PreVal- 35) == -1 & Pos:number(PreVal-42) == -1) {End =1}

}# End Bishop
# Rook
if(Pval == R1 | Pval == R2) {

    if(Select & $Select & PosVal == PreVal + 8) {End =1}
    if(Select & $Select & PosVal == PreVal + 16 & Pos:number(PreVal+8) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal + 24 & Pos:number(PreVal+8) == -1 & Pos:number(PreVal+16) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal + 32 & Pos:number(PreVal+8) == -1 & Pos:number(PreVal+16) == -1 & Pos:number(PreVal+24) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal + 40 & Pos:number(PreVal+8) == -1 & Pos:number(PreVal+16) == -1 & Pos:number(PreVal+24) == -1 & Pos:number(PreVal+32) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal + 48 & Pos:number(PreVal+8) == -1 & Pos:number(PreVal+16) == -1 & Pos:number(PreVal+24) == -1 & Pos:number(PreVal+32) == -1 & Pos:number(PreVal+ 40) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal + 56 & Pos:number(PreVal+8) == -1 & Pos:number(PreVal+16) == -1 & Pos:number(PreVal+24) == -1 & Pos:number(PreVal+32) == -1 & Pos:number(PreVal+ 40) == -1 & Pos:number(PreVal+ 48) == -1) {End =1}

    if(Select & $Select & PosVal == PreVal - 8) {End =1}
    if(Select & $Select & PosVal == PreVal - 16 & Pos:number(PreVal-8) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal - 24 & Pos:number(PreVal-8) == -1 & Pos:number(PreVal-16) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal - 32 & Pos:number(PreVal-8) == -1 & Pos:number(PreVal-16) == -1 & Pos:number(PreVal-24) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal - 40 & Pos:number(PreVal-8) == -1 & Pos:number(PreVal-16) == -1 & Pos:number(PreVal-24) == -1 & Pos:number(PreVal-32) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal - 48 & Pos:number(PreVal-8) == -1 & Pos:number(PreVal-16) == -1 & Pos:number(PreVal-24) == -1 & Pos:number(PreVal-32) == -1 & Pos:number(PreVal- 40) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal - 56 & Pos:number(PreVal-8) == -1 & Pos:number(PreVal-16) == -1 & Pos:number(PreVal-24) == -1 & Pos:number(PreVal-32) == -1 & Pos:number(PreVal- 40) == -1 & Pos:number(PreVal- 48) == -1) {End =1}

    if(Select & $Select & PosVal == PreVal + 1) {End =1}
    if(Select & $Select & PosVal == PreVal + 2 & Pos:number(PreVal+1) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal + 3 & Pos:number(PreVal+1) == -1 & Pos:number(PreVal+2) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal + 4 & Pos:number(PreVal+1) == -1 & Pos:number(PreVal+2) == -1 & Pos:number(PreVal+3) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal + 5 & Pos:number(PreVal+1) == -1 & Pos:number(PreVal+2) == -1 & Pos:number(PreVal+3) == -1 & Pos:number(PreVal+4) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal + 6 & Pos:number(PreVal+1) == -1 & Pos:number(PreVal+2) == -1 & Pos:number(PreVal+3) == -1 & Pos:number(PreVal+4) == -1 & Pos:number(PreVal+ 5) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal + 7 & Pos:number(PreVal+1) == -1 & Pos:number(PreVal+2) == -1 & Pos:number(PreVal+3) == -1 & Pos:number(PreVal+4) == -1 & Pos:number(PreVal+ 5) == -1 & Pos:number(PreVal+ 6) == -1) {End =1}

    if(Select & $Select & PosVal == PreVal - 1) {End =1}
    if(Select & $Select & PosVal == PreVal - 2 & Pos:number(PreVal-1) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal - 3 & Pos:number(PreVal-1) == -1 & Pos:number(PreVal-2) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal - 4 & Pos:number(PreVal-1) == -1 & Pos:number(PreVal-2) == -1 & Pos:number(PreVal-3) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal - 5 & Pos:number(PreVal-1) == -1 & Pos:number(PreVal-2) == -1 & Pos:number(PreVal-3) == -1 & Pos:number(PreVal-4) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal - 6 & Pos:number(PreVal-1) == -1 & Pos:number(PreVal-2) == -1 & Pos:number(PreVal-3) == -1 & Pos:number(PreVal-4) == -1 & Pos:number(PreVal-5) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal - 7 & Pos:number(PreVal-1) == -1 & Pos:number(PreVal-2) == -1 & Pos:number(PreVal-3) == -1 & Pos:number(PreVal-4) == -1 & Pos:number(PreVal-5) == -1 & Pos:number(PreVal- 6) == -1) {End =1}
}# End Rook

# Queen
if(Pval == Q) {
    
    if(Select & $Select & PosVal == PreVal + 9) {End =1}
    if(Select & $Select & PosVal == PreVal + 18 & Pos:number(PreVal+9) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal + 27 & Pos:number(PreVal+9) == -1 & Pos:number(PreVal+18) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal + 36 & Pos:number(PreVal+9) == -1 & Pos:number(PreVal+18) == -1 & Pos:number(PreVal+27) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal + 45 & Pos:number(PreVal+9) == -1 & Pos:number(PreVal+18) == -1 & Pos:number(PreVal+27) == -1 & Pos:number(PreVal+36) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal + 54 & Pos:number(PreVal+9) == -1 & Pos:number(PreVal+18) == -1 & Pos:number(PreVal+27) == -1 & Pos:number(PreVal+36) == -1 & Pos:number(PreVal+ 45) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal + 63 & Pos:number(PreVal+9) == -1 & Pos:number(PreVal+18) == -1 & Pos:number(PreVal+27) == -1 & Pos:number(PreVal+36) == -1 & Pos:number(PreVal+ 45) == -1 & Pos:number(PreVal+ 54) == -1) {End =1}

    if(Select & $Select & PosVal == PreVal - 9) {End =1}
    if(Select & $Select & PosVal == PreVal - 18 & Pos:number(PreVal-9) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal - 27 & Pos:number(PreVal-9) == -1 & Pos:number(PreVal-18) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal - 36 & Pos:number(PreVal-9) == -1 & Pos:number(PreVal-18) == -1 & Pos:number(PreVal-27) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal - 45 & Pos:number(PreVal-9) == -1 & Pos:number(PreVal-18) == -1 & Pos:number(PreVal-27) == -1 & Pos:number(PreVal-36) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal - 54 & Pos:number(PreVal-9) == -1 & Pos:number(PreVal-18) == -1 & Pos:number(PreVal-27) == -1 & Pos:number(PreVal-36) == -1 & Pos:number(PreVal- 45) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal - 63 & Pos:number(PreVal-9) == -1 & Pos:number(PreVal-18) == -1 & Pos:number(PreVal-27) == -1 & Pos:number(PreVal-36) == -1 & Pos:number(PreVal- 45) == -1 & Pos:number(PreVal- 54) == -1) {End =1}

    if(Select & $Select & PosVal == PreVal + 7) {End =1}
    if(Select & $Select & PosVal == PreVal + 14 & Pos:number(PreVal+7) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal + 21 & Pos:number(PreVal+7) == -1 & Pos:number(PreVal+14) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal + 28 & Pos:number(PreVal+7) == -1 & Pos:number(PreVal+14) == -1 & Pos:number(PreVal+21) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal + 35 & Pos:number(PreVal+7) == -1 & Pos:number(PreVal+14) == -1 & Pos:number(PreVal+21) == -1 & Pos:number(PreVal+28) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal + 42 & Pos:number(PreVal+7) == -1 & Pos:number(PreVal+14) == -1 & Pos:number(PreVal+21) == -1 & Pos:number(PreVal+28) == -1 & Pos:number(PreVal+ 35) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal + 49 & Pos:number(PreVal+7) == -1 & Pos:number(PreVal+14) == -1 & Pos:number(PreVal+21) == -1 & Pos:number(PreVal+28) == -1 & Pos:number(PreVal+ 35) == -1 & Pos:number(PreVal+42) == -1) {End =1}

    if(Select & $Select & PosVal == PreVal - 7) {End =1}
    if(Select & $Select & PosVal == PreVal - 14 & Pos:number(PreVal-7) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal - 21 & Pos:number(PreVal-7) == -1 & Pos:number(PreVal-14) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal - 28 & Pos:number(PreVal-7) == -1 & Pos:number(PreVal-14) == -1 & Pos:number(PreVal-21) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal - 35 & Pos:number(PreVal-7) == -1 & Pos:number(PreVal-14) == -1 & Pos:number(PreVal-21) == -1 & Pos:number(PreVal-28) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal - 42 & Pos:number(PreVal-7) == -1 & Pos:number(PreVal-14) == -1 & Pos:number(PreVal-21) == -1 & Pos:number(PreVal-28) == -1 & Pos:number(PreVal- 35) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal - 49 & Pos:number(PreVal-7) == -1 & Pos:number(PreVal-14) == -1 & Pos:number(PreVal-21) == -1 & Pos:number(PreVal-28) == -1 & Pos:number(PreVal- 35) == -1 & Pos:number(PreVal-42) == -1) {End =1}

    if(Select & $Select & PosVal == PreVal + 8) {End =1}
    if(Select & $Select & PosVal == PreVal + 16 & Pos:number(PreVal+8) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal + 24 & Pos:number(PreVal+8) == -1 & Pos:number(PreVal+16) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal + 32 & Pos:number(PreVal+8) == -1 & Pos:number(PreVal+16) == -1 & Pos:number(PreVal+24) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal + 40 & Pos:number(PreVal+8) == -1 & Pos:number(PreVal+16) == -1 & Pos:number(PreVal+24) == -1 & Pos:number(PreVal+32) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal + 48 & Pos:number(PreVal+8) == -1 & Pos:number(PreVal+16) == -1 & Pos:number(PreVal+24) == -1 & Pos:number(PreVal+32) == -1 & Pos:number(PreVal+ 40) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal + 56 & Pos:number(PreVal+8) == -1 & Pos:number(PreVal+16) == -1 & Pos:number(PreVal+24) == -1 & Pos:number(PreVal+32) == -1 & Pos:number(PreVal+ 40) == -1 & Pos:number(PreVal+ 48) == -1) {End =1}

    if(Select & $Select & PosVal == PreVal - 8) {End =1}
    if(Select & $Select & PosVal == PreVal - 16 & Pos:number(PreVal-8) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal - 24 & Pos:number(PreVal-8) == -1 & Pos:number(PreVal-16) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal - 32 & Pos:number(PreVal-8) == -1 & Pos:number(PreVal-16) == -1 & Pos:number(PreVal-24) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal - 40 & Pos:number(PreVal-8) == -1 & Pos:number(PreVal-16) == -1 & Pos:number(PreVal-24) == -1 & Pos:number(PreVal-32) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal - 48 & Pos:number(PreVal-8) == -1 & Pos:number(PreVal-16) == -1 & Pos:number(PreVal-24) == -1 & Pos:number(PreVal-32) == -1 & Pos:number(PreVal- 40) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal - 56 & Pos:number(PreVal-8) == -1 & Pos:number(PreVal-16) == -1 & Pos:number(PreVal-24) == -1 & Pos:number(PreVal-32) == -1 & Pos:number(PreVal- 40) == -1 & Pos:number(PreVal- 48) == -1) {End =1}

    if(Select & $Select & PosVal == PreVal + 1) {End =1}
    if(Select & $Select & PosVal == PreVal + 2 & Pos:number(PreVal+1) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal + 3 & Pos:number(PreVal+1) == -1 & Pos:number(PreVal+2) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal + 4 & Pos:number(PreVal+1) == -1 & Pos:number(PreVal+2) == -1 & Pos:number(PreVal+3) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal + 5 & Pos:number(PreVal+1) == -1 & Pos:number(PreVal+2) == -1 & Pos:number(PreVal+3) == -1 & Pos:number(PreVal+4) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal + 6 & Pos:number(PreVal+1) == -1 & Pos:number(PreVal+2) == -1 & Pos:number(PreVal+3) == -1 & Pos:number(PreVal+4) == -1 & Pos:number(PreVal+ 5) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal + 7 & Pos:number(PreVal+1) == -1 & Pos:number(PreVal+2) == -1 & Pos:number(PreVal+3) == -1 & Pos:number(PreVal+4) == -1 & Pos:number(PreVal+ 5) == -1 & Pos:number(PreVal+ 6) == -1) {End =1}

    if(Select & $Select & PosVal == PreVal - 1) {End =1}
    if(Select & $Select & PosVal == PreVal - 2 & Pos:number(PreVal-1) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal - 3 & Pos:number(PreVal-1) == -1 & Pos:number(PreVal-2) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal - 4 & Pos:number(PreVal-1) == -1 & Pos:number(PreVal-2) == -1 & Pos:number(PreVal-3) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal - 5 & Pos:number(PreVal-1) == -1 & Pos:number(PreVal-2) == -1 & Pos:number(PreVal-3) == -1 & Pos:number(PreVal-4) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal - 6 & Pos:number(PreVal-1) == -1 & Pos:number(PreVal-2) == -1 & Pos:number(PreVal-3) == -1 & Pos:number(PreVal-4) == -1 & Pos:number(PreVal-5) == -1) {End =1}
    if(Select & $Select & PosVal == PreVal - 7 & Pos:number(PreVal-1) == -1 & Pos:number(PreVal-2) == -1 & Pos:number(PreVal-3) == -1 & Pos:number(PreVal-4) == -1 & Pos:number(PreVal-5) == -1 & Pos:number(PreVal- 6) == -1) {End =1}

}# End Queen
}#End Selected
if(!Selected){
    holoDelete(150)
    holoDelete(151)
    holoDelete(152)
    holoDelete(153)
    holoDelete(154)
    holoDelete(155)
    holoDelete(156)
    holoDelete(157)
    holoDelete(158)
    holoDelete(159)
    holoDelete(160)
    }

#Death Refrence:
#
#DWP = White Pawn
#DBP = Black Pawn
#DWR = White Rook
#DBR = Black Rook
#DWKN = White Knight
#DBKN = Black Knight
#DWB = White Bishup
#DBB = Black Bishup
#DWK = White King
#DBK = Black King
#DWQ = White Queen
#DBQ = Black Queen

#Jail Spawn
if(DWP) {
    DWI++
    DWA++
    holoCreate(DWI)
    holoModel(DWI,"hqcone")
    holoScale(DWI,vec(2,2,3))
    holoPos(DWI,entity():pos()+vec(-164,160,0)+vec(0,-20*DWA,0))
    if(holoEntity(DWI) != noentity()) {DWP = 0}}
if(DBP) {
    DBI++
    DBA++
    holoCreate(DBI)
    holoModel(DBI,"hqcone")
    holoScale(DBI,vec(2,2,3))
    holoColor(DBI,vec())
    holoPos(DBI,entity():pos()+vec(154,-160,0)+vec(0,20*DBA,0))
    if(holoEntity(DBI) != noentity()) {DBP = 0}}
if(DWR) {
    DWI++
    DWA++
    holoCreate(DWI)
    holoModel(DWI,"hqcylinder2")
    holoScale(DWI,vec(1,1,3))
    holoPos(DWI,entity():pos()+vec(-164,160,0)+vec(0,-20*DWA,0))
    if(holoEntity(DWI) != noentity()) {DWP = 0}}
if(DBR) {    
    DBI++
    DBA++
    holoCreate(DBI)
    holoModel(DBI,"hqcylinder2")
    holoScale(DBI,vec(1,1,3))
    holoColor(DBI,vec())
    holoPos(DBI,entity():pos()+vec(154,-160,0)+vec(0,20*DBA,0))
    if(holoEntity(DBI) != noentity()) {DBP = 0}}
if(DWKN) {
    DWI++
    DWA++
    holoCreate(DWI)
    holoModel(DWI,"hqcube")
    holoScale(DWI,vec(0.5,1.5,3.5))
    holoPos(DWI,entity():pos()+vec(-164,160,0)+vec(0,-20*DWA,0))
    if(holoEntity(DWI) != noentity()) {DWP = 0}}
if(DBKN) {    
    DBI++
    DBA++
    holoCreate(DBI)
    holoModel(DBI,"hqcube")
    holoScale(DBI,vec(0.5,1.5,3.5))
    holoColor(DBI,vec())
    holoPos(DBI,entity():pos()+vec(154,-160,0)+vec(0,20*DBA,0))
    if(holoEntity(DBI) != noentity()) {DBP = 0}}
if(DWB) {
    DWI++
    DWA++
    holoCreate(DWI)
    holoModel(DWI,"hqcylinder2")
    holoScale(DWI,vec(0.5,0.5,4))
    holoPos(DWI,entity():pos()+vec(-164,160,0)+vec(0,-20*DWA,0))
    if(holoEntity(DWI) != noentity()) {DWP = 0}}
if(DBB) {    
    DBI++
    DBA++
    holoCreate(DBI)
    holoColor(DBI,vec())
    holoModel(DBI,"hqcylinder2")
    holoScale(DBI,vec(0.5,0.5,4))
    holoPos(DBI,entity():pos()+vec(154,-160,0)+vec(0,-20*DBA,0))
    if(holoEntity(DBI) != noentity()) {DBP = 0}}
if(DWK) {
    holoDeleteAll()
    holoCreate(DWI)
    holoModel(DWI,"hqtorus")
    holoScale(DWI,vec(1,1,25))
    holoPos(DWI,entity():pos()+vec(0,-200,50))    
    }

if(DBK) {
    holoDeleteAll()
    holoCreate(DBI)
    holoModel(DBI,"hqtorus")
    holoScale(DBI,vec(1,1,25))
    holoColor(DBI,vec())
    holoPos(DBI,entity():pos()+vec(0,200,50))    
}

if(DWQ) {    
    DWI++
    DWA++
    holoCreate(DWI)
    holoModel(DWI,"pyramid")
    holoScale(DWI,vec(2,2,7))
    holoPos(DWI,entity():pos()+vec(-164,160,0)+vec(0,-20*DWA,0))
    if(holoEntity(DWI) != noentity()) {DWP = 0}}
if(DBQ) {    
    DBI++
    DBA++
    holoCreate(DBI)
    holoColor(DBI,vec())
    holoModel(DBI,"pyramid")
    holoScale(DBI,vec(2,2,7))
    holoPos(DBI,entity():pos()+vec(-154,160,0)+vec(0,-20*DBA,0))
    if(holoEntity(DBI) != noentity()) {DBP = 0}}