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); }
public override AIDecision RequestMove(AiGameInformation gameInformation) { RandomPlayer internalPlayer = new RandomPlayer(gameInformation.AIColor == StoneColor.Black ? 'B' : 'W'); char[,] board = JokerExtensionMethods.OurBoardToJokerBoard(GetLastNodeOrEmptyBoard(gameInformation.GameTree).BoardState, gameInformation.GameInfo.BoardSize); JokerPoint point = internalPlayer.makeMove(board, gameInformation.GameInfo.BoardSize.Width, gameInformation.GameInfo.BoardSize.Height); return(AIDecision.MakeMove(Move.PlaceStone(gameInformation.AIColor, new Position(point.x, point.y)), "I chose at random.")); }
/** 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); } }
private bool makeCaptures(JokerPlayer capturingPlayer, JokerPlayer gettingCapturedPlayer) { LinkedList <JokerPoint> toRemove = Rules.findCaptured(capturingPlayer.getColor(), gettingCapturedPlayer.getColor(), board, height); if (toRemove.isEmpty()) { return(false); } while (!toRemove.isEmpty()) { JokerPoint tmp = toRemove.First.Value; toRemove.RemoveFirst(); board[tmp.x, tmp.y] = '*'; } return(true); }
public JokerPoint makeMove(char[,] board, int width, int height) { List <JokerPoint> list = new List <JokerPoint>(); for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { if (board[i, j] == '*') { list.Add(new JokerPoint(i, j)); } } } if (list.Count == 0) { return(new Joker23.JokerPoint(0, 0)); } JokerPoint randomMove = list[rand.Next(list.Count)]; return(randomMove); }
private int alphabeta(int depth, int alpha, int beta, char turn) { // Takes 95% CPU int me = GameEngine.Rules.findCaptured(getColor(), getOpponentColor(), boardCopy, boardCopy.GetLength(0)).Count; int oppo = GameEngine.Rules.findCaptured(getOpponentColor(), getColor(), boardCopy, boardCopy.GetLength(0)).Count; if (oppo > 0 && me > 0) { if (turn == getColor()) { return(-1000000000); } else { return(1000000000); } } else if (oppo + me > 0) { if (oppo > 0) { return(-1000000000); } else if (me > 0) { return(1000000000); } } if (depth == 0) { return(AiUtil.getLiberties(getColor(), boardCopy) - AiUtil.getLiberties(getOpponentColor(), boardCopy)); } //both player have the same next moves //List<Point> nextMoves = AiUtil.getNextMoves(boardCopy, influence, 10); //hard coded horizontal pruning IEnumerable <JokerPoint> nextMoves = AiUtil.getNextMoves(boardCopy, 3); if (turn == getColor()) { foreach (JokerPoint next in nextMoves) { int priorInf = influence[next.x, next.y]; updateInfluenceMap(next.x, next.y, boardCopy.GetLength(0)); boardCopy[next.x, next.y] = getColor(); int temp = alphabeta(depth - 1, alpha, beta, getOpponentColor()); boardCopy[next.x, next.y] = '*'; restoreInfluenceMap(next.x, next.y, priorInf, boardCopy.GetLength(0)); if (alpha < temp) { alpha = temp; if (depth == this._maxDepth) { bestMove = next; } } if (beta <= alpha) { return(alpha); } } return(alpha); } else { foreach (JokerPoint next in nextMoves) { int priorInf = influence[next.x, next.y]; updateInfluenceMap(next.x, next.y, boardCopy.GetLength(0)); boardCopy[next.x, next.y] = getOpponentColor(); int temp = alphabeta(depth - 1, alpha, beta, getColor()); boardCopy[next.x, next.y] = '*'; restoreInfluenceMap(next.x, next.y, priorInf, boardCopy.GetLength(0)); if (beta > temp) { beta = temp; if (depth == this._maxDepth) { bestMove = next; } } if (beta <= alpha) { return(beta); } } return(beta); } }
public void setLocation(JokerPoint location) { this.location = location; }
private JokerPoint location; // this is the placement of the piece public JokerMove(char color, JokerPoint location) { this.color = color; this.location = location; }