I have made use of a 2 dimensional integer array to represent the 3x3 grid. Each block therefore has a co-ordinate.eg. grid[0][0].Initially all blocks in the grid are equal to zero. The computer uses ones(1) and the player uses twos(2).The user is prompted to enter the row and column number and their choice is entered.

The problemm arises when the computer has to respond by choosig a block to play in. I thought that i could solve this by generating random numbers. The glitch is that when the same set of random co-ordinates is generated it appears as though the computer hasnt played at all. This means that as yet the game is still un-playable.

Expand|Select|Wrap|Line Numbers

- int row3;
- int col3;
- int win;
- public void game()
- {
- display_grid();
- for(int loop=4;loop>=0&&win!=1;loop--){
- System.out.println("Computers turn:");
- int row2=(int)(Math.random()*2+0);
- int col2=(int)(Math.random()*2+0);
- while(grid[row2][col2]==2||grid[row2][col2]==1){//glitch is somewhere here.
- row3=row2;
- col3=col2;
- }
- grid[row3][col3]=1;
- display_grid();

Thank you.