public override AIDecision RequestMove(AiGameInformation gameInformation) { var moves = gameInformation.GameTree.PrimaryMoveTimeline.ToList(); if (moves.Any() && moves.Last().Kind == MoveKind.Pass) { return(AIDecision.MakeMove(Move.Pass(gameInformation.AIColor), "You passed, too!")); } JokerGame currentGame = new JokerGame(gameInformation.GameInfo.BoardSize.Height, gameInformation.GameInfo.BoardSize.Width, null, null); foreach (Move move in gameInformation.GameTree.PrimaryMoveTimeline) { currentGame.moves.AddLast(new JokerMove(move.WhoMoves == StoneColor.Black ? 'B' : 'W', new JokerPoint(move.Coordinates.X, move.Coordinates.Y))); } currentGame.board = JokerExtensionMethods.OurBoardToJokerBoard(GetLastNodeOrEmptyBoard(gameInformation.GameTree).BoardState, gameInformation.GameInfo.BoardSize); JokerPoint point = new AlphaBetaPlayer(gameInformation.AIColor == StoneColor.Black ? 'B' : 'W').betterPlanMove(currentGame, this.TreeDepth); return(AIDecision.MakeMove(Move.PlaceStone(gameInformation.AIColor, new Position(point.x, point.y)), "I chose using the minimax algorithm and heuristics.")); }
public override void planMove(JokerGame game) { char[,] board = game.getBoard(); List <JokerPoint> list = new List <JokerPoint>(); for (int i = 0; i < game.getHeight(); i++) { for (int j = 0; j < game.getWidth(); j++) { if (board[i, j] == '*') { list.Add(new JokerPoint(i, j)); } } } JokerPoint randomMove = list[rand.Next(list.Count)]; while (!list.isEmpty()) { if (makeMove(game, randomMove)) { return; } } }
public JokerPoint betterPlanMove(JokerGame game) { if (orderMap == null) { initOrderMap(game.getHeight()); } int n = game.getHeight(); JokerMove prevMove; if ((prevMove = game.getLastMove()) != null) { int row = prevMove.getLocation().x; int col = prevMove.getLocation().y; updateOrderMap(row, col, n); } char[,] tmpBoard = game.getBoardCopy(); int best = int.MinValue; List <JokerPoint> bestMoves = new List <JokerPoint>(); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (tmpBoard[i, j] != '*') { continue; } tmpBoard[i, j] = color; int heuristic = AiUtil.getLiberties(getColor(), tmpBoard); heuristic -= (AiUtil.getLiberties(getOpponentColor(), tmpBoard) * 2); heuristic += orderMap[i, j]; if (heuristic > best) { best = heuristic; bestMoves.Clear(); bestMoves.Add(new JokerPoint(i, j)); } else if (heuristic == best) { bestMoves.Add(new JokerPoint(i, j)); } tmpBoard[i, j] = '*'; } } JokerPoint bestMove = bestMoves[Randomizer.Next(bestMoves.Count)]; updateOrderMap(bestMove.x, bestMove.y, n); return(bestMove); }
/** playMove * this method will allow the player to play a move on to the board * * @param row : the row tha the piece will be played on * @param col : the column that the piece will be played on */ public bool makeMove(JokerGame game, JokerPoint point) { if (game.play(this.color, point.x, point.y)) { moves.AddLast(new JokerMove(color, point)); return(true); } else { return(false); } }
public override void planMove(JokerGame game) { if (influence == null) { initInfluenceMap(game.getHeight()); } boardCopy = game.getBoardCopy(); this._maxDepth = game.getWidth() + 1; alphabeta(this._maxDepth, -INF, INF, getColor()); makeMove(game, bestMove); }
public JokerPoint betterPlanMove(JokerGame game, int maxDepth) { // Takes 95% CPU if (influence == null) { initInfluenceMap(game.getHeight()); } boardCopy = game.getBoardCopy(); this._maxDepth = maxDepth; alphabeta(this._maxDepth, -INF, INF, getColor()); return(bestMove); }
public override void planMove(JokerGame game) { throw new NotImplementedException(); }
/**planMove * this is the AI thing that plans the move for * the player */ public abstract void planMove(JokerGame game);