示例#1
0
int main()
{
    char p1,p2;
    int end=-1,turn,human=-1,next_move=-1,ply_max=8,ch,player,inifact[2]= {8,-8};
    while(1)
    {
        printf("\n1.select X\n2.select O\n3.simulation\n4.quit\n");
        scanf("%d",&ch);
        if(ch==4)
        {
            printf("\nthank u for playing game :) ");
            break;
        }
        initialize();
        turn=0;
        human=-1;
        if(ch==1)
        {
            human=0;
        }
        else if(ch==2)
        {
            human=1;
        }
        disp_board(-1,-1);
        while((end=END(turn))<0)
        {
            player=turn%2;
            if(human==player)
                next_move=user_move();
            else
            {
                printf("\nCOMP%d is choosing move....",player);
                sleep(0.5);
                next_move=chose_move(player,ply_max,0,turn,inifact[player]);
                printf("\nmove choosen: %d",next_move);
            }
            disp_board(player,next_move);
            turn++;
        }

        if(end==0)
        {
            if(human==0)
                printf("\nCongratulations you win !!!!");
            else printf("\nCOMP1 wins the game");
        }
        else if(end==1)
        {
            if(human==1)
                printf("\nCongratulations you win !!!!");
            else printf("\nCOMP2 wins the game");
        }
        else printf("The game ended as a draw");
    }
    return(0);
}
示例#2
0
int
main(int argc, char** argv){
	GAME_STATE game; /*ゲーム構造体*/
	int legal_move = 0; /*1なら合法手*/
	int finish = 0; /*1になるとゲームが終了となる*/

	/*ゲーム状態の初期化*/
	init(&game);
	/*ディスプレイに盤面を出力*/
	disp_board(&game);
	/*ループ*/
	while(finish != 1){
		legal_move = 0;
		while(legal_move != 1){
			if(game.teban == 1){
				get_move(&game); /*人間側*/
			}else{
				think_move(&game); /*コンピュータ側*/
			}
			/*その手が合法手かを判定*/
			legal_move = check_legal_move(&game);
		}

		/*手によって盤面の状態を変更する*/
		make_move(&game);
	
		/*ディスプレイに盤面を表示*/
		disp_board(&game);

		/*終局判定*/
		finish = check_finish_game(&game);

		/*手番を交代する*/
		change_teban(&game);
	}
	exit(0);
}
示例#3
0
void game_main(){
  int squares_dat[SIZE];//全マスのデータ
  int squares_sta[SIZE];//全マスの状態

  init_board(squares_dat, squares_sta);
  
  while(1){
    disp_board(squares_dat, squares_sta);
    
    if(should_continue_game(squares_dat, squares_sta)){
      select_square(squares_dat, squares_sta);
    }else{
      break;
    }
  }
  
}