# Artificial intelligence coding problems

• 02-26-2010, 09:24 AM
MuslimCoder
Artificial intelligence coding problems
Hey,

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...

Code:

``` //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)       {       System.out.println("in\$");         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     return b;             }```
• 02-26-2010, 04:30 PM
FlyNn
I've been working on a little tic-tac-toe game myself for the last two days. I am about to write some sort off code that can "play against" me just by looking for what fields are taken and what fields the opponent needs to get to win the game. Depending of the results received, rules for the code will determine the best proposition for the next move. I assume it will not be much of AI anyway. I am not 100% sure what you are asking though