Demo Project 2 Milestone 3 Part 2

Demo Project 2 Milestone 3 Part 2

You cannot submit for this problem because the homework's deadline is due.

Submit terminal.c and main.c here.

Task2: File load & save

Implement load() and save(). Save current game status (board and turn) to a specified file. If not specified, save/load to/from sample.txt.

Task3: Game simulation

Implement the loop!

/**
 * @brief Each iteration of the main loop of the command-line interface, reading and processing commands
 * @param game pointer to current game status
 * @return 0 if you want the main program to continue running; return any other value if you want to exit
 */
int loop(Game *game) {
    printBoardColor(game->board);
    if (curPlayer(game->turn) == Black) {
        printf(MAGENTA "Now it's Black's turn.\n" RESET);
    } else {
        printf(CYAN "Now it's White's turn.\n" RESET);
    }
    printf(">> ");
    
    // TODO: Implement this function.
    return 0;
}

It supports the following functions depend on the input:

  • PRINT: call printBoard()

  • PRINTC: call printBoardColor()

  • PLACE x y: \(x = 1,2,\dots 8,y = a,b,\dots h\)

    • First check if this is a valid move or not (call isValidMove)

    • If the move is valid, you should

    • call updateBoard()

    • game->turn++

    • return judgeEnd(game)

  • LOAD filename: call load()

  • SAVE filename: call save()

  • AUTO: call findFirstNext()

  • DONE: printf("Exit Reversi. See you!\n");return -1;

  • Otherwise: printf("Unknown command. Ignore it.\n");return 0;

Hint: strtok() can be used here.

Lab11 Mon

Not Claimed
Status
Finished
Problems
5
Open Since
2024-08-05 00:00
DDL
2024-08-07 23:59
Extension
0.0 hour(s)