/* * Load boards file. */ void load_boards( void ) { FILE *board_fp = NULL; BOARD_DATA *board = NULL; char boardfile[256]; sprintf( boardfile, "%s%s", BOARD_DIR, BOARD_FILE ); if( ( board_fp = fopen( boardfile, "r" ) ) == NULL ) return; while( ( board = read_board( boardfile, board_fp ) ) != NULL ) { char notefile[256]; FILE *note_fp = NULL; LINK( board, first_board, last_board, next, prev ); sprintf( notefile, "%s%s", BOARD_DIR, board->note_file ); if( ( note_fp = fopen( notefile, "r" ) ) != NULL ) { NOTE_DATA *pnote = NULL; while( ( pnote = read_note( notefile, note_fp ) ) != NULL ) { LINK( pnote, board->first_note, board->last_note, next, prev ); board->num_posts++; } } } }
main() { int i,j; /* counters */ int a[DIMENSION*DIMENSION+1]; boardtype board; /* Seduko board structure */ boardtype temp; read_board(&board); print_board(&board); copy_board(&board,&temp); for (fast=TRUE; fast>=FALSE; fast--) for (smart=TRUE; smart>=FALSE; smart--) { printf("----------------------------------\n"); steps = 0; copy_board(&temp,&board); finished = FALSE; backtrack(a,0,&board); /*print_board(&board);*/ printf("It took %d steps to find this solution ",steps); printf("for fast=%d smart=%d\n",fast,smart); } }
int main(int argc, const char **argv) { if (argc != 2) return usage(); read_board(argv[1]); solve_board(); print_board(); return 0; }
char *read_phyboard(int pass) { static char board[BD_SIZE]; if (!pass) return board; if (read_board(board, pass) == -1) fprintf(stderr, "warning: unable to read board\n"); printf("board is read\n"); return board; }
/*---------------------------------------------------------------------- * main entry point *----------------------------------------------------------------------*/ int main(int argc, char *argv[]) { progname = argv[0]; read_board(); /* read the board file */ dict = Dict_open(NULL); /* open the dictionary */ play.dirn = ACROSS; board = horiz_board; value = horiz_value; xboard = vert_board; xvalue = vert_value; find_best(); play.dirn = DOWN; board = vert_board; value = vert_value; xboard = horiz_board; xvalue = horiz_value; find_best(); if (nb_count == 0) { printf("Cannot play\n"); }else{ int i; nb_sort(); for (i=0; i<nb_count; i++) { NBTYPE *p = nb_sorted[i]; if (p->dirn==ACROSS) { printf("[%d,%d]a", p->row, p->col); }else{ printf("[%d,%d]d", p->col, p->row); } printf(" %s %d\n", p->word, p->score); } } Dict_close(dict); return 0; }
int do_chess() { // 8 rows of 8 chars + newlines for each row char board[9 * 8]; printf("Welcome to chessmaster 0x8000, enter your board:\n"); if (read_board(board) != EXIT_SUCCESS) { printf("Invalid board\n"); return EXIT_SUCCESS; } find_move(board); printf("Muahhaha, I move to %c%c%c%c\n", game_state.games.chess.move[0], game_state.games.chess.move[1], game_state.games.chess.move[2], game_state.games.chess.move[3]); return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { FILE *in; struct board b; int ret; if (argc > 2) { fprintf(stderr, "ERROR: too many arguments\n"); return 1; } if (argc == 2) { in = fopen(argv[1], "r"); if (in == NULL) { fprintf(stderr, "ERROR: could not open \"%s\"\n", argv[1]); return 2; } } else { in = stdin; } /* Initialize data structures. */ init_board(&b); /* Read and solve board. */ read_board(in, &b); ret = solve_board(&b, MIN_NUM, MIN_NUM); /* Close input and return. */ fclose(in); if (! ret) fprintf(stderr, "ERROR: board could not be solved\n"); return (ret?0:3); }
/** * Process command-line options: * -v = verbose output * -f init = use init as file to describe start state * -n size = set the board size (always square with wraparound) * -g step = set the number of generations */ void read_options(int argc, char** argv, problem_t* problem) { /* Default options */ problem->verbose = 0; problem->nboard = 100; problem->g = 100; problem->init = NULL; for (int i = 1; i < argc; ++i) { if (*argv[i] == '-' && i+1 < argc) { switch (argv[i][1]) { case 'n': problem->nboard = atoi(argv[++i]); break; case 'g': problem->g = atoi(argv[++i]); break; case 'f': problem->init = argv[++i]; break; case 'v': problem->verbose = 1; break; default: fprintf(stderr, "Unknown flag: %s", argv[i]); print_usage_quit(argv[0]); } } else { print_usage_quit(argv[0]); } } if (problem->init == NULL) { fprintf(stderr, "Initialization file not specified\n"); print_usage_quit(argv[0]); } read_board(problem); }
int main() { logfile.open("ai++.log", std::ios_base::out | std::ios_base::trunc); if (!logfile.is_open()) { std::cerr << "ai: cannot open log. terminating." << std::endl; return 1; } RawBoard board; uint8_t state; AI ai; while (true) { read_board(std::cin, board); read_state(std::cin, state); AnalyzeResult result = ai.actuate(board); if (std::get<1>(result)) { std::cout << (uint8_t)std::get<0>(result) << std::flush; } else { std::cerr << "ai: no further options. terminating." << std::endl; return 0; } } }
static void construct_study( army_type army[] ) { char str[10]; unsigned int i, row, col, pc_num, colour; army_type * owner; piece_type * pc; close_open_book( army->sh ); // Automatically create the 2 kings, // prompting user for coords for( i = 0; i < 2; i++ ) { owner = &army[i]; do { printf( "Coordinates of %s king: ", owner->name ); scanf( "%s", str ); } while( !coord_ext_to_int( str, &row, &col ) || !create_piece( owner, row, col, 5 ) ); if( row != 7*(1-i) || col != 4 ) { printf( "Castling disallowed for %s\n", owner->name ); owner->castle_lost[0] = owner->castle_lost[1] = 0; } } /* Allow creation of extra pieces */ for( ; ; ) { print_board( army ); for( i = 0; i < NUM_PIECE_DEFS; i++ ) { printf( "%d: %s ", i, army->sh->pc_def[i].name ); } printf( "\nCreate which piece (-1 to exit): " ); scanf( "%d", &pc_num ); if( pc_num >= NUM_PIECE_DEFS ) break; do { printf( "Colour (white=%d, black=%d): ", O_WHITE, O_BLACK ); scanf( "%d", &colour ); } while( colour >= 2 ); owner = &army[colour]; if( owner->num_pieces >= MAX_ARMY_SIZE ) { printf( "%s already has %d pieces\n", owner->name, owner->num_pieces ); continue; } do { printf( "Coordinates: " ); scanf( "%s", str ); } while( !coord_ext_to_int( str, &row, &col ) || !create_piece( owner, row, col, pc_num ) ); } // Check rooks for castling for( colour = 0; colour <= 1; colour++ ) { // Army num owner = &army[colour]; for( i = 0; i <= 1; i++ ) { // Castle type if( owner->castle_lost[i] == 0 ) continue; pc = read_board(owner,7*(1-colour),7*(1-i)); if( pc == NULL || pc->owner != owner || pc->def->token != ROOK_TOKEN ) { printf( "%sside castling disallowed for %s\n", (i == 0) ? "King" : "Queen", owner->name ); owner->castle_lost[i] = 0; } } } } // construct_study()