Пример #1
0
void board::generation()
{
	srand(time(0));

	if (playerone.tosses<5)
	{
		playerone.x=rand()%10;
		playerone.y=rand()%10;

		if (pitch[playerone.y][playerone.x]=='P')
		{
			generation();
		}
		else
		{
			system("cls");
			scoring();
			pitch[playerone.y][playerone.x]='P';
			playerone.tosses++;
			showboard();
			cout<<"Score for that throw "<<playerone.throwscore<<endl;
			cout<<"Number of tosses "<<playerone.tosses<<"/5"<<endl;
			wait();
			system("pause");
			generation();
		}
	}
	else
	{
		system("cls");
	}

}
void
decide_eye(int pos)
{
  int color;
  struct eyevalue value;
  int attack_point;
  int defense_point;
  int eyepos;
  SGFTree tree;

  reset_engine();
  silent_examine_position(BLACK, EXAMINE_DRAGONS_WITHOUT_OWL);
  
  if (black_eye[pos].color == BLACK_BORDER) 
    color = BLACK;
  else if (white_eye[pos].color == WHITE_BORDER) 
    color = WHITE;
  else {
    gprintf("The eye at %1m is not of a single color.\n", pos);
    return;
  }

  if (printboard)
    showboard(0);

  /* Enable sgf output. */
  if (*outfilename)
    sgffile_begindump(&tree);
  count_variations = 1;
  
  if (black_eye[pos].color == BLACK_BORDER) {
    eyepos = black_eye[pos].origin;
    compute_eyes(eyepos, &value, &attack_point, &defense_point,
		 black_eye, half_eye, 0, EMPTY);
    gprintf("Black eyespace at %1m: %s\n", eyepos, eyevalue_to_string(&value));
    if (eye_move_urgency(&value) > 0) {
      gprintf("  vital points: %1m (attack) %1m (defense)\n", attack_point,
	      defense_point);
    }
  }
  
  if (white_eye[pos].color == WHITE_BORDER) {
    eyepos = white_eye[pos].origin;
    compute_eyes(eyepos, &value, &attack_point, &defense_point,
		 white_eye, half_eye, 0, EMPTY);
    gprintf("White eyespace at %1m: %s\n", eyepos, eyevalue_to_string(&value));
    if (eye_move_urgency(&value) > 0) {
      gprintf("  vital points: %1m (attack) %1m (defense)\n", attack_point,
	      defense_point);
    }
  }
  
  /* Finish sgf output. */
  sgffile_enddump(outfilename);
  count_variations = 0;
}
Пример #3
0
void winplayer(int pawn, int **board)
{
  printf("******************************************************\n");
  showboard(board);
  if(pawn==1){
    printf("先手の勝利です!\n");
    }
  if(pawn==-1){
    printf("後手の勝利です!\n");
    }
  exit(1);
}
Пример #4
0
int main()
{
	srand(time(0));

	system("cls");
	showboard();
	z++;
	cout<<"Number of moves "<<z<<endl;
	move();
	wait();
	main();

	return 0;
}
Пример #5
0
void gameflow(int **board)
{
  int i,j=0;
  int count_turn=0;
  while(1){
    if(count_turn >= n){
      printf("上限手数に達したため引き分けとします!\n" );
      exit(0);
      }
    count_turn++;
    printf("******************************************************\n");
    printf("%dターン目です。\n",count_turn);
    showboard(board);
    attack(board,count_turn);
    }
  return;
  }
Пример #6
0
int main()
{

	player1.x=11;
	player1.y=0;
	player2.x=11;
	player2.y=0;
	player3.x=11;
	player3.y=0;

	showboard();

	while(player1.x>0||player2.x>0||player3.x>0)
advances to the end of the game board
	{
	sort();
smaller
	}
	return 0;
}
Пример #7
0
const char* game(int user)
{
	int i, j, k, move, win = 0;
	for_ij b[i][j] = 0;
 
	printf("Board postions are numbered so:\n1 2 3\n4 5 6\n7 8 9\n");
	printf("You have O, I have X.\n\n");
	for (k = 0; k < 9; k++, user = !user) {
		while(user) {
			printf("your move: ");
			if (!scanf("%d", &move)) {
				scanf("%*s");
				continue;
			}
			if (--move < 0 || move >= 9) continue;
			if (b[i = move / 3][j = move % 3]) continue;
 
			b[i][j] = 1;
			break;
		}
		if (!user) {
			if (!k) { /* randomize if computer opens, less boring */
				best_i = rand() % 3;
				best_j = rand() % 3;
			} else
				test_move(-1, 0);
 
			b[best_i][best_j] = -1;
			printf("My move: %d\n", best_i * 3 + best_j + 1);
		}
 
		showboard();
		if ((win = check_winner())) 
			return win == 1 ? "You win.\n\n": "I win.\n\n";
	}
	return "A draw.\n\n";
}
Пример #8
0
/*
 * Play a single game
 * Reset the word lists from last game
 * Keep track of the running stats
 */
