// public jcMove Query // Querying the table for a ready-made move to play. Return null if there // is none public jcMove Query(jcBoard theBoard) { // First, look for a match in the table int key = Math.Abs(theBoard.HashKey() % TABLE_SIZE); int hashLock = theBoard.HashLock(); // If the hash lock doesn't match the one for our position, get out if (Table[key].theLock != hashLock) return null; // If there is an entry for this board in the table, verify that it // contains a move for the current side if (theBoard.GetCurrentPlayer() == jcPlayer.SIDE_BLACK) { if (Table[key].BlackMove.MoveType != jcOpeningBookEntry.NO_MOVE) return Table[key].BlackMove; } else { if (Table[key].WhiteMove.MoveType != jcOpeningBookEntry.NO_MOVE) return Table[key].WhiteMove; } // If we haven't found anything useful, quit return null; }
private bool StoreMove(jcBoard theBoard, jcMove theMove) { // Where should we store this data? int key = Math.Abs(theBoard.HashKey() % TABLE_SIZE); int hashLock = theBoard.HashLock(); // Is there already an entry for a different board position where we // want to put this? If so, mark it deleted if (Table[key].theLock != hashLock) { Table[key].BlackMove.MoveType = jcOpeningBookEntry.NO_MOVE; Table[key].WhiteMove.MoveType = jcOpeningBookEntry.NO_MOVE; } // And store the new move Table[key].theLock = hashLock; if (theBoard.GetCurrentPlayer() == jcPlayer.SIDE_BLACK) { Table[key].BlackMove.Copy(theMove); } else { Table[key].WhiteMove.Copy(theMove); } return true; }