From 74c826cd40d0d1b2cfa6af8d76e6e5f877b76a5c Mon Sep 17 00:00:00 2001 From: mssalkhalifah Date: Sun, 12 Jul 2020 22:35:45 +0300 Subject: [PATCH] Fixed Phase 2 --- core/src/com/groupg/game/Game.java | 5 +-- core/src/com/groupg/game/ai/MiniMax.java | 34 +++++++++++++++++++-- core/src/com/groupg/game/player/Player.java | 19 ++++++++---- 3 files changed, 45 insertions(+), 13 deletions(-) diff --git a/core/src/com/groupg/game/Game.java b/core/src/com/groupg/game/Game.java index cd78bde..1483912 100644 --- a/core/src/com/groupg/game/Game.java +++ b/core/src/com/groupg/game/Game.java @@ -1,10 +1,8 @@ package com.groupg.game; import com.badlogic.gdx.graphics.g2d.SpriteBatch; -import com.groupg.game.ai.Evaluation; import com.groupg.game.ai.MiniMax; import com.groupg.game.board.Board; -import com.groupg.game.board.PointsPosition; import com.groupg.game.gameobject.PieceColor; import com.groupg.game.player.Player; @@ -13,7 +11,6 @@ public class Game { private GameState gameState; private Player whitePlayer; private Player blackPlayer; - private Evaluation evaluationBoard; public Game(MyGame myGame) { whitePlayer = new Player(myGame.getCamera(), PieceColor.WHITE); @@ -21,7 +18,7 @@ public Game(MyGame myGame) { gameBoard = new Board(); gameBoard.initialize(); gameState = new GameState(whitePlayer, blackPlayer, gameBoard); - evaluationBoard = new Evaluation(); + blackPlayer.setAI(true); } public void update(float delta) { diff --git a/core/src/com/groupg/game/ai/MiniMax.java b/core/src/com/groupg/game/ai/MiniMax.java index 1e38595..2063fe4 100644 --- a/core/src/com/groupg/game/ai/MiniMax.java +++ b/core/src/com/groupg/game/ai/MiniMax.java @@ -5,7 +5,6 @@ import com.groupg.game.board.Board; import com.groupg.game.board.PointsPosition; import com.groupg.game.gameobject.PieceColor; -import com.groupg.game.gameobject.Point; import com.groupg.game.player.Player; import java.util.ArrayList; @@ -40,7 +39,7 @@ public static int getBestOpeningPhaseMove(Board board, GameState gameState, Play gameState.firstPhase(blackPlayer); } else if (gameState.getGameStates().peek() == State.CAPTURE) { for (int i = 0; i < PointsPosition.NUMBER_OF_POINTS; i++) { - if (!PointsPosition.checkMill(i, board.getBitBoard(PieceColor.WHITE))) { + if (board.getBitBoard(PieceColor.WHITE).get(i) && !PointsPosition.checkMill(i, board.getBitBoard(PieceColor.WHITE))) { // AI Captures a piece board.getBitBoard(PieceColor.WHITE).clear(i); @@ -190,7 +189,36 @@ private static int miniMaxSecondPhase(Board board, int depth, int alpha, int bet } private static int midPhaseStaticEvaluation(Board board) { - return openingPhaseStaticEvaluation(board); + count++; + + int numberOfWhiteMills = getNumberOfMills(board, false); + int numberOfBlackMills = getNumberOfMills(board, true); + + int lastMorris; + if (numberOfBlackMills - numberOfWhiteMills > 0) { + lastMorris = 1; + } else if (numberOfBlackMills - numberOfWhiteMills < 0) { + lastMorris = -1; + } else { + lastMorris = 0; + } + + int numberOfBlockedBlack = getNumberOfBlockedOpponentPieces(board, false); + int numberOfBlockedWhite = getNumberOfBlockedOpponentPieces(board, true); + + int numberOfBlackPieces = 0; + int numberOfWhitePieces = 0; + for (int i = 0; i < PointsPosition.NUMBER_OF_POINTS; i++) { + if (board.getBitBoard(PieceColor.WHITE).get(i)) numberOfWhitePieces++; + if (board.getBitBoard(PieceColor.BLACK).get(i)) numberOfBlackPieces++; + } + + int winConfig = 0; + if (numberOfBlackPieces < 3) winConfig = -1; + if (numberOfWhitePieces < 3) winConfig = 1; + + return 14 * (numberOfBlackMills - numberOfWhiteMills) + 43 * (lastMorris) + 10 * (numberOfBlockedWhite - numberOfBlockedBlack) + + 11 * (numberOfBlackPieces - numberOfWhitePieces) + 1086 * winConfig; } private static int openingPhaseStaticEvaluation(Board board) { diff --git a/core/src/com/groupg/game/player/Player.java b/core/src/com/groupg/game/player/Player.java index ee28afb..9a1fdd0 100644 --- a/core/src/com/groupg/game/player/Player.java +++ b/core/src/com/groupg/game/player/Player.java @@ -10,6 +10,7 @@ public class Player { public static final int NUMBER_OF_PLAYER_PIECES = 9; private boolean action; + private boolean isAI; private int totalNumberOfPieces; private int currentNumberOfPieces; @@ -33,12 +34,14 @@ public Player(OrthographicCamera camera, PieceColor pieceColor) { } public void update(double delta) { - mousePosition.set(Gdx.input.getX(), Gdx.input.getY(), 0); - camera.unproject(mousePosition); - - if (isPlay() || action) { - touchPosition.set(Gdx.input.getX(), Gdx.input.getY(), 0); - camera.unproject(touchPosition); + if (!isAI) { + mousePosition.set(Gdx.input.getX(), Gdx.input.getY(), 0); + camera.unproject(mousePosition); + + if (isPlay() || action) { + touchPosition.set(Gdx.input.getX(), Gdx.input.getY(), 0); + camera.unproject(touchPosition); + } } } @@ -108,4 +111,8 @@ public boolean isAction() { public void setAction(boolean action) { this.action = action; } + + public void setAI(boolean AI) { + isAI = AI; + } }