Esempio n. 1
0
/*----------------------------------------------------------------------------*/
void  
set_rating_handicap (double rating) 
{
  int h, handicap, i, j;
  YT_GOBAN *goban = pa->goban;

  handicap = (int) (fabs(rating));

  if (rating >= 0) { // первый ход - компутер
    for (h = 0; h < handicap; h++) {
      //computer_move (); 
      //if (goban_random_stone_new (goban, &i, &j))
      if (goban_random_handicap (goban, handicap, &i, &j))
        goban_set_move (goban, i, j, STONE_WHITE);
    }
  ////////////
  } else {
  ////////////
    for (h = 0; h < handicap; h++) {
      //if (goban_random_stone_new (goban, &i, &j)) // не сработает только, если нет места
      if (goban_random_handicap (goban, handicap, &i, &j)) // не сработает только, если нет места
        human_move (i, j); 
    }
    computer_move (STONE_WHITE); 
  }

  return;
}
int main() {
  int i,j;
  char again[2],winner,**board;
   
  board=(char**)malloc(sizeof(char*)*3);
  for (i=0; i<3; i++) {
    board[i]=(char*)malloc(sizeof(char)*3);
  }
  
  printf("\nWelcome to a game of Tic-Tac-Toe!\n");   
  do {
    board=initboard(board);
    displayboard(board);
    do {
      board=human_move(board,PLAYER1);
  	  displayboard(board);
	    winner=checkwin(board,PLAYER1);
    	if (winner!=PLAYER1 && winner!=' ') {
	      if (computer_move(board,PLAYER2,PLAYER1)) {
	        winner=checkwin(board,PLAYER2);
	      } else {
          printf("\nComputer passed\n");
	      }
	      displayboard(board);
	    }
	  } while (winner==BLANK);
	  
  	if (winner!=' ') {
  	  printf("THE WINNER IS %c!\n",winner);
  	} else {
	    printf("IT'S A TIE.\n");
	  }	 
	  
  	printf("\nPlay again (y)?: ");
	  scanf("%s",again);
  } while(again[0]=='y');

  for (i=0; i<3; i++) {
    free(board[i]);
  }
  free(board);
   
  printf("\nThank you for playing.\n\n");
  return 0;
}
Esempio n. 3
0
/*----------------------------------------------------------------------------*/
void  
baby_onestep_moves (int i, int j) 
{

  if (i == -1 && j == -1) {
    // комп играет сам с собой, т.е. делает ход за человека
    if (! computer_move (STONE_BLACK)) return; 
  }
  else {
    if (! human_move (i, j)) {return; OUTD (555);}
  }

  if (update_check_end ()) return;

  //draw_status ("Я думаю.."); 
  if (! computer_move (STONE_WHITE)) return; 

  if (update_check_end ()) return;
  //draw_status ("Ваш ход.."); 

  return;
}
Esempio n. 4
0
int main()
{
   srand((time(0)));

   int i,j;
   char again[2],winner,**board,agin='y';

   board=(char**)malloc(sizeof(char*)*3);
   for (i=0; i<3; i++)
      board[i]=(char*)malloc(sizeof(char)*3);

    do {
        board=initboard(board);
        char first = 'y';
        printf("Play first? ");
        scanf("%c",&first);
        displayboard(board);
        if (first == 'y'){
            do {
                board=human_move(board,PLAYER1);
                displayboard(board);
                winner=checkwin(board,PLAYER1);
                if (winner!=PLAYER1 && winner!=' ') {
                   if (computer_move(board,PLAYER2,PLAYER1))
                       winner=checkwin(board,PLAYER2);
                   else
                       printf("\nComputer passed\n");
                   displayboard(board);
                }
            } while (winner==BLANK);
        }else{
            do{
                if (computer_move(board,PLAYER2,PLAYER1))
                   winner=checkwin(board,PLAYER2);
               else
                   printf("\nComputer passed\n");
               displayboard(board);
               if (winner!=PLAYER2 && winner!=' ') {
                    board=human_move(board,PLAYER1);
                    winner=checkwin(board,PLAYER1);
                    displayboard(board);
               }
            }while (winner == BLANK);
        }

        if (winner!=' ')
            printf("THE WINNER IS %c!\n",winner);
        else
            printf("IT'S A TIE.\n");

        printf("\nPlay again (y)?: ");
        scanf("%s",again);
        getchar();
    } while(again[0]=='y');
//         getchar();
//         scanf("%c",&agin);
//     } while(agin=='y');

    //Free Allocated Space
    for (i=0; i<3; i++)
        free(board[i]);
    free(board);

   printf("\nThank you for playing.\n\n");
   return 0;
}