Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * This class implements and evaluates game situations of a TicTacToe game.
- */
- public class TicTacToe {
- /**
- * Returns an evaluation for player at the current board state.
- * Arbeitet nach dem Prinzip der Alphabeta-Suche. Works with the principle of Alpha-Beta-Pruning.
- *
- * @param board current Board object for game situation
- * @param player player who has a turn
- * @return rating of game situation from player's point of view
- **/
- public static int alphaBeta(Board board, int player)
- {
- // TODO
- return alphaBeta(board, player, -Integer.MAX_VALUE, Integer.MAX_VALUE, 0);
- }
- //return alphabeta(1, -Integer.MAX_VALUE, Integer.MAX_VALUE);}
- public static int alphaBeta(Board board, int player, int alpha, int beta, int depth) {
- if (board.isGameWon()) {
- return player * (1 + board.free_fields);
- }
- else if (board.free_fields == 0){ //es gibt keine freie felder
- return 0;
- }
- for (Position pos_move : board.validMoves()) {
- board.doMove(pos_move, player);
- int score = - alphaBeta(board, -player, -beta, -alpha, 0);
- board.undoMove(pos_move);
- if (score > alpha) {
- alpha = score;
- if (alpha >= beta) break;
- }
- }
- return alpha;
- }
- /**
- * Vividly prints a rating for each currently possible move out at System.out.
- * (from player's point of view)
- * Uses Alpha-Beta-Pruning to rate the possible moves.
- * formatting: See "Beispiel 1: Bewertung aller Zugmöglichkeiten" (Aufgabenblatt 4).
- *
- * @param board current Board object for game situation
- * @param player player who has a turn
- **/
- public static void evaluatePossibleMoves(Board board, int player)
- {
- // TODO
- }
- public static void main(String[] args)
- {
- Board first_board = new Board(3); //leeres Board erstellt
- //Position pos1 = new Position(1, 1);
- //first_board.doMove(pos1, 1); //x gesetzt
- first_board.print();
- System.out.println("Score fuer Spieler 1 : " + TicTacToe.alphaBeta(first_board, 1));
- System.out.println("Score fuer Spieler -1 : " + TicTacToe.alphaBeta(first_board, -1));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement