this may take a few moments but it is appreciated....
as astart to a game of noughts and crosses i am using djgpp on win 98, place takes values 1-9, a_1[9] takes values 0-8 as can be seen from the code. board display(a) is just a printf function for a_1[9] to print either 1's,5's or 0's.place_it() just gets a user input.
the problem is if there is already a 5 on the board then
placing a 1 in that position puts a 1 there but you can also
place a 1 elsewhere afterwards because it has been told to
loop unless a nought is there. however if you place a 1 twice or more times and then replace the one it works just
fine. i think it is the recursive function part maybe?
any help would do thanks in advance.
int check_nought( int place, int a_1[] )
{
if ( ((place==1) && (a_1[place - 1]==0)) ||
((place==2) && (a_1[place - 1]==0)) ||
((place==3) && (a_1[place - 1]==0)) ||
((place==4) && (a_1[place - 1]==0)) ||
((place==5) && (a_1[place - 1]==0)) ||
((place==6) && (a_1[place - 1]==0)) ||
((place==7) && (a_1[place - 1]==0)) ||
((place==8) && (a_1[place - 1]==0)) ||
((place==9) && (a_1[place - 1]==0)) )
a_1[place - 1 ] = 1;
else
{
board_display( a );
place = place_it();
check_nought(place, a_1);
}
return a_1[place - 1];
}
as astart to a game of noughts and crosses i am using djgpp on win 98, place takes values 1-9, a_1[9] takes values 0-8 as can be seen from the code. board display(a) is just a printf function for a_1[9] to print either 1's,5's or 0's.place_it() just gets a user input.
the problem is if there is already a 5 on the board then
placing a 1 in that position puts a 1 there but you can also
place a 1 elsewhere afterwards because it has been told to
loop unless a nought is there. however if you place a 1 twice or more times and then replace the one it works just
fine. i think it is the recursive function part maybe?
any help would do thanks in advance.
int check_nought( int place, int a_1[] )
{
if ( ((place==1) && (a_1[place - 1]==0)) ||
((place==2) && (a_1[place - 1]==0)) ||
((place==3) && (a_1[place - 1]==0)) ||
((place==4) && (a_1[place - 1]==0)) ||
((place==5) && (a_1[place - 1]==0)) ||
((place==6) && (a_1[place - 1]==0)) ||
((place==7) && (a_1[place - 1]==0)) ||
((place==8) && (a_1[place - 1]==0)) ||
((place==9) && (a_1[place - 1]==0)) )
a_1[place - 1 ] = 1;
else
{
board_display( a );
place = place_it();
check_nought(place, a_1);
}
return a_1[place - 1];
}