[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [pbmserv-dev] ForcedMove



>      for (i=0;i==2;i++) {

should be

>      for (i=0;i<=2;i++) {

and ditto for the j loop.

>Coding an implementation of TicTacToe for practice, and my implementation of
>ForcedMove isn't quite up to snuff.  I'm sure I'm missing something obvious,
>but I don't know what it may be.  Moves are made by entering numbers 1-9.
>Code is below.
>
> 1 | 2 | 3
>-----------
> 4 | 5 | 6
>-----------
> 7 | 8 | 9
>
>My logic is: if it's the last turn, you have to play in the only open space.
>Did I miss something?
>
>Mike
>
>const char *Tictactoe::ForcedMove(void)
>{
>
>
>   static char forced[2];
>   int i;
>   int j;
>
>   if (moves.Count() == 8)  {
>      for (i=0;i==2;i++) {
>         for (j=0;j==2;j++) {
>	    if (IsBlank(i,j)) {
>                 sprintf(forced,"%c",i*3+j+1);
>	         return forced;
>             }
>         }
>      }
>   }
>   return NULL;
>}