void
playgame(void)
{
	int i, *p, *q;
	time_t t;
	char buf[MAXWORDLEN + 1];

	ngames++;
	npwords = 0;
	pwordsp = pwords;
	nmwords = 0;
	mwordsp = mwords;

	time(&start_t);

	q = &wordpath[MAXWORDLEN + 1];
	p = wordpath;
	while (p < q)
		*p++ = -1;
	showboard(board);
	startwords();
	if (setjmp(env)) {
		badword();
		goto timesup;
	}

	while (1) {
		if (get_line(buf) == NULL) {
			if (feof(stdin))
				clearerr(stdin);
			break;
		}
		time(&t);
		if (t - start_t >= tlimit) {
			badword();
			break;
		}
		if (buf[0] == '\0') {
			int remaining;

			remaining = tlimit - (int) (t - start_t);
			(void)snprintf(buf, sizeof(buf),
			    "%d:%02d", remaining / 60, remaining % 60);
			showstr(buf, 1);
			continue;
		}
		if (strlen(buf) < (size_t)minlength) {
			badword();
			continue;
		}

		p = wordpath;
		while (p < q && *p != -1)
			*p++ = -1;
		usedbits = 0;

		if (checkword(buf, -1, wordpath) < 0)
			badword();
		else {
			if (debug) {
				(void) printf("[");
				for (i = 0; wordpath[i] != -1; i++)
					(void) printf(" %d", wordpath[i]);
				(void) printf(" ]\n");
			}
			for (i = 0; i < npwords; i++) {
				if (strcmp(pword[i], buf) == 0)
					break;
			}
			if (i != npwords) {	/* already used the word */
				badword();
				showword(i);
			}
			else if (!validword(buf))
				badword();
			else {
				int len;

				if (npwords == maxpwords - 1) {
					maxpwords += MAXPWORDS;
					pword = realloc(pword,
					    maxpwords * sizeof(char *));
					if (pword == NULL) {
						cleanup();
						errx(1, strerror(ENOMEM));
					}
				}
				len = strlen(buf) + 1;
				if (pwordsp + len >= &pwords[maxpspace]) {
					maxpspace += MAXPSPACE;
					pwords = realloc(pwords, maxpspace);
					if (pwords == NULL) {
						cleanup();
						errx(1, strerror(ENOMEM));
					}
				}
				pword[npwords++] = pwordsp;
				memcpy(pwordsp, buf, len);
				pwordsp += len;
				addword(buf);
			}
		}
	}

timesup: ;

	/*
	 * Sort the player's words and terminate the list with a null
	 * entry to help out checkdict()
	 */
	qsort(pword, npwords, sizeof(pword[0]), compar);
	pword[npwords] = NULL;

	/*
	 * These words don't need to be sorted since the dictionary is sorted
	 */
	checkdict();

	tnmwords += nmwords;
	tnpwords += npwords;

	results();
}
Пример #9
0
void endgame(void)
/* count pieces and announce the winner */
{
  char an[10];
  int i, j, k, N, mtot, utot, cont;
  int mymovelist[NODES][5];
  int umovelist[NODES][5];

  printf("\nTo count score, we need the following steps:\n");
  printf("First, I need you to remove all dead pieces on the board.\n");
  printf("Second, I need you to fill in neutral territories with ");
  printf("pieces.\n");
  printf("Last, I will fill in all pieces and announce the winner.\n");

/* remove dead pieces */
  printf("\nFirst, you should enter the dead pieces (black and white) to");
  printf(" be removed.  Enter\n");
  printf(" 'stop' when you have finished.\n");

/* Create an adjacency list for the game board. */
/* First a list for the computer's moves */
  createlist(mymove, mymovelist);

/* Then a list for our opponent's moves */
  createlist(umove, umovelist);

  cont = 1;
  do {
      printf("Dead piece? ");
      scanf("%s", an);
      if (strcmp(an, "stop"))
        {
  	 getij(an, &i, &j);
 	 if (p[i][j] == mymove)
 	   {
#ifdef DEBUG 
printf("Just before bfslist.\n");
#endif
 	    N = bfslist(i, j, mymovelist, listpt);
#ifdef DEBUG 
printf("Survived first bfslist.\n");
#endif
 	    for (k=0;k<N;k++)
               {
                node2ij(listpt[k], &i, &j);
                p[i][j] = EMPTY;
                mk++;
               }
 	 }
 	else
 	   if (p[i][j] == umove)
 	     {
#ifdef DEBUG 
printf("Just before second bfslist.\n");
#endif
              N = bfslist(i, j, umovelist, listpt);
              for (k=0;k<N;k++)
                 {
                  node2ij(listpt[k], &i, &j);
                  p[i][j] = EMPTY;
                  uk++;
                 }
       	    }
           showboard();
       }
     else
        cont = 0;
    }
  while (cont);

/* fill in neutral */
  printf("Next, you need to fill in pieces (black and white) in all neutral");
  printf(" territories.\n");
  printf("Enter your and my pieces alternately and");
  printf(" enter 'stop' when finish\n");
  cont = 1;
  N = 0;

  do {
    if ( (N%2) == 0 ) 
     {
      printf("Your piece? ");
      scanf("%s", an);
      if (strcmp(an, "stop"))
        {
 	getij(an, &i, &j);
 	p[i][j] = umove;
 	showboard();
       }
      else
 	cont = 0;
     }
     else
     {
      printf("My piece? ");
      scanf("%s", an);
      if (strcmp(an, "stop"))
        {
 	getij(an, &i, &j);
 	p[i][j] = mymove;
 	showboard();
        }
      else
 	cont = 0;
     }
     N++;
    }
   while (cont);

/* set empty to side they belong to */
   for (i = 0; i < 19; i++)
      for (j = 0; j < 19; j++)
 	if (p[i][j] == EMPTY)
 	   p[i][j] = findcolor(i, j);

/* count total */
  mtot = 0;  utot = 0;
  for (i = 0; i < 19; i++)
     for (j = 0; j < 19; j++)
	if (p[i][j] == mymove)
	  ++mtot;
	else
	   if (p[i][j] == umove)
	     ++utot;

  showboard();
  printf("Your total number of pieces %d\n", utot);
  printf("My total number of pieces %d\n", mtot);

}  /* end endgame */
Пример #10
0
int main()
{
showboard();
return 0;
}
Пример #11
0
void
do_play_ascii(Gameinfo *gameinfo)
{
  int m, num;
  float fnum;
  int passes = 0;  /* two passes and its over */
  int tmp;
  char line[80];
  char *line_ptr = line;
  char *command;
  char *tmpstring;
  int state = 1;

  if (have_time_settings())
    clock_on = 1;

  while (state == 1) {
    state = 0;

    /* No score is estimated yet. */
    current_score_estimate = NO_SCORE;

    /* Allow resignation at interface level (the engine may still be not
     * allowed to resign.
     */
    resignation_allowed = 1;

    printf("\nBeginning ASCII mode game.\n\n");
    gameinfo_print(gameinfo);

    /* Does the computer play first?  If so, make a move. */
    if (gameinfo->computer_player == gameinfo->to_move)
      state = computer_move(gameinfo, &passes);

    /* main ASCII Play loop */
    while (state == 0) {
      /* Display game board. */
      if (opt_showboard)
	ascii_showboard();

#if !READLINE
      /* Print the prompt */
      mprintf("%s(%d): ", color_to_string(gameinfo->to_move), movenum + 1);

      /* Read a line of input. */
      line_ptr = line;
      if (!fgets(line, 80, stdin))
	return;
#else
      snprintf(line, 79, "%s(%d): ",
	       color_to_string(gameinfo->to_move), movenum + 1);
      if (!(line_ptr = readline(line)))
	return;

      add_history(line_ptr);
#endif

      while (state == 0
	     && (command = strtok(line_ptr, ";"), line_ptr = 0, command)) {
	/* Get the command or move. */
	switch (get_command(command)) {
	case RESIGN:
	  state = ascii_endgame(gameinfo, 1);
	  break;

	case END:
	case EXIT:
	case QUIT:
	  return;

	case HELP:
	  show_commands();
	  break;

	case CMD_HELPDEBUG:
	  printf(DEBUG_COMMANDS);
	  break;

	case SHOWBOARD:
	  opt_showboard = !opt_showboard;
	  break;

	case INFO:
	  printf("\n");
	  gameinfo_print(gameinfo);
	  break;

	case SETBOARDSIZE:
	  if (sgf_initialized) {
	    printf("Boardsize cannot be changed after record is started!\n");
	    break;
	  }
	  command += 10;
	  if (sscanf(command, "%d", &num) != 1) {
	    printf("\nInvalid command syntax!\n");
	    break;
	  }
	  if (!check_boardsize(num, stdout))
	    break;
	  /* Init board. */
	  board_size = num;
	  clear_board();
	  /* In case max handicap changes on smaller board. */
	  gameinfo->handicap = place_fixed_handicap(gameinfo->handicap);
	  sgfOverwritePropertyInt(sgftree.root, "SZ", board_size);
	  sgfOverwritePropertyInt(sgftree.root, "HA", gameinfo->handicap);
	  break;

	case SETHANDICAP:
	  if (sgf_initialized) {
	    printf("Handicap cannot be changed after game is started!\n");
	    break;
	  }
	  command += 9;
	  if (sscanf(command, "%d", &num) != 1) {
	    printf("\nInvalid command syntax!\n");
	    break;
	  }
	  if (num < 0 || num > MAX_HANDICAP) {
	    printf("\nInvalid handicap: %d\n", num);
	    break;
	  }
	  /* Init board. */
	  clear_board();
	  /* Place stones on board but don't record sgf 
	   * in case we change more info. */
	  gameinfo->handicap = place_fixed_handicap(num);
	  printf("\nSet handicap to %d\n", gameinfo->handicap);
          gameinfo->to_move = (gameinfo->handicap ? WHITE : BLACK);
	  break;

	case FREEHANDICAP:
	  if (sgf_initialized) {
	    printf("Handicap cannot be changed after game is started!\n");
	    break;
	  }
	  while (*command && *command != ' ')
	    command++;
	  ascii_free_handicap(gameinfo, command);
	  break;

	case SETKOMI:
	  if (sgf_initialized) {
	    printf("Komi cannot be modified after game record is started!\n");
	    break;
	  }
	  command += 5;
	  if (sscanf(command, "%f", &fnum) != 1) {
	    printf("\nInvalid command syntax!\n");
	    break;
	  }
	  komi = fnum;
	  printf("\nSet Komi to %.1f\n", komi);
	  break;

	case SETDEPTH:
	  command += 6;
	  if (sscanf(command, "%d", &num) != 1) {
	    printf("\nInvalid command syntax!\n");
	    break;
	  }
	  mandated_depth = num;
	  printf("\nSet depth to %d\n", mandated_depth);
	  break;

	case SETLEVEL:
	  command += 6;
	  if (sscanf(command, "%d", &num) != 1) {
	    printf("\nInvalid command syntax!\n");
	    break;
	  }
	  set_level(num);
	  printf("\nSet level to %d\n", num);
	  break;

	case DISPLAY:
	  if (!opt_showboard)
	    ascii_showboard();
	  break;

	case FORCE:
	  command += 6; /* skip the force part... */
	  switch (get_command(command)) {
	  case MOVE:
	    state = do_move(gameinfo, command, &passes, 1);
	    break;
	  case PASS:
	    state = do_pass(gameinfo, &passes, 1);
	    break;
	  default:
	    printf("Illegal forced move: %s %d\n", command,
		   get_command(command));
	    break;
	  }
	  break;

	case MOVE:
	  state = do_move(gameinfo, command, &passes, 0);
	  break;

	case PASS:
	  state = do_pass(gameinfo, &passes, 0);
	  break;

	case PLAY:
	  command += 5;
	  if (sscanf(command, "%d", &num) != 1) {
	    printf("\nInvalid command syntax!\n");
	    break;
	  }
	  if (num >= 0)
	    for (m = 0; m < num; m++) {
	      gameinfo->computer_player 
		= OTHER_COLOR(gameinfo->computer_player);
	      state = computer_move(gameinfo, &passes);
	      if (state)
		break;
	      if (passes >= 2)
		break;
	    }
	  else {
	    printf("\nInvalid number of moves specified: %d\n", num);
	    break;
	  }
	  break;

	case PLAYBLACK:
	  if (gameinfo->computer_player == WHITE)
	    gameinfo->computer_player = BLACK;
	  if (gameinfo->computer_player == gameinfo->to_move)
	    state = computer_move(gameinfo, &passes);
	  break;

	case PLAYWHITE:
	  if (gameinfo->computer_player == BLACK)
	    gameinfo->computer_player = WHITE;
	  if (gameinfo->computer_player == gameinfo->to_move)
	    state = computer_move(gameinfo, &passes);
	  break;

	case SWITCH:
	  gameinfo->computer_player = OTHER_COLOR(gameinfo->computer_player);
	  state = computer_move(gameinfo, &passes);
	  break;

	case UNDO:
	case CMD_BACK:
	  if (undo_move(1)) {
            sgftreeAddComment(&sgftree, "undone");
	    sgftreeBack(&sgftree);
	    gameinfo->to_move = OTHER_COLOR(gameinfo->to_move);
	  }
	  else
	    printf("\nCan't undo.\n");
	  break;

	case CMD_FORWARD:
         if (sgftreeForward(&sgftree))
           gameinfo->to_move = gnugo_play_sgfnode(sgftree.lastnode,
						  gameinfo->to_move);
	  else
	    printf("\nEnd of game tree.\n");
	  break;

	case CMD_LAST:
         while (sgftreeForward(&sgftree))
           gameinfo->to_move = gnugo_play_sgfnode(sgftree.lastnode,
						  gameinfo->to_move);
	  break;

	case COMMENT:
	  printf("\nEnter comment. Press ENTER when ready.\n");
	  fgets(line, 80, stdin);
	  sgftreeAddComment(&sgftree, line);
	  break;

	case SCORE:
	  showscore = !showscore;
	  if (!showscore)
	    current_score_estimate = NO_SCORE;
	  break;

	case CMD_DEAD:
	  silent_examine_position(FULL_EXAMINE_DRAGONS);
	  showdead = !showdead;
	  break;

	case CMD_CAPTURE:
	  strtok(command, " ");
	  showcapture(strtok(NULL, " "));
	  break;

	case CMD_DEFEND:
	  strtok(command, " ");
	  showdefense(strtok(NULL, " "));
	  break;

	case CMD_SHOWMOYO:
	  tmp = printmoyo;
	  printmoyo = PRINTMOYO_MOYO;
	  silent_examine_position(EXAMINE_DRAGONS);
	  printmoyo = tmp;
	  break;

	case CMD_SHOWTERRI:
	  tmp = printmoyo;
	  printmoyo = PRINTMOYO_TERRITORY;
	  silent_examine_position(EXAMINE_DRAGONS);
	  printmoyo = tmp;
	  break;

	case CMD_SHOWAREA:
	  tmp = printmoyo;
	  printmoyo = PRINTMOYO_AREA;
	  silent_examine_position(EXAMINE_DRAGONS);
	  printmoyo = tmp;
	  break;

	case CMD_SHOWDRAGONS:
	  silent_examine_position(EXAMINE_DRAGONS);
	  showboard(1);
	  break;

	case CMD_GOTO:
	  strtok(command, " ");
	  ascii_goto(gameinfo, strtok(NULL, " "));
	  break;

	case CMD_SAVE:
	  strtok(command, " ");
	  tmpstring = strtok(NULL, " ");
	  if (tmpstring) {
	    /* discard newline */
	    tmpstring[strlen(tmpstring) - 1] = 0;
	    /* make sure we are saving proper handicap */
	    init_sgf(gameinfo);
	    writesgf(sgftree.root, tmpstring);
	    printf("You may resume the game");
	    printf(" with -l %s --mode ascii\n", tmpstring);
	    printf("or load %s\n", tmpstring);
	  }
	  else
	    printf("Please specify filename\n");
	  break;

	case CMD_LOAD:
	  strtok(command, " ");
	  tmpstring = strtok(NULL, " ");
	  if (tmpstring) {
	    /* discard newline */
	    tmpstring[strlen(tmpstring) - 1] = 0;
	    if (!sgftree_readfile(&sgftree, tmpstring)) {
	      fprintf(stderr, "Cannot open or parse '%s'\n", tmpstring);
	      break;
	    }
            /* to avoid changing handicap etc. */
	    if (gameinfo_play_sgftree(gameinfo, &sgftree, NULL) == EMPTY)
	      fprintf(stderr, "Cannot load '%s'\n", tmpstring);
	    else {
	      sgf_initialized = 1;
	      sgfOverwritePropertyInt(sgftree.root, "HA", gameinfo->handicap);
	    }
	  }
	  else
	    printf("Please specify a filename\n");
	  break;

	case CMD_LISTDRAGONS:
	  silent_examine_position(EXAMINE_DRAGONS);
	  show_dragons();
	  break;

	default:
	  printf("\nInvalid command: %s", command);
	  break;
	}

	if (passes >= 2)
	  state = ascii_endgame(gameinfo, 0);
      }
#if READLINE
      free(line_ptr);
#endif
    }

    sgffile_output(&sgftree);
    passes = 0;
    
    /* Play a different game next time. */
    update_random_seed();

    /* Free the sgf tree and prepare for a new game. */
    sgfFreeNode(sgftree.root);
    sgftree_clear(&sgftree);
    sgftreeCreateHeaderNode(&sgftree, board_size, komi, gameinfo->handicap);
    sgf_initialized = 0;

    gameinfo_clear(gameinfo);
  }
}