コード例 #1
0
ファイル: fish.c プロジェクト: jyin0813/OpenBSD-src
int
main(int argc, char *argv[])
{
	int ch, move;

	while ((ch = getopt(argc, argv, "ph")) != -1)
		switch(ch) {
		case 'p':
			promode = 1;
			break;
		case '?':
		case 'h':
		default:
			usage();
		}

	srandomdev();
	instructions();
	init();

	if (nrandom(2) == 1) {
		printplayer(COMPUTER);
		(void)printf("get to start.\n");
		goto istart;
	}
	printplayer(USER);
	(void)printf("get to start.\n");
	
	for (;;) {
		move = usermove();
		if (!comphand[move]) {
			if (gofish(move, USER, userhand))
				continue;
		} else {
			goodmove(USER, move, userhand, comphand);
			continue;
		}

istart:		for (;;) {
			move = compmove();
			if (!userhand[move]) {
				if (!gofish(move, COMPUTER, comphand))
					break;
			} else
				goodmove(COMPUTER, move, comphand, userhand);
		}
	}
	/* NOTREACHED */
}
コード例 #2
0
ファイル: fish.c プロジェクト: msharov/bsd-games
int main (void)
{
    initialize_curses();
    initialize_windows();
    shuffle_deck_and_deal();
    instructions();

    enum EPlayer player = nrand(NPLAYERS);
    printplayer (player);
    waddstr (_wmsg, "get to start.\n");
    for (;;) {
	unsigned m = makemove (player);
	if (_hand[OTHER(player)][m])
	    goodmove (player, m);
	else if (!gofish (player, m))
	    player = OTHER(player);
    }
    return EXIT_SUCCESS;
}
コード例 #3
0
ファイル: main5.c プロジェクト: naoto0804/reversi
int main(int argc, char **argv)
{
  srand((unsigned) time(NULL));
  int board[8][8];//グローバル変数ではなく、いちいち渡すことに
  const int random_side = (argc >= 2) ? atoi(argv[1]) : 0;//MANの先攻後攻の決定
  init_board(board);

  int turn;
  int pass=0;
  for (turn = 1;; turn *= -1) {//先手の時はturn=1,後手の時はturn=-1
    print_board(board);
    Pair legal_moves[60];//合法手を全て収納するための配列
    const int nmoves = generate_all_legal_moves(turn, legal_moves,board);//空きマス0能時にnamoves=-1を返す ←一回目のここで既に何かミスってる
    if (nmoves == -1) break;     // no empty square→ゲーム終了
    if (nmoves ==  0) {
      pass++;
      printf("turn = %d, move = Pass\n", turn);//パスの処理
      if(pass>=2){
	break;
      }
      continue;  
    }else{//passの初期化
      pass=0;
    }

    Pair move;
    if (turn == random_side) {//人間側の操作のとき。com同士ならこれはおこらない
      move = legal_moves[rand()%nmoves];  //ランダム選択
      assert(is_legal_move(turn,move,board));
    } else {//COM側の操作
      move = goodmove(turn,board);//turnは少なくとも必要
      assert(is_legal_move(turn,move,board));//念のため。最適解がちゃんとlegalmoveか確認
    }
    place_disk(turn, move,board);//moveをそもそも受け取れていなかった
    printf("turn = %d, move = %c%c\n", turn, 'a' + move.x, '1' + move.y);
  }//breakするまでfor文は繰り返す
  judge(random,board);//先攻か後攻かを返す
  return 0;
}