Basically, I have a program that simulates a game of Kalah, I have an AI player that evaluates each mvoe possible to see if it is a good move.
Here is the code for this:
package kalah; public class IntelligentPlayer extends KalaPlayer { public IntelligentPlayer() { } public int chooseMove(KalaGameState gs) throws NoMoveAvailableException { for (int move = 1; move < 7; move++) { int evalValue[] = new int[7]; int maxEval = 0; int maxEvalMove = 0; KalaGameState clone = (KalaGameState) gs.clone(); if (clone.getNumStones(move - 1) > 0) { clone.getTurn(); try { clone.makeMove(move); } catch (IllegalMoveException ex) { } int firstScore = clone.getScore(0); int secondScore = clone.getScore(1); if (clone.playerTurn == 0) { evalValue[move] = firstScore - secondScore; } else { evalValue[move] = secondScore - firstScore; } if (evalValue[move] > evalValue[move - 1]) { maxEval = evalValue[move]; maxEvalMove = move; } }} return maxEvalMove;}
This is probably a retarded question, but like I said I am a beginner.
It doesn't seem to be able to find the maxEvalMove variable even though it is defined in the for loop. Any quick solutions, I tried to move the declaration of the variables outside the for loop, but the computer just plays move 0 every time.
Thanks for your help!