I am trying to create a simple AI (for four in a line). I have looked online and found a few complicated AI's but they were to complex for me. I am trying to use recursion and maxDepth to create an AI to play two moves ahead.
public class AIMove { //holds a score, column pair. int Score; int col; AIMove(int s,int c) { Score=s; col=c; } AIMove() { Score=col=0; } class Connect4 { byte gameBoard[][]=new byte[7][6]; //Circle[][] gameBoard = new Circle[7][6]; //the connect 4 board. 0 means empty AIMove recursiveMinMax(byte placement, int depth, int maxDepth) {//Find the best move for the placement. Returns column and score pair //depth specifies current level of depth (should be passed as 0) //maxDepth specifies the maximum depth to search AIMove goodness = new AIMove(-120000,0); if(depth%2==1)goodness.Score*=-1; /* * * for i = 1 to 7 if column i is not full { drop coin into column i value = -Goodness(-player,depth-1) / 2 remove coin from column i if value > max max = value } return max } */ AIMove value=new AIMove(); for (int i=0;i<7;i++) { //try putting a piece at each of 7 columns. value.col=i; if(gameBoard[0][i]!=0) continue; //if column is full ignore it. //find the row to put this piece. x is the row int x=0;
Any help or examples will be greatly appreciated. Thanks!