Author: Andrew Williams
Date: 06:08:03 05/09/99
Go up one level in this thread
On May 09, 1999 at 07:32:28, Frank Phillips wrote: >On May 09, 1999 at 06:50:17, Andrew Williams wrote: > >>On May 09, 1999 at 06:31:41, Frank Phillips wrote: >> >>>I have noticed that bugs in my program sometimes cause the onset of >>>irrationality where I bang the keyboard randomly hoping that by magic (or >>>perhaps the monkeys writing Shakespeare theory) the problem will go away. >>> >>>Up until now I have been calculating the hash code for a position in the >>>ABSearch() from scratch by looping through the board and XORing the Random64 >>>[colour_of_piece][piece][square] combinations, followed by XORing for the >>>enpassant square and castling rights. To speed things up I thought I would do >>>this incrementally in the MakeMove() function by taking the last hash code >>>(always stored as wtm), undoing the enpassant and castling effects, by XORing >>>with same values to switch them off, then XORing to remove the piece from a >>>square, put piece on square, remove captured piece, add promoted piece >>>etc???.and then finally XORing the result for new enpassant square and castling >>>rights. >>> >>>Everything works fine without hashing the enpassant square and castling rights, >>>but not otherwise. By which I mean the new method gives the same hash code as >>>that calculated from scratch in the same position by looping through the board, >>>provided I do not hash for ep and castling. When I print out the moves, the >>>offending move where it all goes wrong seems to be castling, but I cannot find >>>the error. >>> >>>Should what I am doing work, so that there is still a bug in the incremental >>>hash update I have not found yet, or can I not do it the way I am trying? >> >>What you describe here is exactly what I do, so it is possible to do it this >>way. Do you also include the hashkey update for the Rook and King moving about >>during castling? This question isn't meant to insult your intelligence; this >>was one of the main problems I had when implementing incremental hashkey >>updates. >> >>Andrew > >Thanks. Yes. I XOR king[E1]/king[G1]/rook[H1]/rook[F1] for example. Well, I don't know if it will help much, but here is what PostModernist does when updating the hashkey for castling moves: void update_hashKey_castle(move mv) { piece movedP; move rookmv; movedP = bd[mv.frsq]; /* This bit does the King movement */ currentHashKey = currentHashKey ^ random_bd[movedP.type][mv.frsq][movedP.colour]; currentHashKey = currentHashKey ^ random_bd[movedP.type][mv.tosq][movedP.colour]; /* This bit does the Rook movement */ switch(mv.tosq) { case C1 : rookmv.frsq = A1; rookmv.tosq = D1; break; case G1 : rookmv.frsq = H1; rookmv.tosq = F1; break; case C8 : rookmv.frsq = A8; rookmv.tosq = D8; break; case G8 : rookmv.frsq = H8; rookmv.tosq = F8; break; } movedP = bd[rookmv.frsq]; currentHashKey = currentHashKey ^ random_bd[movedP.type][rookmv.frsq][movedP.colour]; currentHashKey = currentHashKey ^ random_bd[movedP.type][rookmv.tosq][movedP.colour]; currentHashKey = currentHashKey ^ random_cstl[gamescore[halfMoves].cr]; currentHashKey = currentHashKey ^ random_cstl[castlerights]; currentHashKey = currentHashKey ^ random_epsq[gamescore[halfMoves].epsquare]; currentHashKey = currentHashKey ^ random_epsq[epsquare]; currentHashKey = currentHashKey ^ random_col[OTHERSIDE(whoseTurn)]; currentHashKey = currentHashKey ^ random_col[whoseTurn]; } bd[] is the board array. gamescore[halfMoves] is a record of various information from the previous position: .cr is the castling rights; .epsquare is the ep square castlerights and epsquare are the current values. random_bd, random_cstl, random_col and random_epsq are my random number tables. Hope this makes some sense. Andrew
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.