コード例 #1
0
 /**
 * This function shows the menu to pick the size of the board
 *
 * @v info_s
 * @return	none
 * @date	2014-04-18
 * @author	PL Team
 **/
void choose_board()
{
    int control; // to verify if it is not a char!
    int size_board;
    do
    {
        //clearscr();
        printf("\nChoose board size:\n");
        printf("1. Small board (%dx%d)\n", BOARD_SMALL, BOARD_SMALL);
        printf("2. Medium board (%dx%d)\n", BOARD_MEDIUM, BOARD_MEDIUM);
        printf("3. Big board (%dx%d)\n", BOARD_BIG, BOARD_BIG);
        printf("4. Large board (%dx%d)\n\n", BOARD_LARGE, BOARD_LARGE);
        printf("(Choose an option and press enter): ");

        control=scanf("%d",&size_board);
        clean_buffer_keyboard();

    }
    while (size_board<1 || size_board>4 || control ==0);

    switch(size_board)
    {
    case 1:
        board_set_size(BOARD_SMALL);
        G_current_game.board_columns=BOARD_SMALL;
        G_current_game.board_rows=BOARD_SMALL;
        break;
    case 2:
        board_set_size(BOARD_MEDIUM);
        G_current_game.board_columns=BOARD_MEDIUM;
        G_current_game.board_rows=BOARD_MEDIUM;
        break;
    case 3:
        board_set_size(BOARD_BIG);
        G_current_game.board_columns=BOARD_BIG;
        G_current_game.board_rows=BOARD_BIG;
        break;
    case 4:
        board_set_size(BOARD_LARGE);
        G_current_game.board_columns=BOARD_LARGE;
        G_current_game.board_rows=BOARD_LARGE;
        break;
    default:
        clearscr();
        choose_board();
        break;
    }
}
コード例 #2
0
void test_reading_converting_validating()
{
    int counter = 1, check = 0;
    reset_data_structs();
    board_set_size(BOARD_MEDIUM);
    int dimension = board_get_size();
    position_t pos;

    while(counter == 1)
    {
        test_representation_matrix(get_current_game_ptr()->board, dimension);

        do
        {
            read_move(&pos);

            check = function_validate_move(pos);
        }
        while(check != 0);
        //arise the variable "int playNumber".
        //save in log
    }
}
コード例 #3
0
void loadLogs(int gameCounter)
{

    FILE *playLog;

    int playNumber;
    char dateExtended[32];
    char playerName[30];
    int dimension;
    int i;
    int moveX;
    char moveY;
    int lineCounter=0;
    int headLinesNumber=6;
    char logName[255];

    sprintf(logName, "data/logs/TripletsLog-%d.txt", gameCounter);

    lineCounter=get_file_lines(logName);

    lineCounter-=headLinesNumber;

    lineCounter++; // to add the last line which doesn't have /n !!


    playLog = fopen(logName, "rt");
    if(playLog == NULL)
    {
        printf("\n\tERR: Unable to read Log!");
    }
    else
    {
        gameCounter=0;
        dimension=0;
        fscanf(playLog, "--Triplets Log--\n");
        fscanf(playLog, "Game #%d\n", &gameCounter);
        fscanf(playLog, "Matrix Dimension: %dx%d\n", &dimension, &dimension);
        fscanf(playLog, "Started on: %s\n", dateExtended);

        board_set_size(dimension);
        board_set_empty();
        clearscr();
        board_print_raw();
        init_players();

        for (i=0; i<lineCounter; i++)
        {
            printf("\nPress any key to print next move...");
            readchar();
            clearscr();
            fscanf(playLog, "Player %s ; Play %d ; Move [%d][%c]\n", playerName, &playNumber, &moveX, &moveY);


            board_set_content_row_col(moveX, moveY);
            if (i==lineCounter-1)
            {
                finish_gamePL(get_current_game_ptr()->board);
            }
            board_print_raw();
            printf("\nPlayer Name: %s - Play Number: %d - Move: [%d][%c]\n",playerName, playNumber, moveX, moveY); // was just to test if it's reading right

            cmp.tmp=cmp.current_player_move;                   //swap current player
            cmp.current_player_move=cmp.previous_player_move;  //
            cmp.previous_player_move=cmp.tmp;

        }
        printf("\nWINNER: %s\a\n", playerName);
        printf("\nPress any key to go back to menu...");
        readchar();



    }

    fclose(playLog);

}
コード例 #4
0
ファイル: sgf.c プロジェクト: horaceho/michi-c2
void PropValue(void)
// PropValue = "[" ValueType "]"
{
    yyaccept('['); ValueType();

    // Property Value was read : use it to modify the game
    int size = board_size(game->pos);
    if (board_nmoves(game->pos) < nmoves-1 
        && strcmp(prop_name[prop], "B") == 0) {
        if (yytext[0] != 'B')
            do_play(game, BLACK, parse_sgf_coord(yytext, size));
        else
            do_play(game, BLACK, PASS_MOVE);
    }
    else if (board_nmoves(game->pos) < nmoves-1 
        && strcmp(prop_name[prop], "W") == 0) {
        if (yytext[0] != 'W')
            do_play(game, WHITE, parse_sgf_coord(yytext, size));
        else
            do_play(game, WHITE, PASS_MOVE);
    }
    else if (strcmp(prop_name[prop], "AB") == 0) {
        Point pt = parse_sgf_coord(yytext, size);
        slist_push(game->placed_black_stones, pt);
        board_place_stone(game->pos, pt, BLACK);
    }
    else if (strcmp(prop_name[prop], "AW") == 0) {
        Point pt = parse_sgf_coord(yytext, size);
        slist_push(game->placed_white_stones, pt);
        board_place_stone(game->pos, pt, WHITE);
    }
    else if (strcmp(prop_name[prop], "KM") == 0)
        board_set_komi(game->pos, atof(yytext));
    else if (strcmp(prop_name[prop], "SZ") == 0) {
        if (is_game_board_empty(game)) { 
            board_set_size(game->pos, atoi(yytext));
            game_clear_board(game);
        }
        else {
            // Can happen if SZ occurs after AB or AW
            Point    bstones[BOARDSIZE], wstones[BOARDSIZE];
            Position *pos=game->pos;

            slist_clear(bstones); slist_clear(wstones);
            slist_append(bstones, game->placed_black_stones);
            slist_append(wstones, game->placed_white_stones);

            board_set_size(game->pos, atoi(yytext));
            game_clear_board(game);
            
            FORALL_IN_SLIST(bstones, pt) {
                board_set_color_to_play(pos, BLACK);
                play_move(pos, pt);
                slist_push(game->placed_black_stones, pt);
            }
            FORALL_IN_SLIST(wstones, pt) {
                board_set_color_to_play(pos, WHITE);
                play_move(pos, pt);
                slist_push(game->placed_white_stones, pt);
            }
        }