void start(int diff) { STRU_B board[M][N]; char drection = RIGHT; int isn_lose = 1, i, dc; initialise_board(board); creat_sanke(board); while (isn_lose) { dc = 0; system("CLS"); show_board(board); for (i = 0; i < diff; i++) { if (GetKeyState(VK_UP) < 0 && drection != DOWN && dc == 0) drection = UP, dc++; if (GetKeyState(VK_DOWN) < 0 && drection != UP && dc == 0) drection = DOWN, dc++; if (GetKeyState(VK_LEFT) < 0 && drection != RIGHT && dc == 0) drection = LEFT, dc++; if (GetKeyState(VK_RIGHT) < 0 && drection != LEFT && dc == 0) drection = RIGHT, dc++; Sleep(10); } isn_lose = move_snake(board, drection); } system("CLS"); show_board(board); }
int run_game(int nb_lin, int nb_col, unsigned char board[nb_lin][nb_col] ) { unsigned char continue_game = 1; unsigned char nb_boxes = nb_lin * nb_col; unsigned char nb_player = 0; unsigned char winner = 0; do { if ( nb_boxes == 0 ) { winner = 0; continue_game = 0; break; } // Print the board #ifdef __DEBUG__ show_array(nb_lin, nb_col, board); #else clear_screen(); // Clear the screen show_board(nb_lin, nb_col, board); #endif if ( run_a_step(nb_lin, nb_col, board, nb_player) ) { winner = nb_player + 1; continue_game = 0; break; } // Change the player ++nb_player; nb_player %= 2; // Decrement the number of boxes available nb_boxes--; } while ( continue_game ); // Print the board #ifdef __DEBUG__ show_array(nb_lin, nb_col, board); #else clear_screen(); show_board(nb_lin, nb_col, board); #endif return (winner); }
void test_display_empty_board() { Board* board = new_board(3); char expected[] = "1 2 3 4 5 6 7 8 9 "; show_board(board); destroy_board(board); assert(strstr(writer_log, expected)); }
void test_display_played_board() { Board* board = draw_board(); char expected[] = "X O X O X O O X O "; show_board(board); destroy_board(board); assert(strstr(writer_log, expected)); }
static void card_clicked (HandDisplay *handdisp, int card, int *seatp) { if (card == -1) return; PROTECT_BEGIN; board *b = CUR_BOARD; assert (card >= 0 && card < 52); //printf("Clicked: %s for %c.\n", card_string(card), "WNES"[*seatp - 1]); int redraw = 0; if (*seatp != b->current_turn && b->n_played_cards > 0 && b->dealt_cards[b->played_cards[b->n_played_cards - 1]] == *seatp) { /* quick undo */ rewind_card (b); redraw = 1; } if (play_card(b, *seatp, card)) { redraw = 1; } if (redraw) { compute_dd_scores (b, run_dd); show_board(b, REDRAW_HANDS | REDRAW_NAMES | REDRAW_TRICKS | REDRAW_PLAY); } PROTECT_END; }
void show_moves(const state_t *s) { if (s->prev) show_moves(s->prev); usleep(200000); printf("\033[H"); show_board(s); }
void board_set_dealer (seat dealer) { PROTECT_BEGIN; board *b = CUR_BOARD; b->dealer = dealer; show_board(b, REDRAW_CONTRACT | REDRAW_HANDS | REDRAW_NAMES | REDRAW_BIDDING); PROTECT_END; }
void board_set_doubled (int doubled) { PROTECT_BEGIN; board *b = CUR_BOARD; b->doubled = doubled; show_board(b, REDRAW_CONTRACT | REDRAW_BOARD_LIST); PROTECT_END; }
/* tries opening a file in a temporary win structure, and displays errors if unable */ int board_load_popup (window_board_t *win, int append, char *filename) { int i; int ret = 0; window_board_t *win1 = calloc (1, sizeof (window_board_t)); if (board_load (win1, filename)) { if (append) { int n = win->n_boards; for (i = 0; i < win1->n_boards; i++) board_window_append_board (win, win1->boards[i]); if (win->n_boards > n) /* set to first new board */ win->cur = n; } else { MOVE_PTR (win->filename, win1->filename); MOVE_PTR (win->title, win1->title); MOVE_PTR (win->subtitle, win1->subtitle); MOVE_PTR (win->team1, win1->team1); MOVE_PTR (win->team2, win1->team2); for (i = 0; i < win->n_boards; i++) if (win->boards[i]) board_free (win->boards[i]); win->boards = win1->boards; win->n_boards = win1->n_boards; win->n_boards_alloc = win1->n_boards_alloc; win->cur = 0; } card_window_update(win->boards[win->cur]->dealt_cards); show_board(win->boards[win->cur], REDRAW_FULL); recently_used_add (filename); ret = 1; } else { GtkWidget *error = gtk_message_dialog_new (GTK_WINDOW (win->window), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, _("Error loading file '%s': %s"), filename, g_strerror (errno)); gtk_dialog_run (GTK_DIALOG (error)); gtk_widget_destroy (error); } TRY_FREE (win1->filename); TRY_FREE (win1->title); TRY_FREE (win1->subtitle); TRY_FREE (win1->team1); TRY_FREE (win1->team2); free (win1); return ret; }
int main(int c, char **v) { if (c < 2 || (n = atoi(v[1])) <= 3) n = 5; if (n >= 20) n = 20; w = n * 2 + 1; init(); do { show_board(), usleep(60000); } while (run()); return 0; }
int chess_handle(struct chess_t *chess) { int ret; if (chess->net_flag && (chess->who == 1 || !chess->p_flag)) { if (chess->who == 1) srv_send_data(chess); else if (chess->who == 2) cli_send_data(chess); SDL_EventState(SDL_MOUSEBUTTONDOWN, SDL_DISABLE); SDL_EventState(SDL_KEYDOWN, SDL_DISABLE); } ret = press_chess(chess->board, chess->y, chess->x, &chess->flag); switch (ret) { case SUCCESS: show_board(chess); break; case WIN: show_board(chess); if (chess->flag) printf("黑方赢!\n"); else printf("白方赢!\n"); return EXIT; case H: show_board(chess); printf("和棋!\n"); return EXIT; case NONE: default: break; } return TRUE; }
void board_set_declarer (seat declarer) { board *b = CUR_BOARD; if (declarer == b->declarer) return; if (b->n_played_cards > 0) { board_statusbar (_("Cannot change declarer while cards are in play")); PROTECT_BEGIN; show_board(b, REDRAW_CONTRACT); PROTECT_END; return; } PROTECT_BEGIN; b->declarer = declarer; b->current_turn = seat_mod(declarer + 1); invalidate_dd_scores (b); show_board(b, REDRAW_CONTRACT | REDRAW_TRICKS | REDRAW_HANDS | REDRAW_NAMES | REDRAW_BOARD_LIST); PROTECT_END; }
void board_set_trumps (suit trumps) { board *b = CUR_BOARD; if (trumps == b->trumps) return; if (b->n_played_cards > 0) { board_statusbar (_("Cannot change trumps while cards are in play")); PROTECT_BEGIN; show_board(b, REDRAW_CONTRACT); PROTECT_END; return; } PROTECT_BEGIN; board_rewind (b); b->trumps = trumps; invalidate_dd_scores (b); show_board(b, REDRAW_CONTRACT | REDRAW_BOARD_LIST); PROTECT_END; }
int main(void) { // test_is_alowed(); initscr(); noecho(); keypad(stdscr,TRUE); refresh(); int ch;// = getch(); int x=0, y=0; board_t *board = new_board(10); bool turn_a = true; while (ch != 'q'){ switch(ch) { case KEY_LEFT: x--; break; case KEY_RIGHT: x++; break; case KEY_UP: y--; break; case KEY_DOWN: y++; break; case 'x': remove_at(y,x,0,0, board); break; case 't': turn_a = !turn_a ; break; case 's': shoot(y,x,0,0, board, turn_a); break; case 'r': dumb_fill(board->player_b, board->length);break; case 'p': place(y,x,0,0, board); break; default: show_board(0, 0, board, turn_a); } show_board(0, 0, board, turn_a); move(y,x); // printw("Hello World !!!"); ch = getch(); refresh(); } endwin(); return 0; }
void board_set_vuln (int ns, int ew) { PROTECT_BEGIN; board *b = CUR_BOARD; if (ns == b->vuln[0] && ew == b->vuln[1]) PROTECT_RETURN; b->vuln[0] = ns; b->vuln[1] = ew; b->par_score = -1; show_board(b, REDRAW_CONTRACT | REDRAW_NAMES | REDRAW_BIDDING | REDRAW_PAR); PROTECT_END; }
void board_set_level (int level) { board *b = CUR_BOARD; if (level == b->level) return; PROTECT_BEGIN; b->level = level; invalidate_dd_scores (b); calculate_target(b); show_board(b, REDRAW_CONTRACT | REDRAW_BOARD_LIST); PROTECT_END; }
static void board_menu_select (GtkWidget *menuitem, int *n) { PROTECT_BEGIN; if (!gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (menuitem))) PROTECT_RETURN; if (*n == win->cur) PROTECT_RETURN; win->cur = *n; //printf ("jump to %d\n", *n); assert (0 <= *n && *n < win->n_boards); show_board (win->boards[*n], REDRAW_BOARD); PROTECT_END; }
/* gets called for target widget */ static void card_drag_drop (HandDisplay *handdisp, int card, int on_card, int *to_seat) { PROTECT_BEGIN; board *b = CUR_BOARD; printf("Dropped: %s on seat %c.\n", card_string(card), "WNES"[*to_seat - 1]); if (on_card >= 0) printf("Dropped on: %s.\n", card_string(on_card)); if (b->dealt_cards[card] && b->dealt_cards[card] == *to_seat) /* card didn't move */ PROTECT_RETURN; if (b->dealt_cards[card] && !b->cards[card]) { board_statusbar(_("Card is in play and cannot be moved")); PROTECT_RETURN; } seat from_seat = b->dealt_cards[card]; if (on_card >= 0) { /* exchange 2 cards */ if (b->dealt_cards[on_card] && !b->cards[on_card]) { board_statusbar(_("Card is in play and cannot be exchanged")); PROTECT_RETURN; } remove_card(b, *to_seat, on_card); if (from_seat) { remove_card(b, from_seat, card); add_card(b, from_seat, on_card); } add_card(b, *to_seat, card); } else { /* move single card */ if (b->hand_cards[*to_seat-1] == 13) { board_statusbar(_("Hand has already 13 cards")); PROTECT_RETURN; } if (from_seat) remove_card(b, from_seat, card); add_card(b, *to_seat, card); } b->par_score = -1; invalidate_dd_scores (b); board_statusbar(NULL); card_window_update(b->dealt_cards); show_board(b, REDRAW_HANDS | REDRAW_PAR); PROTECT_END; }
void board_window_apply_style (window_board_t *win) { /* check if the svg file is there */ if (win->svg) { struct stat buf; if (stat (win->svg, &buf) == -1) { g_free (win->svg); win->svg = NULL; } } /* otherwise set a default */ if (! win->svg) { int i; for (i = 0; svg_files[i] != NULL; i++) { struct stat buf; if (stat (svg_files[i], &buf) != -1) { win->svg = strdup (svg_files[i]); break; } } } if (! win->svg && win->hand_display_style == HAND_DISPLAY_STYLE_CARDS) /* still nothing... */ win->hand_display_style = HAND_DISPLAY_STYLE_TEXT; int h; for (h = 0; h < 4; h++) { hand_display_set_style(win->handdisp[h], win->hand_display_style); } hand_display_set_style(win->table, win->hand_display_style); window_card_set_style (win->hand_display_style); if (win->hand_display_style == HAND_DISPLAY_STYLE_CARDS && win->svg) { hand_display_set_svg (win->svg, win->card_width); } if (win->n_boards) show_board(CUR_BOARD, REDRAW_HANDS); }
int chess_init(struct chess_t *chess) { int ret; memset(chess, 0, sizeof(struct chess_t)); memset(chess->board, '+', sizeof(chess->board)); chess->x = COL / 2; chess->y = ROW / 2; chess->flag = 1; chess->sdl.width = WIDTH; chess->sdl.height = HEIGHT; chess->sdl.bpp = BPP; ret = sdl_init(&chess->sdl); ERRP(ret != TRUE, goto ERR1, 0); show_board(chess); return TRUE; ERR1: return FALSE; }
main() { int x, y; /* Coordinates of the player's move */ void init(); /* Initialises global variables. */ void get_move(); /* Gets a move from the player. */ void show_board(); /* Displays Othello Board. */ int make_move(); /* Make the move specified. */ init(); /* Initialise Othello. */ /* Main loop - repeats until end_othello takes a non-zero value */ while ( !end_othello ) { /* Read in a move from the player. * * Note that the player's move, translated into coordinates in the * Othello Board, is "returned" via pointers to (int)x and (int)y . */ get_move ( &x, &y ); /* The first thing we check is whether or not the player has quit, * skipped a go or restarted the game. x is set to -1 to indicate * the latter two options. */ if ( !end_othello && x != -1 ) { if ( make_move ( x, y ) ) { /* Switch to next player if the move given was legal. */ if ( player == 0 ) player = 1; else player = 0; /* Re-display the Othello Board. */ show_board(); } else { /* Move was illegal, so try again. */ printf ( ": Illegal Move: Press a Key" ); Bconin ( 2 ); /* Back space over previous message, erase * it and then backspace back again. */ printf ("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"); printf ("\b\b\b\b\b\b\b\b\b\b\b\b\b\b"); printf ( " " ); printf ("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"); printf ("\b\b\b\b\b\b\b\b\b\b\b\b\b\b"); }; }; }; /* Handle error codes. */ printf ( "\n\n%s\nPress a Key\n", errors[end_othello - 1] ); Bconin ( 2 ); /* Free block of memory used by Othello Board if necessary. */ if ( board != NULL ) free ( board ); };
/* set program data from options window */ static void apply_options (GtkWidget *window_options) { /* Card display */ GtkWidget *w = get_widget ("show_played_cards"); win->show_played_cards = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (w)); w = get_widget ("show_as_cards"); int style = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (w)) ? HAND_DISPLAY_STYLE_CARDS : HAND_DISPLAY_STYLE_TEXT; window_card_set_style (style); w = get_widget ("svg_file"); gchar *fname = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (w)); if (fname && strcmp (win->svg, fname)) { /* svg file changed */ if (win->svg) g_free (win->svg); win->svg = fname; } w = get_widget ("spinbutton_card_width"); int card_width = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (w)); board_window_set_style (win, style, card_width); board_window_apply_style (win); /* Hands */ if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (get_widget ("show_dd_all")))) { win->show_dd_scores = seat_all; } else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (get_widget ("show_dd_ns")))) { win->show_dd_scores = north_south; } else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (get_widget ("show_dd_ew")))) { win->show_dd_scores = east_west; } else { win->show_dd_scores = seat_none; } if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (get_widget ("show_hand_all")))) { win->show_hands = seat_all; } else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (get_widget ("show_hand_ns")))) { win->show_hands = north_south; } else { win->show_hands = east_west; } /* Current board */ board *b = CUR_BOARD; w = get_widget ("entry_title"); g_string_printf (b->name, "%s", gtk_entry_get_text (GTK_ENTRY (w))); int i; for (i = 0; i < 4; i++) { w = get_widget (entry_name[i]); g_string_printf (b->hand_name[i], "%s", gtk_entry_get_text (GTK_ENTRY (w))); } /* Board list */ board **new_boards = malloc (win->n_boards_alloc * sizeof (board *)); //int new_cur = 0; i = 0; GtkTreeIter iter; gtk_tree_model_get_iter_first (GTK_TREE_MODEL (board_store), &iter); do { GValue val = { 0 }; gtk_tree_model_get_value (GTK_TREE_MODEL (board_store), &iter, 0, &val); int n = g_value_get_int (&val) - 1; assert (0 <= n && n < win->n_boards); new_boards[i] = win->boards[n]; /*if (n == win->cur) new_cur = i;*/ i++; } while (gtk_tree_model_iter_next (GTK_TREE_MODEL (board_store), &iter)); free (win->boards); win->boards = new_boards; show_board(CUR_BOARD, REDRAW_HANDS | REDRAW_NAMES | REDRAW_CONTRACT | REDRAW_BOARD_LIST); }
int main() { state_t *s = parse_board( #define BIG 0 #if BIG == 0 8, 7, "#######" "# #" "# #" "#. # #" "#. $$ #" "#.$$ #" "#.# @#" "#######" #elif BIG == 1 5, 13, "#############" "# # #" "# $$$$$$$ @#" "#....... #" "#############" #elif BIG == 2 5, 13, "#############" "#... # #" "#.$$$$$$$ @#" "#... #" "#############" #else 11, 19, " ##### " " # # " " # # " " ### #$## " " # # " "### #$## # ######" "# # ## ##### .#" "# $ $ ..#" "##### ### #@## .#" " # #########" " ####### " #endif ); show_board(s); extend_table(); queue_move(s); for (int i = 0; !done; i++) { printf("depth %d\r", i); fflush(stdout); state_t *head = next_level; for (next_level = NULL; head && !done; head = head->qnext) do_move(head); if (!next_level) { puts("no solution?"); return 1; } } printf("press any key to see moves\n"); getchar(), puts("\033[H\033[J"); show_moves(done); #if 0 free(buckets); free(board); free(goals); free(live); while (block_root) { void *tmp = block_root->next; free(block_root); block_root = tmp; } #endif return 0; }
int board_save_dialog (window_board_t *win, int save_as) { GtkWidget *dialog; if (!save_as && win->filename) { int ret = board_save(win, win->filename); if (! ret) { GtkWidget *error = gtk_message_dialog_new (GTK_WINDOW (win->window), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, _("Error saving file '%s': %s"), win->filename, g_strerror (errno)); gtk_dialog_run (GTK_DIALOG (error)); gtk_widget_destroy (error); } return ret; } dialog = gtk_file_chooser_dialog_new (_("Save File"), GTK_WINDOW (win->window), GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, NULL); gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), TRUE); add_filters (GTK_FILE_CHOOSER (dialog)); if (!win->filename) gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), _("hand.lin")); else gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (dialog), win->filename); retry_save: if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) { char *filename; filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog)); int ret = board_save (win, filename); if (ret) { if (win->filename) free (win->filename); win->filename = filename; show_board (CUR_BOARD, REDRAW_TITLE); recently_used_add (filename); } else { GtkWidget *error = gtk_message_dialog_new (GTK_WINDOW (win->window), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, _("Error saving file '%s': %s"), filename, g_strerror (errno)); g_free (filename); gtk_dialog_run (GTK_DIALOG (error)); gtk_widget_destroy (error); goto retry_save; } } gtk_widget_destroy (dialog); return 1; }
int do_game(){ int c, x, y, r, player, turn; char code[6], prev_code[6]; // ------------------------------------------------------------ // start! show_board(); player = first_player; turn = 0; prev_code[0] = 0; while(prompt(player, code, prev_code, !check_possibility(player, turn), turn)){ move m; int e, x_offset, y_offset; if(code[0] == 0) return TERMINATE_WRONG; // ctrl+d // retry if invalid code while(!check_code(code)){ if(interactive(player)){ prompt(player, code, prev_code, FALSE, turn); } else { printf("Invalid move on serial port.\n"); return player; } if(code[0] == 0) return TERMINATE_WRONG; } if(code[0] == 0) return TERMINATE_WRONG; // ctrl+d if(prev_code[0] == 0) strcpy(p1move1, code); if(strcmp(prev_code, "0000") == 0 && strcmp(code, "0000") == 0){ printf("Both pass!\n"); show_hint = FALSE; if(! (check_possibility(player, turn) || check_possibility(next_player(player), turn-1))){ return TERMINATE_NORMAL; } return TERMINATE_NORMAL; // is this OK? } strcpy(prev_code, code); // pass if(strcmp(code, "0000") == 0){ if(turn >= 2){ player = next_player(player); turn++; continue; } else { printf("First move must not be a pass.\n"); return player; } } m = decode_code(code); c = m.piece; r = m.rotate; x_offset = m.x-2; y_offset = m.y-2; if((e = check_move(player, turn, m)) != 0){ show_error(e); return player; } // OK, now place the move for(y=0; y<5; y++){ for(x=0; x<5; x++){ int b; b = pieces[c][0][rotate[r][y][x]]; if (b==1) board[y_offset+y][x_offset+x] = player; } } available[player-1][c] = 0; if(remaining_size(player)==0){ printf("Player %d won the game, since the player has no more pieces.\n", player); return TERMINATE_NORMAL; } // show the board & next player show_board(); player = next_player(player); turn++; } printf("Player %d timed out.\n", player); return player; }
int web_sector(void) { int sid = 0; board_t parent = { .id = 0 }; db_res_t *res = NULL; const char *sname = web_get_param("s"); if (*sname) { res = db_query("SELECT id, descr" " FROM board_sectors WHERE name = %s", sname); if (!res || db_res_rows(res) < 1) { db_clear(res); return BBS_EINVAL; } } else { const char *pname = web_get_param("board"); if (*pname) get_board(pname, &parent); else get_board_by_bid(strtol(web_get_param("bid"), NULL, 10), &parent); if (!parent.id || !(parent.flag & BOARD_FLAG_DIR) || !has_read_perm(&parent)) return BBS_ENOBRD; } xml_header(NULL); printf("<bbsboa link='%sdoc' ", get_post_list_type_string()); if (*sname) { char path[HOMELEN]; sprintf(path, "%s/info/egroup%d/icon.jpg", BBSHOME, (int) strtol(sname, NULL, 16)); if (dashf(path)) printf(" icon='%s'", path); const char *utf8_sector = db_get_value(res, 0, 1); if (web_request_type(UTF8)) { printf(" title='%s'>", utf8_sector); } else { GBK_BUFFER(sector, BOARD_SECTOR_NAME_CCHARS); convert_u2g(utf8_sector, gbk_sector); printf(" title='%s'>", gbk_sector); } sid = db_get_integer(res, 0, 0); db_clear(res); } else { if (web_request_type(UTF8)) { printf(" dir= '1' title='%s'>", parent.descr); } else { GBK_BUFFER(descr, BOARD_DESCR_CCHARS); convert_u2g(parent.descr, gbk_descr); printf(" dir= '1' title='%s'>", gbk_descr); } } if (sid) res = db_query(BOARD_SELECT_QUERY_BASE "WHERE b.sector = %d", sid); else res = db_query(BOARD_SELECT_QUERY_BASE "WHERE b.parent = %d", parent.id); if (res && db_res_rows(res) > 0) show_board(res); db_clear(res); print_session(); printf("</bbsboa>"); return 0; } int bbsclear_main(void) { if (!session_id()) return BBS_ELGNREQ; board_t board; if (!get_board(web_get_param("board"), &board) || !has_read_perm(&board)) return BBS_ENOBRD; session_set_board(board.id); const char *start = web_get_param("start"); brc_init(currentuser.userid, board.name); brc_clear_all(); brc_sync(currentuser.userid); char buf[STRLEN]; snprintf(buf, sizeof(buf), "doc?board=%s&start=%s", board.name, start); http_header(); refreshto(0, buf); printf("</head></html>"); return 0; } int bbsnot_main(void) { board_t board; if (!get_board(web_get_param("board"), &board) || !has_read_perm(&board)) return BBS_ENOBRD; if (board.flag & BOARD_FLAG_DIR) return BBS_EINVAL; session_set_board(board.id); char fname[HOMELEN]; snprintf(fname, sizeof(fname), "vote/%s/notes", board.name); mmap_t m; m.oflag = O_RDONLY; if (mmap_open(fname, &m) < 0) return BBS_ENOFILE; xml_header(NULL); printf("<bbsnot brd='%s'>", board.name); xml_fputs2((char *) m.ptr, m.size); mmap_close(&m); print_session(); printf("</bbsnot>"); return 0; }
/* * Comando per gestire il gioco degli scacchi */ void do_chess( CHAR_DATA *ch, char *argument ) { CHESSBOARD_DATA *board; char arg[MIL]; if ( !ch ) { send_log( NULL, LOG_BUG, "do_chess: ch è NULL" ); return; } if ( IS_MOB(ch) ) { send_to_char( ch, "I mob non possono giocare a scacchi.\r\n" ); return; } board = get_chessboard( ch ); if ( !VALID_STR(argument) || is_name(argument, "sintassi aiuto syntax help ?") ) { char *cmd; cmd = translate_command( ch, "chess" ); ch_printf( ch, "&YSintassi gioco&w: %s inizio|smetto|partecipo|forfeit\r\n", cmd ); ch_printf( ch, "&YSintassi info&w: %s pezzi\r\n", cmd ); ch_printf( ch, "&YSintassi mosse&w: %s muovo <sorgente> <destinazione> [comandi opzionali]\r\n", cmd ); ch_printf( ch, "&YSintassi extra&w: %s arrocco|promuovo\r\n", cmd ); if ( !VALID_STR(argument) && board ) { send_to_char( ch, "\r\n" ); show_status( ch, board ); send_to_char( ch, "\r\n" ); show_board( ch, board ); } return; } argument = one_argument( argument, arg ); if ( is_name_prefix(arg, "inizio inizia comincio comincia cominciare start") ) { CHESSBOARD_DATA *newboard; if ( board ) { send_to_char( ch, "Sto già partecipando ad una partita di scacchi.\r\n" ); return; } CREATE( newboard, CHESSBOARD_DATA, 1 ); init_board( newboard ); newboard->player1 = ch; newboard->turn = ch; LINK( newboard, first_chessboard, last_chessboard, next, prev ); top_chessboard++; send_to_char( ch, "Inizio una nuova partita di scacchi.\r\n" ); return; } if ( is_name_prefix(arg, "partecipa partecipo join") ) { CHESSBOARD_DATA *vboard = NULL; CHAR_DATA *vch; char arg2[MIL]; if ( board ) { send_to_char( ch, "Sto già partecipando ad una partita di scacchi.\r\n" ); return; } argument = one_argument( argument, arg2 ); if ( !VALID_STR(arg2) ) { send_to_char( ch, "Con chi devo partecipare ad una partita di scacchi?\r\n" ); return; } vch = get_player_room( ch, arg2, TRUE ); if ( !vch ) { ch_printf( ch, "Non vedo nessun %s nella stanza.\r\n", arg2 ); return; } vboard = get_chessboard( vch ); if ( !vboard ) { send_to_char( ch, "Non sta giocando a scacchi.\r\n" ); return; } if ( vboard->player2 ) { send_to_char( ch, "Questa scacchiera ha già due giocatori.\r\n" ); return; } vboard->player2 = ch; vboard->turn = vboard->player2; send_to_char( ch, "Mi unisco alla partita, è il mio turno.\r\n" ); ch_printf( vboard->player1, "%s si unisce alla tua partita.\r\n", ch->name ); return; } if ( is_name_prefix(arg, "pezzi pieces") ) { int x; /* contatore dei colori */ int y; /* contatore dei pezzi */ for ( x = 0; x < COLOR_NONE; x++ ) { if ( x == COLOR_BLACK ) send_to_char( ch, "\r\n\r\nPezzi neri:\r\n" ); else send_to_char( ch, "Pezzi bianchi:\r\n" ); for ( y = PIECE_PAWN; y < PIECE_NONE; y++ ) ch_printf( ch, "%-7s", table_pieces[y].name ); send_to_char( ch, "\r\n" ); for ( y = PIECE_PAWN; y < PIECE_NONE; y++ ) send_to_char( ch, (x == COLOR_WHITE) ? table_pieces[y].wgraph1 : table_pieces[y].bgraph1 ); send_to_char( ch, "\r\n" ); for ( y = PIECE_PAWN; y < PIECE_NONE; y++ ) send_to_char( ch, (x == COLOR_WHITE) ? table_pieces[y].wgraph2 : table_pieces[y].bgraph2 ); } send_to_char( ch, "\r\n" ); return; } if ( !board ) { send_to_char( ch, "Non ho iniziato o non sto partecipando a nessuna partita di scacchi.\r\n" ); return; } if ( is_name_prefix(arg, "smetto fermo stop") ) { free_chessboard( board ); return; } if ( is_name_prefix(arg, "forfeit") ) { send_to_char( ch, "Dò forfeit così perdendo.\r\n" ); free_chessboard( board ); return; } if ( !board->player1 || !board->player2 ) { send_to_char( ch, "C'è solo un giocatore.\r\n" ); return; } if ( board->moves < 0 ) { send_to_char( ch, "Il gioco non è ancora iniziato.\r\n" ); return; } if ( is_name_prefix(arg, "promuovo promuovi promote") ) { int piece = board->piece[board->lastx][board->lasty]; char extra[MIL]; if ( !((piece == PIECE_PAWN && board->player1 == ch) || (piece == PIECE_PAWN && board->player2 == ch)) ) { send_to_char( ch, "Non posso promuovere questo pezzo.\r\n" ); return; } if ( (piece == PIECE_PAWN && board->lastx != 0) || (piece == PIECE_PAWN && board->lastx != 7) ) { send_to_char( ch, "Puoi promuovere solamente i pedoni che hanno raggiunto l'altro lato della scacchiera.\r\n" ); return; } if ( !VALID_STR(argument) ) { send_to_char( ch, "Vorrei promuovere il pedone in che cosa?\r\n" ); return; } if ( is_name_prefix(argument, "regina queen" ) ) piece = PIECE_QUEEN; else if ( is_name_prefix(argument, "alfiere bishop") ) piece = PIECE_BISHOP; else if ( is_name_prefix(argument, "cavallo knight") ) piece = PIECE_KNIGHT; else if ( is_name_prefix(argument, "torre rook" ) ) piece = PIECE_ROOK; else { ch_printf( ch, "Non posso promuoverlo a %s.\r\n", argument ); return; } board->piece[board->lastx][board->lasty] = piece; sprintf( extra, "%s (%c%d)", table_pieces[piece].name, board->lastx+'a', board->lasty+1 ); board_move_messages( ch, MOVE_PROMOTE, extra ); return; } if ( board->turn != ch ) { send_to_char( ch, "Non è il mio turno.\r\n" ); return; } if ( is_name_prefix(arg, "arrocco") ) { int myx; int rooky; int kdy; int rdy; bool fRookShort; if ( king_in_check(board, PIECE_KING, (board->player1 == ch) ? COLOR_BLACK : COLOR_WHITE) > 0 ) { send_to_char( ch, "Non posso eseguire un arrocco mentre sono sotto scacco.\r\n" ); return; } if ( (board->player1 == ch && HAS_BIT(board->flags1, CHESSFLAG_MOVEDKING)) || (board->player2 == ch && HAS_BIT(board->flags2, CHESSFLAG_MOVEDKING)) ) { send_to_char( ch, "Non posso effettuare un arrocco quando ho già mosso il mio re.\r\n" ); return; } myx = (board->player1 == ch) ? 7 : 0; if ( !VALID_STR(argument) ) { ch_printf( ch, "Utilizzo: %s arrocco corto|lungo\r\n", translate_command(ch, "chess") ); return; } if ( is_name_prefix(argument, "corto short") ) fRookShort = TRUE; else if ( is_name_prefix(argument, "lungo long") ) fRookShort = FALSE; else { send_command( ch, "chess arrocco", CO ); return; } if ( (board->player1 == ch && HAS_BIT(board->flags1, fRookShort ? CHESSFLAG_MOVEDKROOK : CHESSFLAG_MOVEDQROOK)) || (board->player2 == ch && HAS_BIT(board->flags2, fRookShort ? CHESSFLAG_MOVEDKROOK : CHESSFLAG_MOVEDQROOK)) ) { ch_printf( ch, "Non posso effettuare l'arrocco %s perchè ho già mosso la torre prima.\r\n", fRookShort ? "corto" : "lungo" ); return; } rooky = fRookShort ? 7 : 0; if ( ( fRookShort && (board->piece[myx][6] != PIECE_NONE || board->piece[myx][5] != PIECE_NONE)) || (!fRookShort && (board->piece[myx][1] != PIECE_NONE || board->piece[myx][2] != PIECE_NONE || board->piece[myx][3] != PIECE_NONE)) ) { send_to_char( ch, "L'arrocco è bloccato dalla presenza di pezzi tra il re e la torre.\r\n" ); return; } /* castling succeeded */ if ( fRookShort ) { kdy = 6; rdy = 5; } else { kdy = 2; rdy = 3; } /* (FF) (TT) (RR) (bb) ricordo che una qualsiasi delle caselle, in cui avveniva l'arrocco * non dovevano essere sotto scacco, mi sa che qui non è così, o forse ricordo sbagliato */ /* check for 'move across check' rule */ board->piece[myx][rdy] = board->piece[myx][4]; board->piece[myx][4] = PIECE_NONE; if ( king_in_check(board, board->piece[myx][rdy], board->color[myx][rdy]) > 0 ) { send_to_char( ch, "Il mio re si troverebbe sotto scacco dopo l'arrocco.\r\n" ); board->piece[myx][4] = board->piece[myx][rdy]; board->piece[myx][rdy] = PIECE_NONE; return; } board->piece[myx][kdy] = board->piece[myx][rdy]; board->piece[myx][rdy] = board->piece[myx][rooky]; board->piece[myx][rooky] = PIECE_NONE; /* check for 'check' after castled */ if ( king_in_check(board, board->piece[myx][kdy], board->color[myx][kdy]) > 0 ) { send_to_char( ch, "Il mio re si troverebbe sotto scacco dopo l'arrocco.\r\n" ); board->piece[myx][4] = board->piece[myx][kdy]; board->piece[myx][kdy] = PIECE_NONE; board->piece[myx][rooky] = board->piece[myx][rdy]; board->piece[myx][rdy] = PIECE_NONE; return; } /* Basta indicare che è stato mosso il re per evitare un altro arrocco */ if ( board->player1 == ch ) SET_BIT( board->flags1, CHESSFLAG_MOVEDKING ); else SET_BIT( board->flags2, CHESSFLAG_MOVEDKING ); board_move_stuff( board ); board_move_messages( ch, MOVE_CASTLE, rooky == 7 ? "corto" : "lungo" ); } if ( is_name_prefix(arg, "muovo move") ) { char coord1[MIL]; char coord2[MIL]; char extra[MIL]; int x, y, dx, dy; int ret; if ( !VALID_STR(argument) ) { ch_printf( ch, "Utilizzo: %s muovo <sorgente> <destinazione>\r\n", translate_command(ch, "chess") ); return; } argument = one_argument( argument, coord1 ); argument = one_argument( argument, coord2 ); if ( !VALID_STR(coord1) || !VALID_STR(coord2) ) { ch_printf( ch, "Utilizzo: %s muovo <sorgente> <destinazione>\r\n", translate_command(ch, "chess") ); return; } get_coord( coord1, &x, &y ); get_coord( coord2, &dx, &dy ); if ( x < 0 || x >= 8 || dx < 0 || dx >= 8 || y < 0 || y >= 8 || dy < 0 || dy >= 8 ) { send_to_char( ch, "Mossa non valida, utilizza a-h e 1-8 (esempio: a4 b4).\r\n" ); return; } extra[0] = '\0'; ret = is_valid_move( ch, board, x, y, dx, dy ); if ( ret == MOVE_OK || ret == MOVE_TAKEN ) { int piece; int color; int destpiece; int destcolor; piece = board->piece[x][y]; color = board->color[x][y]; destpiece = board->piece[dx][dy]; destcolor = board->color[dx][dy]; board->piece[dx][dy] = piece; board->color[dx][dy] = color; board->piece[x][y] = PIECE_NONE; board->color[x][y] = COLOR_NONE; if ( king_in_check(board, PIECE_KING, board->color[dx][dy]) > 0 ) { board->piece[dx][dy] = destpiece; board->color[dx][dy] = destcolor; board->piece[x][y] = piece; board->color[x][y] = color; ret = MOVE_INCHECK; } else { if ( destpiece == PIECE_NONE ) sprintf( extra, "%c%d (%s) alle coordinate %c%d", x+'a', y+1, table_pieces[piece].name, y+'a', dy+1 ); else sprintf( extra, "%c%d (%s) alle coordinate %c%d (%s)", x+'a', y+1, table_pieces[piece].name, y+'a', dy+1, table_pieces[destpiece].name ); board_move_stuff( board ); board->lastx = dx; board->lasty = dy; /* Imposta le flag per evitare gli arrocchi */ if ( piece == PIECE_ROOK ) { if ( color == COLOR_WHITE ) { if ( y == 0 && x == 0 ) SET_BIT( board->flags1, CHESSFLAG_MOVEDKROOK ); else if ( y == 0 && x == 7 ) SET_BIT( board->flags1, CHESSFLAG_MOVEDQROOK ); } else { if ( y == 7 && x == 0 ) SET_BIT( board->flags2, CHESSFLAG_MOVEDKROOK ); else if ( y == 7 && x == 7 ) SET_BIT( board->flags2, CHESSFLAG_MOVEDQROOK ); } } else if ( piece == PIECE_KING ) { if ( color == COLOR_WHITE ) SET_BIT( board->flags1, CHESSFLAG_MOVEDKING ); else SET_BIT( board->flags2, CHESSFLAG_MOVEDKING ); } } board_move_messages( ch, ret, extra ); } /* Così qui gestisce i comandi opzionali, come il promote */ if ( VALID_STR(argument) ) { do_chess( ch, argument ); return; } return; } send_command( ch, "chess aiuto", CO ); }
int start_game(){ char board[ BOARD_HEIGHT ][ BOARD_WIDTH ]; char mtx_brick[4][4]; int score = 0; int level = 0; int lines = 0; int tmp_lines = 0; char x, y; char brick; char next_brick; int vel = 10; timespec req; req.tv_sec = 0; req.tv_nsec = vel * PULSE; srand( time( 0 ) ); memset( board, 0, BOARD_HEIGHT * BOARD_WIDTH ); next_brick = rand() % 7 + 1; init_screen(); WINDOW* wboard = create_wboard(); WINDOW* wpreview = create_wpreview(); WINDOW* wscore = create_wscore(); show_title(); show_score( wscore, score, level, lines ); wait_start( wboard ); bool play = true; while( play ){ brick = next_brick; next_brick = rand() % 7 + 1; show_preview( wpreview, next_brick ); show_score( wscore, score, level, lines ); show_board( wboard, board ); x = ( ( BOARD_WIDTH / 3 ) % 2 == 0 ) ? BOARD_WIDTH / 3 : BOARD_WIDTH / 3 + 1; y = - 3; get_brick( brick, mtx_brick ); bool move = true; int delay = 0; while( move ){ switch( getch() ){ case KEY_UP: move_brick( wboard, board, mtx_brick, brick, &y, &x, ROTATE_R ); break; case 'z': move_brick( wboard, board, mtx_brick, brick, &y, &x, ROTATE_R ); break; case 'x': move_brick( wboard, board, mtx_brick, brick, &y, &x, ROTATE_L ); break; case KEY_DOWN: move_brick( wboard, board, mtx_brick, brick, &y, &x, DOWN ); break; case KEY_LEFT: move_brick( wboard, board, mtx_brick, brick, &y, &x, LEFT ); break; case KEY_RIGHT: move_brick( wboard, board, mtx_brick, brick, &y, &x, RIGHT ); break; case ' ': move_brick( wboard, board, mtx_brick, brick, &y, &x, BOTTOM ); break; case 27: play = move = false; break; case 'q': play = move = false; break; default: break; } // switch( getch() ) if( ++delay == DELAY_DOWN ){ move_brick( wboard, board, mtx_brick, brick, &y, &x, DOWN ); } if( delay == DELAY_BOTTOM ){ delay = 0; if( check_brick(mtx_brick, board, y + 1, x ) ){ move = false; if( y < 0 ) play = false; } } nanosleep( &req, 0 ); } // while( move ) set_board( board, mtx_brick, brick, y, x ); tmp_lines += check_lines( board, &score, &lines ); if( tmp_lines >= CH_LEV ){ req.tv_nsec = vel * PULSE; score += 1; level++; if( vel > 1 ) vel--; tmp_lines = tmp_lines % CH_LEV; } } // while( quit ) delwin( wboard ); delwin( wpreview ); delwin( wscore ); restore_screen(); return 0; }
int main (int argc, char *argv[]) { #ifdef ENABLE_NLS bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); #endif gtk_set_locale (); gtk_init (&argc, &argv); init_solve(); srand(time(NULL)); win = malloc(sizeof(window_board_t)); char *xml_file = NULL; int i; for (i = 0; i < sizeof (xml_files); i++) { struct stat buf; if (stat (xml_files[i], &buf) != -1) { xml_file = xml_files[i]; g_debug ("Using interface file %s\n", xml_file); break; } } if (! xml_file) { fprintf (stderr, _("Could not find interface definition file: %s\n"), "tenace.ui"); exit (1); } GError *error = NULL; win->builder = gtk_builder_new (); if (! gtk_builder_add_from_file (win->builder, xml_file, &error)) { g_warning (_("Could not load builder file: %s"), error->message); g_error_free (error); exit (1); } gtk_builder_connect_signals (win->builder, NULL); board_window_init (win); read_config (win); board_window_apply_style (win); if (argc > 1) { char *fname = argv[1]; if (! g_path_is_absolute (argv[1])) { char *cwd = g_get_current_dir (); fname = g_build_filename (cwd, argv[1], NULL); g_free (cwd); } if (! board_load (win, fname)) { if (errno == EMEDIUMTYPE) { perror (fname); puts (_("Hint: tenace can only read files in .lin format")); } else perror (fname); exit (1); } recently_used_add (fname); if (! g_path_is_absolute (argv[1])) g_free (fname); } else { board_window_append_board (win, NULL); deal_random (win->boards[0]); /* show a random deal on startup */ } show_board(win->boards[0], REDRAW_FULL); card_window_update(win->boards[0]->dealt_cards); gtk_main (); write_config (win); return 0; }
int main() { int color = 1; // 現在の手番の色。黒が1で白が2 int tesuu = 0; // 手数 hama[0] = 0; hama[1] = 0; bool pray_pass = false; srand( (unsigned)time( NULL ) ); char str[256]; char playstr[256]; // stdoutをバッファリングしないように。GTPで通信に失敗するので。 setbuf(stdout, NULL); setbuf(stderr, NULL); // stderrに書くとGoGuiに表示される。 //loop: // 盤面初期化 {int i,x,y; for (i=0;i<BOARD_MAX;i++) board[i] = 3; for (y=0;y<B_SIZE;y++) for (x=0;x<B_SIZE;x++) board[get_z(x,y)] = 0; } // static int score_sum; // static int loop_count; for (;;) { if ( fgets(str, 256, stdin)==NULL ) break; // 標準入力から読む //fprintf(stderr, playstr); //strcpy(playstr,str); if ( strstr(str,"boardsize") ) { send_gtp("= \n\n"); // "boardsize 19" 19路盤 } else if ( strstr(str,"clear_board") ) { for (int i=0;i<BOARD_MAX;i++) board[i] = 3; for (int y=0;y<B_SIZE;y++) for (int x=0;x<B_SIZE;x++) board[get_z(x,y)] = 0; tesuu = 0; color = 1; hama[0] = 0; hama[1] = 0; pray_pass = false; node_num = 0; send_gtp("= \n\n"); } else if ( strstr(str,"name") ) send_gtp("= ayasam\n\n"); else if ( strstr(str,"version") ) send_gtp("= 0.0.1\n\n"); else if ( strstr(str,"genmove w") ) { if (pray_pass) { send_gtp("= pass\n\n"); } else { color = 2; clock_t bt = clock(); all_playouts = 0; // playout回数を初期化 #if 0 // 0 でUCT探索 int z = select_best_move(color); // 原始モンテカルロ #else int z = select_best_uct(color); // UCT #endif int err = move(z,color); // 打ってみる if ( err != 0 ) { show_board(); fprintf( stderr, "Err!\n"); char mvstr[8]; change_z_str(mvstr, z); fprintf(stderr, "%s\n", mvstr); exit(0); } kifu[tesuu] = z; tesuu++; print_board(); char gtstr[12] = "= "; char mvstr[8]; change_z_str(mvstr, z); strcat(gtstr, mvstr); strcat(gtstr, "\n\n"); send_gtp(gtstr); fprintf(stderr,"play_xy = %s,手数=%d,色=%d,all_playouts=%d\n",mvstr,tesuu,color,all_playouts); double t = (double)(clock()+1 - bt) / CLOCKS_PER_SEC; fprintf(stderr,"%.1f 秒, %.0f playout/秒\n",t,all_playouts/t); } } else if ( strstr(str,"genmove b") ) { if (pray_pass) { send_gtp("= pass\n\n"); } else { color = 1; clock_t bt = clock(); all_playouts = 0; // playout回数を初期化 #if 0 // 0 でUCT探索 int z = select_best_move(color); // 原始モンテカルロ #else int z = select_best_uct(color); // UCT #endif int err = move(z,color); // 打ってみる if ( err != 0 ) { show_board(); fprintf( stderr, "Err!\n"); char mvstr[8]; change_z_str(mvstr, z); fprintf(stderr, "%s\n", mvstr); exit(0); } kifu[tesuu] = z; tesuu++; print_board(); char gtstr[12] = "= "; char mvstr[8]; change_z_str(mvstr, z); strcat(gtstr, mvstr); strcat(gtstr, "\n\n"); send_gtp(gtstr); fprintf(stderr,"play_xy = %s,手数=%d,色=%d,all_playouts=%d\n",mvstr,tesuu,color,all_playouts); double t = (double)(clock()+1 - bt) / CLOCKS_PER_SEC; fprintf(stderr,"%.1f 秒, %.0f playout/秒\n",t,all_playouts/t); } } // 相手の手を受信 "play W D17" のように来る else if ( strstr(str,"play") ) { char *tp; tp = strtok(str, " "); tp = strtok(NULL, " "); if (strstr(tp, "W") || strstr(tp, "w")) { color = 2; } else { color = 1; } if (tp) { tp = strtok(NULL, " "); int z = change_str_z(tp); int err = play_move(z,color); // 打ってみる if ( (err != 0) && (err != 3) ) { show_board(); fprintf( stderr, "Err!\n"); char mvstr[8]; change_z_str(mvstr, z); fprintf(stderr, "%s\n", mvstr); strcat(playstr,"Error!:"); if (err == 1) { strcat(playstr,"1"); } else if (err == 2) { strcat(playstr,"2"); } else if (err == 3) { strcat(playstr,"3"); } else if (err == 4) { strcat(playstr,"4"); } strcat(playstr," "); strcat(playstr,tp); strcat(playstr," -> "); strcat(playstr,mvstr); strcat(playstr,"\n"); exit(0); } kifu[tesuu] = z; tesuu++; if (z == 0) { pray_pass = true; } else { pray_pass = false; } print_board(); } send_gtp("= \n\n"); } else if ( strstr(str, "showboard")) { show_board(); send_gtp("= \n\n"); } else if ( strstr(str, "quit")) { send_gtp("= \n\n"); break; } else if ( strstr(str,"test")) { for (int n=0;;n++) { for (int i=0;i<BOARD_MAX;i++) board[i] = 3; for (int y=0;y<B_SIZE;y++) for (int x=0;x<B_SIZE;x++) board[get_z(x,y)] = 0; tesuu = 0; color = 1; hama[0] = 0; hama[1] = 0; pray_pass = false; while (true) { if (pray_pass) { break; } else { clock_t bt = clock(); all_playouts = 0; // playout回数を初期化 #if 0 // 0 でUCT探索 int z = select_best_move(color); // 原始モンテカルロ #else int z = select_best_uct(color); // UCT #endif int err = move(z,color); // 打ってみる if ( err != 0 ) { show_board(); fprintf( stderr, "Err!\n"); char mvstr[8]; change_z_str(mvstr, z); fprintf(stderr, "%s\n", mvstr); exit(0); } //kifu[tesuu] = z; tesuu++; //print_board(); //char gtstr[12] = "= "; char mvstr[8]; change_z_str(mvstr, z); //strcat(gtstr, mvstr); //strcat(gtstr, "\n\n"); //send_gtp(gtstr); fprintf(stderr,"play_xy = %s,手数=%d,色=%d,all_playouts=%d\n",mvstr,tesuu,color,all_playouts); double t = (double)(clock()+1 - bt) / CLOCKS_PER_SEC; fprintf(stderr,"%.1f 秒, %.0f playout/秒\n",t,all_playouts/t); color = flip_color(color); if (z == 0) { pray_pass = true; } } } print_board(); printf("%d end\n", n); } } else { send_gtp("= \n\n"); // それ以外のコマンドにはOKを返す } show_board(); } /* // 自己対戦のテスト用 int score = count_score(1); score_sum += score; loop_count++; FILE *fp = fopen("out.txt","a+"); fprintf(fp,"Last Score=%d,%d,%d,tesuu=%d\n",score,score_sum,loop_count,tesuu); fclose(fp); printf("Last Score=%d,%d,%d,tesuu=%d\n",score,score_sum,loop_count,tesuu); color = 1; tesuu = 0; goto loop; */ // SGFで棋譜を吐き出す /* printf("(;GM[1]SZ[%d]\r\n",B_SIZE); for (int i=0; i<tesuu; i++) { int z = kifu[i]; int y = z / WIDTH; int x = z - y*WIDTH; if ( z == 0 ) x = y = 20; char *sStone[2] = { "B", "W" }; printf(";%s[%c%c]",sStone[i&1], x+'a'-1, y+'a'-1 ); if ( ((i+1)%10)==0 ) printf("\r\n"); } printf("\r\n)\r\n"); */ return 0; }