public override ulong GetMove(ulong board) { ulong player_board, opp_board; int player_piecestoplace, opp_piecestoplace; if (Board.IsWhiteTurn(board)) { player_board = Board.WhiteBoard(board); opp_board = Board.BlackBoard(board); player_piecestoplace = Board.WhitePiecesLeftToPlace(board); opp_piecestoplace = Board.BlackPiecesLeftToPlace(board); } else { player_board = Board.BlackBoard(board); opp_board = Board.WhiteBoard(board); player_piecestoplace = Board.BlackPiecesLeftToPlace(board); opp_piecestoplace = Board.WhitePiecesLeftToPlace(board); } ulong new_player_board; if (Board.IsPlacementPhase(board)) { var new_piece = InterpretInput("Place piece at: "); new_player_board = player_board | new_piece; player_piecestoplace--; } else { var old_piece = InterpretInput("Take piece from: "); var new_piece = InterpretInput("And place at: "); new_player_board = player_board & ~old_piece | new_piece; } throw new NotImplementedException(); // see if we made a run var old_runs = Board.GetRunPieces(player_board); var new_runs = Board.GetRunPieces(new_player_board); ulong new_opp_board = opp_board; if (new_runs != old_runs && Board.CountBits(new_runs) >= Board.CountBits(old_runs)) { var remove_piece = InterpretInput("Remove piece at: "); new_opp_board &= ~remove_piece; } return(Board.CreateBoardForNextTurn(IsWhite, new_player_board, new_opp_board, player_piecestoplace, opp_piecestoplace)); }
private void DumpMove(ulong board, ulong move) { if (Board.IsWhiteTurn(board)) { Console.Write("White"); } else { Console.Write("Black"); } // get bits set in original that are no longer set var unset_bits = board & ~move; var set_bits = move & ~board; ulong player_set; ulong player_unset; ulong opp_unset; if (Board.IsWhiteTurn(board)) { player_set = Board.WhiteBoard(set_bits); player_unset = Board.WhiteBoard(unset_bits); opp_unset = Board.BlackBoard(unset_bits); } else { player_set = Board.BlackBoard(set_bits); player_unset = Board.BlackBoard(unset_bits); opp_unset = Board.WhiteBoard(unset_bits); } Console.Write(": "); if (player_unset != 0) { DumpPlace(player_unset); Console.Write(" -> "); } DumpPlace(player_set); if (opp_unset != 0) { Console.Write(" ("); DumpPlace(opp_unset); Console.Write(")"); } Console.WriteLine(); }
public static int Heuristic(ulong board, bool max_for_white, List <ulong> possible_moves = null) { if (!Board.IsPlacementPhase(board)) { if (Board.IsWhiteTurn(board) && Board.WhitePiecesOnBoard(board) < 3) { if (max_for_white) { return(-1000); } else { return(1000); } } else if (!Board.IsWhiteTurn(board) && Board.BlackPiecesOnBoard(board) < 3) { if (max_for_white) { return(1000); } else { return(-1000); } } } if (possible_moves == null) { possible_moves = Board.GetMoves(board); } if (possible_moves.Count == 0) { if (Board.IsWhiteTurn(board)) { if (max_for_white) { return(-1000); } else { return(1000); } } else { if (max_for_white) { return(1000); } else { return(-1000); } } } /* We score +1 for a move, +2 if it forms a mill */ int score = 0; var old_runs = Board.GetRunPieces(board); foreach (var move in possible_moves) { var new_runs = Board.GetRunPieces(move); if (new_runs != old_runs && Board.CountBits(new_runs) >= Board.CountBits(old_runs)) { score += 5; } else { score++; } } if (Board.IsWhiteTurn(board)) { if (max_for_white) { return(score); } else { return(-score); } } else { if (max_for_white) { return(-score); } else { return(score); } } }