Skip to content

Commit

Permalink
Fixed Phase 2
Browse files Browse the repository at this point in the history
  • Loading branch information
mssalkhalifah committed Jul 12, 2020
1 parent ab463a9 commit 74c826c
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 13 deletions.
5 changes: 1 addition & 4 deletions core/src/com/groupg/game/Game.java
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -13,15 +11,14 @@ 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);
blackPlayer = new Player(myGame.getCamera(), PieceColor.BLACK);
gameBoard = new Board();
gameBoard.initialize();
gameState = new GameState(whitePlayer, blackPlayer, gameBoard);
evaluationBoard = new Evaluation();
blackPlayer.setAI(true);
}

public void update(float delta) {
Expand Down
34 changes: 31 additions & 3 deletions core/src/com/groupg/game/ai/MiniMax.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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) {
Expand Down
19 changes: 13 additions & 6 deletions core/src/com/groupg/game/player/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}
}

Expand Down Expand Up @@ -108,4 +111,8 @@ public boolean isAction() {
public void setAction(boolean action) {
this.action = action;
}

public void setAI(boolean AI) {
isAI = AI;
}
}

0 comments on commit 74c826c

Please sign in to comment.