@@ -53,6 +53,10 @@ func isAttackedBy(brd *Board, occ BB, sq int, attacker, defender uint8) bool {
5353 return false
5454}
5555
56+ func pinnedCanMove (brd * Board , from , to int , c , e uint8 ) bool {
57+ return isPinned (brd , brd .AllOccupied (), from , c , e )& sqMaskOn [to ] > 0
58+ }
59+
5660// Determines if a piece is blocking a ray attack to its king, and cannot move off this ray
5761// without placing its king in check.
5862// Returns the area to which the piece can move without leaving its king in check.
@@ -62,15 +66,13 @@ func isAttackedBy(brd *Board, occ BB, sq int, attacker, defender uint8) bool {
6266// 3. Scan in the opposite direction to see detect any potential threats along this ray.
6367
6468// Return a bitboard of locations the piece at sq can move to without leaving the king in check.
65- func isPinned ( brd * Board , sq int , c , e uint8 ) BB {
66- occ := brd . AllOccupied ()
69+
70+ func isPinned ( brd * Board , occ BB , sq int , c , e uint8 ) BB {
6771 var line , attacks , threat BB
6872 kingSq := brd .KingSq (c )
69- dir := directions [sq ][kingSq ] // get direction toward king
70-
7173 line = lineMasks [sq ][kingSq ]
7274 if line > 0 { // can only be pinned if on a ray to the king.
73- if dir < NORTH {
75+ if directions [ sq ][ kingSq ] < NORTH { // direction toward king
7476 attacks = bishopAttacks (occ , sq )
7577 threat = line & attacks & (brd.pieces [e ][BISHOP ] | brd.pieces [e ][QUEEN ])
7678 } else {
@@ -116,12 +118,14 @@ func getSee(brd *Board, from, to int, capturedPiece Piece) int {
116118 count := 1
117119
118120 if capturedPiece == KING {
119- // this move is illegal and will be discarded by search. return the lowest possible
121+ // this move is illegal and will be discarded by the move selector. Return the lowest possible
120122 // SEE value so that this move will be put at end of list. If cutoff occurs before then,
121123 // the cost of detecting the illegal move will be saved.
122-
123124 fmt .Println ("info string king capture detected in getSee()!" )
124- return SEE_MIN
125+ fmt .Printf ("info string %s%s x %s" , SquareString (from ), SquareString (to ), sanChars [capturedPiece ])
126+ brd .Print ()
127+ panic ("king capture detected in getSee()!" )
128+ // return SEE_MIN
125129 }
126130 t = brd .TypeAt (from )
127131 if t == KING { // Only commit to the attack if target piece is undefended.
@@ -191,10 +195,6 @@ func getSee(brd *Board, from, to int, capturedPiece Piece) int {
191195 return pieceList [0 ]
192196}
193197
194- func pinnedCanMove (brd * Board , from , to int , c , e uint8 ) bool {
195- return isPinned (brd , from , brd .c , brd .Enemy ())& sqMaskOn [to ] > 0
196- }
197-
198198func isCheckmate (brd * Board , inCheck bool ) bool {
199199 if ! inCheck {
200200 return false
0 commit comments