public Board.Decision makeMove(Board board) { numMovesCalled++; long startTime = nanoTime(); Move m = minimaxStart(board, depth, getSide(), true); totalTimeElapsed += nanoTime() - startTime; //System.out.println("m is: " + m); //Move move = board.getAllValidMoves(getSide()).get(m); Main.println("::::::::" + m.getEnd() + " " + m.getStart()); Board.Decision decision = board.makeMove(m, getSide()); if (decision == Board.Decision.ADDITIONAL_MOVE) { skippingPoint = m.getEnd(); checkVec = true; } //System.out.println("Pruned tree: " + pruned + " times"); return(decision); }
// Use this for initialization void Start() { multipleRoundsTest = total > 1; //Player one = new Player("Player 1", Player.Side.BLACK); //Player two = new Player("Player 2", Player.Side.WHITE); MinimaxAI one = new MinimaxAI(Player.Side.BLACK, 3); MinimaxAI two = new MinimaxAI(Player.Side.WHITE, 4); //RandomAI one = new RandomAI(Player.Side.BLACK); //RandomAI two = new RandomAI(Player.Side.WHITE); //one goes first if true; bool turn = true; //System.out.println(board.toString()); //Scanner sc = new Scanner(System.in); int blackWin = 0; int whiteWin = 0; int c = 0; for (int t = 0; t < total; t++) { Board board = new Board(); Player current = one; if (!turn) { current = two; } c = 0; println(board.toString()); while (c < 10) { //Thread.sleep(500); c++; print(current.toString() + "'s turn: "); //Board.Decision decision = null; Board.Decision decision = Board.Decision.FAILED_INVALID_DESTINATION; //current instanceof AI if (current.GetType() == typeof(MinimaxAI)) { // decision = ((AI)current).makeMove(board); decision = ((MinimaxAI)current).makeMove(board); //------------* } else { /*string text = sc.nextLine(); * if (text.equals("board")) * { * println(board.toString()); * } * if (text.equals("rand")) * { * decision = current.makeRandomMove(board); * } * else * { * string[] split = text.split(" "); * Move m; * if (split.Length == 1) * { * m = new Move(Integer.parseInt(text.charAt(0) + ""), Integer.parseInt(text.charAt(1) + ""), * Integer.parseInt(text.charAt(2) + ""), Integer.parseInt(text.charAt(3) + "")); * } * else * { * int[] s = new int[split.length]; * for (int i = 0; i < split.length; i++) * { * s[i] = Integer.parseInt(split[i]); * } * m = new Move(s[0], s[1], s[2], s[3]); * * * } * decision = current.makeMove(m, board); * }*/ } //System.out.println("Decision: " + decision); if (decision == Board.Decision.FAILED_INVALID_DESTINATION || decision == Board.Decision.FAILED_MOVING_INVALID_PIECE) { println("Move Failed"); // don't update anything } else if (decision == Board.Decision.COMPLETED) { println(board.toString()); if (board.getNumBlackPieces() == 0) { println("White wins with " + board.getNumWhitePieces() + " pieces left"); whiteWin++; break; } if (board.getNumWhitePieces() == 0) { println("Black wins with " + board.getNumBlackPieces() + " pieces left"); blackWin++; break; } if (turn) { current = two; } else { current = one; } turn = !turn; } else if (decision == Board.Decision.ADDITIONAL_MOVE) { println("Additional Move"); } else if (decision == Board.Decision.GAME_ENDED) { //current player cannot move if (current.getSide() == Player.Side.BLACK) { println("White wins"); whiteWin++; } else { println("Black wins"); blackWin++; } break; } } Debug.Log("Game finished after: " + c + " rounds"); //one instanceof MinimaxAI if (one.GetType() == typeof(MinimaxAI)) { Debug.Log("Avg time per move: " + ((MinimaxAI)one).getAverageTimePerMove()); } } Debug.Log("Black won " + (blackWin / total * 100) + "%" + ", White won " + (whiteWin / total * 100) + "%"); Debug.Log("Count move = " + c); }