-
Notifications
You must be signed in to change notification settings - Fork 0
/
castling.R
67 lines (58 loc) · 3.56 KB
/
castling.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
canCastleKingside = function(activePieces, pieceCol){
if(pieceCol == "White"){
if(activePieces[activePieces$Type == "King" & activePieces$Colour == "White",]$Moves == 0 &
nrow(activePieces[activePieces$Type == "Rook" & activePieces$Colour == "White" & activePieces$XLoc == 8
& activePieces$Moves == 0,]) == 1 &
nrow(activePieces[activePieces$XLoc == 6 & activePieces$YLoc == 1,]) == 0 &
nrow(activePieces[activePieces$XLoc == 7 & activePieces$YLoc == 1,]) == 0){
activePieces[activePieces$Type == "King" & activePieces$Colour == "White",]$XLoc = 7
activePieces[activePieces$Type == "Rook" & activePieces$Colour == "White" & activePieces$XLoc == 8,]$XLoc = 6
if(inCheck(activePieces, pieceCol) == TRUE){return(FALSE)}
if(inCheck(activePieces, pieceCol) == FALSE){return(TRUE)}
}
else{return(FALSE)}
}
if(pieceCol == "Black"){
if(activePieces[activePieces$Type == "King" & activePieces$Colour == "Black",]$Moves == 0 &
nrow(activePieces[activePieces$Type == "Rook" & activePieces$Colour == "Black" & activePieces$XLoc == 8
& activePieces$Moves == 0,]) == 1 &
nrow(activePieces[activePieces$XLoc == 6 & activePieces$YLoc == 8,]) == 0 &
nrow(activePieces[activePieces$XLoc == 7 & activePieces$YLoc == 8,]) == 0){
activePieces[activePieces$Type == "King" & activePieces$Colour == "Black",]$XLoc = 7
activePieces[activePieces$Type == "Rook" & activePieces$Colour == "Black" & activePieces$XLoc == 8,]$XLoc = 6
if(inCheck(activePieces, pieceCol) == TRUE){return(FALSE)}
if(inCheck(activePieces, pieceCol) == FALSE){return(TRUE)}
}
else{return(FALSE)}
}
}
canCastleQueenside = function(activePieces, pieceCol){
if(pieceCol == "White"){
if(activePieces[activePieces$Type == "King" & activePieces$Colour == "White",]$Moves == 0 &
nrow(activePieces[activePieces$Type == "Rook" & activePieces$Colour == "White" & activePieces$XLoc == 1
& activePieces$Moves == 0,]) == 1 &
nrow(activePieces[activePieces$XLoc == 2 & activePieces$YLoc == 1,]) == 0 &
nrow(activePieces[activePieces$XLoc == 3 & activePieces$YLoc == 1,]) == 0 &
nrow(activePieces[activePieces$XLoc == 4 & activePieces$YLoc == 1,]) == 0){
activePieces[activePieces$Type == "King" & activePieces$Colour == "White",]$XLoc = 3
activePieces[activePieces$Type == "Rook" & activePieces$Colour == "White" & activePieces$XLoc == 1,]$XLoc = 4
if(inCheck(activePieces, pieceCol) == TRUE){return(FALSE)}
if(inCheck(activePieces, pieceCol) == FALSE){return(TRUE)}
}
else{return(FALSE)}
}
if(pieceCol == "Black"){
if(activePieces[activePieces$Type == "King" & activePieces$Colour == "Black",]$Moves == 0 &
nrow(activePieces[activePieces$Type == "Rook" & activePieces$Colour == "Black" & activePieces$XLoc == 1
& activePieces$Moves == 0,]) == 1 &
nrow(activePieces[activePieces$XLoc == 2 & activePieces$YLoc == 8,]) == 0 &
nrow(activePieces[activePieces$XLoc == 3 & activePieces$YLoc == 8,]) == 0 &
nrow(activePieces[activePieces$XLoc == 4 & activePieces$YLoc == 8,]) == 0){
activePieces[activePieces$Type == "King" & activePieces$Colour == "Black",]$XLoc = 3
activePieces[activePieces$Type == "Rook" & activePieces$Colour == "Black" & activePieces$XLoc == 1,]$XLoc = 4
if(inCheck(activePieces, pieceCol) == TRUE){return(FALSE)}
if(inCheck(activePieces, pieceCol) == FALSE){return(TRUE)}
}
else{return(FALSE)}
}
}