Oct 13, 2008 at 1:29am UTC
I'm currently trying my hand at a simple tic tac toe program with a simple AI that doesn't act based on branch logic. I've setup the grid and for some reason I can't get it to return the numbers 1 - 9 in the grid from left to right and top to bottom,
here's the code,
[code]/#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
unsigned char O = 'O';
unsigned char X = 'X';
int x = 0;
int y = 0;
bool moveisvalid(false);
bool isfirstmove(true);
bool isAIturn(true);
// initialises the grid, organises it into rows, columns and diagonals, adds functionality to AI grid recognition
int square[2] [2];
int lnx1[3] = { square[0] [0], square[1] [0], square[2] [0] };
int lnx2[3] = { square[0] [1], square[1] [1], square[2] [1] };
int lnx3[3] = { square[0] [2], square[1] [2], square[2] [2] };
int lny1[3] = { square[0] [0], square[0] [1], square[0] [2] };
int lny2[3] = { square[1] [0], square[1] [1], square[1] [2] };
int lny3[3] = { square[2] [0], square[2] [1], square[2] [2] };
int lncrslr[3] = { square[0] [0], square[1] [1], square[2] [2] };
int lncrsrl[3] = { square[2] [0], square[1] [1], square[0] [2] };
int gridthink[8] = { lnx1[3], lnx2[3], lnx3[3], lny1[3], lny2[3], lny3[3], lncrslr[3], lncrsrl[3] };
void main()
{
for( int ndisp = 1; ndisp <= 9; ndisp++ )
{
if( x == 3 ) { y += 1; x = 0;}
square[x] [y] = ndisp;
x += 1;
}
cout << square[0] [0] << '|' << square[1] [0] << '|' << square[2] [0] << '\n'
<< square[0] [1] << '|' << square[1] [1] << '|' << square[2] [1] << '\n'
<< square[0] [2] << '|' << square[1] [2] << '|' << square[2] [2] << '\n';
[code]
any help here would be appreciated :)
Last edited on Oct 13, 2008 at 1:35am UTC
Oct 13, 2008 at 1:51am UTC
oh yeah... workd perfec' now. thanks a bunch
Last edited on Oct 13, 2008 at 1:52am UTC