U
U
U
U
U
U
U
U
U
U
U
U
U
U
U
U
U
U
U
U
U
U
U
U
U
U
U
W
B
U
U
U
U
U
U
B
W
U
U
U
U
U
U
U
U
U
U
U
U
U
U
U
U
U
U
U
U
U
U
U
U
U
U
U

Play reversi with your own .c function:

int makeMove(const char board[][26], int n, char turn, int *row, int *col);

What is ReverC?

ReverC is a lightweight browser platform where you use your own C function to play Reversi against humans, candidate code, historical algorithms, or AI.

Code Requirements?

To upload your own code to compete, you should know:

  • ReverC has built-in "lab8part2.h" and "liblab8part2.h", so codes with these two headers decleared won't cause error.
  • Ensure there's a MakeMove() function with correct format.
  • There is a time limit of 3 seconds for .c algorithm, exceeding it will end the game.

Enjoy the game! See here for more details

Instructions (FAQs)
rvc_example.c

/**
 * This sample code can be directly submitted to reverc.org to compete.
 *
 * The makeMove() signature was defined in lab8part2.h by the APS105 teaching team
 * at the University of Toronto (UofT) in 2022. This sample code and reverc.org are
 * provided by Jue Wang. The code is protected under the MIT License.
 *
 * APS105 students at UofT are responsible for academic integrity defined by UofT 
 * and should take responsibility when referring to this code.
 */

#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>

/**
 * For APS105 students, you can safely keep these two including statement since ReverC stores them.
 */
#include "lab8part2.h"
#include "liblab8part2.h"

/**
 * You can also choose to include rvc.h, which is a library provided by ReverC (not teaching team).
 * It helps you quickly test your prototype, though they may not be the most runtime-efficient.
 */
#include "rvc.h"      

// By using rvc.h, your code will be linked with another file called "rvc_tools.c", 
// where four ready-made functions are defined for you to use, they are:

/*
static bool rvc_in_bounds(int n, int row, int col);     // Whether the position is in bound
static bool rvc_occupied(const char board[][26], int row, int col); // Whether the position is occupied
static bool rvc_position_legal_direction(const char board[][26], int n, int row, 
    int col, char color, int deltaRow, int deltaCol);   // Whether the position is legal in one direction
bool rvc_position_legal(const char board[][26], int n, int row, int col, char color);   // Whether the position is legal
*/

// Together, you can use those provided tool functions to write a random placed Reversi AI.
int makeMove(const char board[][26], int n, char turn, int *row, int *col) {
    int availableRows[26 * 26];
    int availableCols[26 * 26];
    int count = 0;

    // Traverse the board, find all possible moves
    for (int r = 0; r < n; r++) {
        for (int c = 0; c < n; c++) {
            if (rvc_position_legal(board, n, r, c, turn)) {
                availableRows[count] = r;
                availableCols[count] = c;
                count++;
            }
        }
    }

    // In case no available moves (ReverC won't let it happen)
    if (count == 0) {
        return -1;
    }

    // Randomly choose one position to place
    int idx = rand() % count;
    *row = availableRows[idx];
    *col = availableCols[idx];
    return 0;
}

/**
 * Only a valid makeMove() function is required in ReverC. It's not mandatory to have main() function.
 */