package Inteligence;
import basicObjects.boardObjects.Board;
public class ArtificalInteligence {
private int nodeCount;
private Node rootNode;
public ArtificalInteligence(Board board) {
Board newBoard = new Board(board);
rootNode = new Node(newBoard);
}
public int Move() {
int max = -10;
Node bestNode = new Node();
for (int i = 0; i < 16; i++) {
Node node = new Node();
node.copy(rootNode);
// if(node.getBoard().SetMove(i, )==true){ //have to add in the piece you want to play here.
rootNode.AddChildren(node);
node.setMoveBox(i);
int val = minimaxAB(node, true, 100, -10, 10);
if (val >= max) {
max = val;
bestNode = node;
}
}
return bestNode.getMoveBox();
}
private int minimaxAB(Node node, boolean min, int depth, int alpha, int beta) {
if (boardPoint(node) != 2) {
node.setPoint(boardPoint(node));
return boardPoint(node);
} else {
if (min == true) {
for (int x = 0; x < 16; x++) {
Node n = new Node();
n.copy(node);
if (n.getBoard().setMove(x, null) == true) {
node.AddChildren(n);
n.setMoveBox(x);
int val = minimaxAB(n, false, depth - 1, alpha, beta);
if (val < beta) {
beta = val;
n.getParent().setPoint(val);
}
}
}
return beta;
}
if (min == false) {
for (int x = 0; x < 16; x++) {
Node n = new Node();
n.copy(node);
if (n.getBoard().setMove(x, null) == true) {
node.AddChildren(n);
n.setMoveBox(x);
int val = minimaxAB(n, true, depth - 1, alpha, beta);
if (val > alpha) {
alpha = val;
n.getParent().setPoint(val);
}
}
}
return alpha;
}
}
return -100;
}
/*
* private int boardPoint(Node n){ if(n.getBoard().checkConditions() == 1){
* return -1; } if(n.getBoard().checkConditions() == 2){ return 1; }
* if(n.getBoard().checkConditions() == -1){ return 0; } return - 2; }
*/
}