11package engine
22
3- import "fmt"
4-
53var (
64 nextRank int8 = 16
75 nextFile int8 = 1
@@ -132,9 +130,11 @@ func (g *Generator) GenerateMoves() []Move {
132130// CheckSimple finds possible check attacks
133131func (g * Generator ) CheckSimple () bool {
134132
133+ g .reset ()
134+
135135 // check for knight attacks first
136136 for _ , delta := range deltaKnight {
137- to := g .kingSquare + int8 ( delta )
137+ to := g .kingSquare + delta
138138 if g .board .legalSquare (to ) && g .board .data [to ]* opponent (g .board .sideToMove ) == Knight {
139139 return true
140140 }
@@ -144,6 +144,7 @@ func (g *Generator) CheckSimple() bool {
144144 for _ , delta := range deltaAll {
145145 depth := 0
146146 for to := g .kingSquare + delta ; g .board .legalSquare (to ); to += delta {
147+ depth ++
147148 found := g .board .data [to ] * opponent (g .board .sideToMove )
148149
149150 // empty square, go ahead
@@ -153,7 +154,7 @@ func (g *Generator) CheckSimple() bool {
153154
154155 if found == Pawn || found == King {
155156 if depth == 1 {
156- if g .attackPosible (to , opposite (delta )) {
157+ if g .attackPossible (to , opposite (delta )) {
157158 return true
158159 }
159160 }
@@ -166,7 +167,7 @@ func (g *Generator) CheckSimple() bool {
166167 }
167168
168169 // found opponent
169- if g .attackPosible (to , delta ) {
170+ if g .attackPossible (to , delta ) {
170171 return true
171172 }
172173 break
@@ -233,11 +234,6 @@ func (g *Generator) sortMoves() {
233234 // 5. normal moves
234235 sorted = append (sorted , ordinary ... )
235236
236- if len (sorted ) != len (g .moves ) {
237- fmt .Printf ("len(g.moves): %d, len(sorted): %d\n " , len (g .moves ), len (sorted ))
238- panic ("Sorted moves are missing moves!" )
239- }
240-
241237 g .moves = sorted
242238}
243239
@@ -471,7 +467,7 @@ func (g *Generator) findThreats(square Square, sideToMove int8, skipKing bool) [
471467 // if there is a pawn/king on next square, check for attack
472468 if content == - Pawn || content == - King {
473469 if depth == 1 {
474- if g .attackPosible (to , opposite (delta )) {
470+ if g .attackPossible (to , opposite (delta )) {
475471 threats = append (threats , to )
476472 }
477473 }
@@ -493,7 +489,7 @@ func (g *Generator) findThreats(square Square, sideToMove int8, skipKing bool) [
493489 }
494490
495491 // found opponent piece
496- if g .attackPosible (to , delta ) {
492+ if g .attackPossible (to , delta ) {
497493 threats = append (threats , to )
498494 }
499495
@@ -545,7 +541,7 @@ func (g *Generator) numberOfCheckThreats() int {
545541 // pawn on the next square, check if attack possible
546542 if piece == Pawn || piece == King {
547543 if depth == 1 {
548- if g .attackPosible (newSquare , opposite (delta )) {
544+ if g .attackPossible (newSquare , opposite (delta )) {
549545 g .kingUnderCheck = true
550546 threats ++
551547 g .legalEnding [newSquare ] = true
@@ -565,7 +561,7 @@ func (g *Generator) numberOfCheckThreats() int {
565561 }
566562
567563 // we found an opponents piece; might be a threat for the current square
568- if g .attackPosible (newSquare , delta ) {
564+ if g .attackPossible (newSquare , delta ) {
569565 if squareOfGuardingPiece == Invalid {
570566 threats ++
571567 g .kingUnderCheck = true
@@ -599,11 +595,8 @@ func (g *Generator) hasDirection(delta []int8, direction int8) bool {
599595
600596// check for attacks from a diven square in a particular direction
601597// does not work for knight obviously
602- func (g * Generator ) attackPosible (from int8 , direction int8 ) bool {
603- absPiece := g .board .data [from ]
604- if absPiece < 0 {
605- absPiece = - absPiece
606- }
598+ func (g * Generator ) attackPossible (from int8 , direction int8 ) bool {
599+ absPiece := abs (g .board .data [from ])
607600
608601 switch absPiece {
609602 case King :
0 commit comments