@@ -14,7 +14,7 @@ const (
1414
1515var cntNodes uint64
1616
17- //TODO search limits: counting nodes and testing for limit.nodes
17+ //TODO search limits: count nodes and test for limit.nodes
1818//TODO search limits: limit.depth
1919
2020//TODO search limits: time per game w/wo increments
@@ -89,7 +89,7 @@ func (pv *pvList) String() string {
8989func engine () (toEngine chan bool , frEngine chan string ) {
9090 frEngine = make (chan string )
9191 toEngine = make (chan bool )
92- go root (toEngine , frEngine )
92+ go rootx (toEngine , frEngine )
9393
9494 return
9595}
@@ -214,35 +214,34 @@ func search(alpha, beta, depth, ply int, pv *pvList, b *boardStruct) int {
214214 return bs
215215}
216216
217- func initQS (ml * moveList , b * boardStruct ){
217+ func initQS (ml * moveList , b * boardStruct ) {
218218 ml .clear ()
219219 b .genAllCaptures (ml )
220220}
221- func qs (beta int , b * boardStruct ) int {
221+ func qs (beta int , b * boardStruct ) int {
222222 ev := signEval (b .stm , evaluate (b ))
223223 if ev >= beta {
224224 // we are good. No need to try captures
225225 return ev
226226 }
227227 bs := ev
228228
229- qsList := make (moveList ,0 ,60 )
230- initQS (& qsList ,b ) // create attacks
231-
232- done := bitBoard (0 )
229+ qsList := make (moveList , 0 , 60 )
230+ initQS (& qsList , b ) // create attacks
231+ done := bitBoard (0 )
233232
234233 // move loop
235- for _ ,mv := range qsList {
236- fr := mv .fr ()
237- to := mv .to ()
234+ for _ , mv := range qsList {
235+ fr := mv .fr ()
236+ to := mv .to ()
238237
239- // This works because we pick lower value pieces first
240- if done .test (to ) {// Don't do the same to-sw again
238+ // This works because we pick lower value pieces first
239+ if done .test (to ) { // Don't do the same to-sw again
241240 continue
242241 }
243242 done .set (to )
244243
245- see := see (fr ,to ,b )
244+ see := see (fr , to , b )
246245
247246 if see < 0 {
248247 continue // equal captures not interesting
@@ -252,9 +251,9 @@ func qs(beta int, b *boardStruct) int{
252251 see = pieceVal [wQ ] - pieceVal [wP ]
253252 }
254253
255- sc := ev + see
254+ sc := ev + see
256255 if sc > bs {
257- bs = sc
256+ bs = sc
258257 if sc >= beta {
259258 return sc
260259 }
@@ -263,6 +262,7 @@ func qs(beta int, b *boardStruct) int{
263262
264263 return bs
265264}
265+
266266// see (Static Echange Evaluation)
267267// Start with the capture fr-to and find out all the other captures to to-sq
268268func see (fr , to int , b * boardStruct ) int {
@@ -275,12 +275,13 @@ func see(fr, to int, b *boardStruct) int {
275275 // All the attackers to the to-sq, but first remove the moving piece and use X-ray to the to-sq
276276 occ := b .allBB ()
277277 occ .clr (fr )
278- attackingBB := mRookTab [to ].atks (occ )& (b .pieceBB [Rook ]| b .pieceBB [Queen ]) |
279- mBishopTab [to ].atks (occ )& (b .pieceBB [Bishop ]| b .pieceBB [Queen ]) |
280- (atksKnights [to ] & b .pieceBB [Knight ]) |
281- (atksKings [to ] & b .pieceBB [King ]) |
282- (b .wPawnAtksFr (to ) & b .pieceBB [Pawn ] & b .wbBB [BLACK ]) |
283- (b .bPawnAtksFr (to ) & b .pieceBB [Pawn ] & b .wbBB [WHITE ])
278+ attackingBB :=
279+ mRookTab [to ].atks (occ )& (b .pieceBB [Rook ]| b .pieceBB [Queen ]) |
280+ mBishopTab [to ].atks (occ )& (b .pieceBB [Bishop ]| b .pieceBB [Queen ]) |
281+ (atksKnights [to ] & b .pieceBB [Knight ]) |
282+ (atksKings [to ] & b .pieceBB [King ]) |
283+ (b .wPawnAtksFr (to ) & b .pieceBB [Pawn ] & b .wbBB [BLACK ]) |
284+ (b .bPawnAtksFr (to ) & b .pieceBB [Pawn ] & b .wbBB [WHITE ])
284285 attackingBB &= occ
285286
286287 if (attackingBB & b .wbBB [them ]) == 0 { // 'they' have no attackers - good bye
@@ -290,16 +291,17 @@ func see(fr, to int, b *boardStruct) int {
290291 // Now we continue to keep track of the material gain/loss for each capture
291292 // Always remove the last attacker and use x-ray to find possible new attackers
292293
293- lastAtkVal := abs (pieceVal [pc ]) // save attacker piece value for later use
294+ lastAtkVal := abs (pieceVal [pc ]) // save attacker piece value for later use
294295 var captureList [32 ]int
296+ captureList [0 ] = abs (pieceVal [cp ])
295297 n := 1
296298
297299 stm := them // change side to move
298- var pt int
299- var BB bitBoard
300300
301301 for {
302302 cnt ++
303+
304+ var pt int
303305 switch { // select the least valuable attacker
304306 case (attackingBB & b .pieceBB [Pawn ] & b .wbBB [stm ]) != 0 :
305307 pt = Pawn
@@ -318,7 +320,7 @@ func see(fr, to int, b *boardStruct) int {
318320 }
319321
320322 // now remove the pt above from the attackingBB and scan for new attackers by possible x-ray
321- BB = attackingBB & (attackingBB & b .pieceBB [pt ] & b .wbBB [stm ])
323+ BB : = attackingBB & (attackingBB & b .pieceBB [pt ] & b .wbBB [stm ])
322324 occ ^= (BB & - BB ) // turn off the rightmost bit from BB in occ
323325
324326 // pick sliding attacks again (do it from to-sq)
@@ -330,10 +332,10 @@ func see(fr, to int, b *boardStruct) int {
330332 n ++
331333
332334 // save the value of tha capturing piece to be used later
333- lastAtkVal = abs ( pieceVal [pt2pc (pt , stm )])
334- stm = stm .opp () // next side to move
335+ lastAtkVal = pieceVal [pt2pc (pt , WHITE )] // using WHITE always gives positive integer
336+ stm = stm .opp () // next side to move
335337
336- if pt == King && (attackingBB & b .pieceBB [ King ] & b . wbBB [stm ]) != 0 {
338+ if pt == King && (attackingBB & b .wbBB [stm ]) != 0 { //NOTE: just changed stm-color above
337339 // if king capture and 'they' are atting we have to stop
338340 captureList [n ] = pieceVal [wK ]
339341 n ++
@@ -414,7 +416,7 @@ func (k *killerStruct) clear() {
414416
415417// add killer 1 and 2 (Not inCheck, caaptures and promotions)
416418func (k * killerStruct ) add (mv move , ply int ) {
417- if ! k [ply ].k1 .cmpFrTo (mv ) {
419+ if ! k [ply ].k1 .cmp (mv ) {
418420 k [ply ].k2 = k [ply ].k1
419421 k [ply ].k1 = mv
420422 }
0 commit comments