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);

}
Ejemplo n.º 2
0
/*=====================================
* main
*===================================*/
int main(void){
reset_data_structs();
clearscr();
welcome_screen();
show_menu();

int check=0;
if(G_current_game.game_mode==pvp){ //pvp mode

    if(G_current_game.player_first==1){  // who first start game,  first move
        cmp.current_player_move=G_players[0];
        cmp.previous_player_move=G_players[1];
    }
    else{
       cmp.current_player_move=G_players[1];
       cmp.previous_player_move=G_players[0];
    }

//    while(1){   // in while add finish_game...
    while( !finish_game_wrapper(pos) ){
            //system("cls");
            clearscr();
            board_print_raw();
                do{
                        //
                    printf("%s your move! (all your moves: %d)\n",cmp.current_player_move.name,cmp.current_player_move.moves);
                    read_move(&pos);
                    check = function_validate_move(pos);
                    }while(check != 0);

            cmp.current_player_move.moves+=1;
            cmp.tmp=cmp.current_player_move;                   //swap current player
            cmp.current_player_move=cmp.previous_player_move;  //
            cmp.previous_player_move=cmp.tmp;                  //
    }//end while(1)
    cmp.tmp=cmp.current_player_move;                   //swap current player
    cmp.current_player_move=cmp.previous_player_move;  //
    cmp.previous_player_move=cmp.tmp;
    board_print_raw();
    printf("%s wins! (In %d moves!)\n",cmp.current_player_move.name,cmp.current_player_move.moves);
}// end pvp mode

if(G_current_game.game_mode==pvc){ //pvc mode

    if(G_current_game.player_first==1){  // who first start game,  first move
        cmp.current_player_move=G_players[0];
        cmp.previous_player_move=G_players[1];// G_players[1] is cpu player
    }
    else{
       cmp.current_player_move=G_players[1];
       cmp.previous_player_move=G_players[0];
    }
    while(1){
            //system("cls");
            clearscr();
            board_print_raw();
            do{
                printf("%s your move! (all your moves: %d)\n",cmp.current_player_move.name,cmp.current_player_move.moves);
                read_move(&pos);
                check = function_validate_move(pos);
                }while(check != 0);

            cmp.current_player_move.moves+=1;
            cmp.tmp=cmp.current_player_move;                   //swap current player
            cmp.current_player_move=cmp.previous_player_move;  //
            cmp.previous_player_move=cmp.tmp;                  //
    }//end while(1)
}// end pvc
return 0;
}
Ejemplo n.º 3
0
void loadLogs(int gameCounter)
{

    FILE *playLog;

    position_t posMove;
    char logName[30] = "TripletsLog-";
    int playNumber;
    char dateExtended[32];
    char playerName[30];
    int dimension;
    int i;
    int moveX;
    char moveY;
    int lineCounter=0;
    int headLinesNumber=6;
    int ch;

    sprintf(logName, "%s%d.txt", logName, gameCounter);

    playLog = fopen(logName, "r");
    if(playLog == NULL)
    {
        printf("\n\tERR: Unable to read Log!");
    }
    else
    {


        do
        {
            ch = fgetc(playLog);
            if( ch== '\n')
            {
                lineCounter++;
            }
        }
        while( ch != EOF );



        fclose(playLog);

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


    }
    playLog = fopen(logName, "r");
    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: %d\n", &dimension);
        fscanf(playLog, "Started on: %s\n", dateExtended);

        for (i=0; i<lineCounter; i++)
        {
            fscanf(playLog, "Player %s ; Play %d ; Move [%d][%c]\n", playerName, &playNumber, &moveX, &moveY);
//         printf("player %s, play number %d, moveX %d, moveY %c\n",playerName, playNumber, moveX, moveY); // was just to test if it's reading right
            posMove.X=moveX;
            posMove.Y=moveY;

            read_move(&posMove);
            board_print_raw();
        }

    }

    fclose(playLog);

}