Artificial intelligence coding problems
I am having problem coding a class in ont of ai packages we are suppose to create for our project, it is suppose to be a tic tac toe game and this class in particular deals everything to do with the state including making a move, checking if the current state is a win state etc.
i created some methods to help me determine the win states , they are the neighbour methods, each time a person makes a move it find the North, North East , East .... neighbours of the move to see if they are same, if they are same it ends the game , determines the winner.
The noeighbours work find but the problem is checking them, it always seems to return true . here is a code peak...
//checks a the values in a given set of poitn to see if they are same and returns true if they are
//else it returns false
public boolean areSame(Vector<Point> nbrs)
Point p1, p2;
int v1, v2;
boolean b = true; // b starts with true because we need it for and operations which would determine
System.out.printf("no. of elements", nbrs.size() );
for(int i = 1; i < nbrs.size() - 1 ; ++i)
p1 = nbrs.elementAt(i); v1 = board[(int)p1.getX()] [(int)p1.getY()];
p2 = nbrs.elementAt(i + 1); v2 = board[(int)p2.getX()] [(int)p2.getY()];
System.out.printf("v1: %d , v2: %d", v1,v2);
b = b && (v1 == v2); // get the and of the last value(or first) with that of the next
}//this part of the code is only reached when all are same so we can return true