Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

#Actualarkane7

Posted 19 October 2012 - 10:26 AM

If all you're actually trying to do is find the first empty space and replace it with an O then this would do it:

//Set all spaces to ' ' when you initialize the board
for (int i = 0; i < 8; ++i)	 //Where 8 is the size of the board
{
	 board[i] = ' ';
}
//Then when you're wanting to replace the first empty space wth 'O'
for (int i = 0; i < 8; ++i)
{
	 if (board[i] == ' ')
		 board[i] = 'O';
}



if you do not put a break in that if statement, it will change ALL empty spaces into O's, rather than the first one you find

If (board[i] =='')
{
   board [i] = 'O';
  break;
}

that way only one empty is changed

also i think you may want 9 instead of 8; arent there 9 tiles in TTT?

#2arkane7

Posted 19 October 2012 - 10:23 AM

If all you're actually trying to do is find the first empty space and replace it with an O then this would do it:


//Set all spaces to ' ' when you initialize the board
for (int i = 0; i < 8; ++i)	 //Where 8 is the size of the board
{
	 board[i] = ' ';
}

//Then when you're wanting to replace the first empty space wth 'O'
for (int i = 0; i < 8; ++i)
{
	 if (board[i] == ' ')
	   {		   
		   board[i] = 'O';
		   [b]break; [/b]
		}



if you do not put a break in that if statement, it will change ALL empty spaces into O's, rather than the first one you find

#1arkane7

Posted 19 October 2012 - 10:22 AM

If all you're actually trying to do is find the first empty space and replace it with an O then this would do it:


//Set all spaces to ' ' when you initialize the board
for (int i = 0; i < 8; ++i)	 //Where 8 is the size of the board
{
	 board[i] = ' ';
}

//Then when you're wanting to replace the first empty space wth 'O'
for (int i = 0; i < 8; ++i)
{
	 if (board[i] == ' ')
	   [color=#ff0000] { [/color]
		   board[i] = 'O';
		   [color=#ff0000]break; [/color]
	    [color=#ff0000]} [/color]
}



if you do not put a break in that if statement, it will change ALL empty spaces into O's, rather than the first one you find

PARTNERS