/* * Extension: Checks and adds to hash table using Zobrist hash function */ void generateUniqueBoardHash(BoardNode currentBoard, int rowMove, int colMove, int currRow, int currCol) { int hashKey; BoardNode generatedBoard; generatedBoard = makeMove(copyParentToChild(currentBoard,createBoard(currentBoard)),rowMove,colMove,currRow,currCol,DELETE); hashKey = generateHashKey(generatedBoard); if(hashBoard(hashKey,generatedBoard)) { addToQueue(generatedBoard); checkTarget(generatedBoard); } }
// performs move on this state, assumes move is valid // any move it makes is valid, of course // because gen() performs validation of moves // before adding to the vector of moves void KhetState::imake(KhetMove mv) { //move piece KhetPiece targetPiece = board[mv.toFile][mv.toRank]; if (targetPiece.type != EMPTY && mv.fromRot == mv.toRot) {//if its rotation target wont be empty assert(mv.piece.type == SCARAB); assert(targetPiece.type == ANUBIS || targetPiece.type == PYRAMID); //scarab swap board[mv.fromFile][mv.fromRank] = targetPiece; board[mv.toFile][mv.toRank] = mv.piece; } else { board[mv.fromFile][mv.fromRank].type = EMPTY; board[mv.toFile][mv.toRank] = mv.piece; board[mv.toFile][mv.toRank].rot = (Rotation)mv.toRot;//mv.piece is original piece } key = hashBoard(); //shoot laser KhetPiece sph; int tFile; int tRank; //set inital laser location if(ctm == SILVER) { sph = board[9][0]; tFile = 9; tRank = 0; } else { sph = board[0][7]; tFile = 0; tRank = 7; } assert(board[tFile][tRank].type == SPHINX && board[tFile][tRank].color == ctm); Rotation laserDir = sph.rot; LaserHitInfo laserHitInfo = fireLaser(board, tFile, tRank, laserDir, 0, 0); //piece is to be removed from board //handle it approrpiately targetPiece = laserHitInfo.hitPiece; tFile = laserHitInfo.hitFile; tRank = laserHitInfo.hitRank; switch(targetPiece.type) { case ANUBIS: //anubis can take hit on front if(!isOppositeDirections(laserHitInfo.laserDir, targetPiece.rot)) { board[tFile][tRank].type = EMPTY; } break; case PHAROAH: board[tFile][tRank].type = EMPTY; gameOver = true; winner = (targetPiece.color == RED) ? SILVER : RED; break; case PYRAMID: board[tFile][tRank].type = EMPTY; break; case SCARAB: cout << "ERROR: scarab being removed" << endl; break; case SPHINX://sphinx cant be affected break; case EMPTY: break; default: cout << "Unknown laser target " << targetPiece.type << endl; } //change player ctm = (ctm == RED) ? SILVER : RED; }