Challenge Overview
Important Links
- Submission-Review You can find your submissions artifacts here. Artifacts will contain output.txt's for both example test cases and provisional test cases with stdout/stderr and individual test case scores.
- Other Details For other details like Processing Server Specifications, Submission Queue, Example Test Cases Execution.
Overview
You are playing a game on an N*N grid, where each cell is either empty, a wall or a token from one of C colours. Tokens and of colour surround token if
- lies on a straight line (vertical, horizontal or diagonal) between and ; and
- There are no walls, empty cells or other tokens of colour between and .
A token of colour can be placed on an empty cell if together with another token of colour they surround one or more tokens of a different colour. When such a token is placed, all the surrounded tokens change their colour to . Your task is to place tokens onto a given starting grid in order to reach a given target grid. Your score will be the number of tokens placed plus , where is the number of tokens that match in colour to the target grid.
Here is an example solution for seed=1. Empty cells are in white and walls are in gray. All the other coloured cells are tokens. Mismatches are shown in a lighter colour.
Input and Output
Your code will receive as input the following values, each on a separate line:
- N, the grid size.
- C, the number of colours.
- N*N lines representing the starting grid in row-major order. Each cell will be described with an integer: wall (-1), empty (0) or a token colour between 1 and C, inclusive.
- N*N lines representing the target grid in row-major order. This has the same format as the starting grid.
You must output a sequence of moves, formatted as follows:
- M, number of moves.
- M lines representing the moves, each formatted as "r c col" (without the quotes), indicating that you want to place a token of colour col at location (r, c). All locations are 0-based.
Scoring
The raw score is the total points obtained from your sequence of moves. If your return was invalid, then your raw score on this test case will be -1. Possible reasons include:
- Using fewer than 0 moves.
- Using more moves than the number of empty locations in the starting grid.
- Trying to place a token on a non-empty cell or outside the grid.
- Making a move that does not change the colour of any tokens.
- Using an invalid move format.
- Exceeding the time limit.
If your raw score for a test case is negative then your normalized score for that test case is 0. Otherwise, your normalized score for each test case is YOUR/MAX, where YOUR is your raw score and MAX is the largest positive raw score currently obtained on this test case (considering only the last submission from each competitor). Finally, the sum of all your test scores is normalized to 100.
Test Case Generation
Please look at the generate() method in the visualizer's source code for the exact details about test case generation. Each test case is generated as follows:
- The grid size N is chosen between 8 and 30, inclusive.
- The number of colours C is chosen between 2 and 6, inclusive.
- The wall probability P is chosen between 0 and 0.2, inclusive.
- Generate the starting grid. Start with an empty N*N grid. For each colour , randomly place a 2 x 2 subgrid of tokens in a cross pattern with colours and . With probability P change each empty cell to a wall.
- Generate the target grid. From the starting grid run 100 random playouts until there are no more legal moves. Choose the final grid that contains the least number of empty cells. If there are multiple such grids then choose the one that uses the most number of colours.
- All values are chosen uniformly at random.
Notes
- The time limit is 10 seconds per test case (this includes only the time spent in your code). The memory limit is 1024 megabytes.
- The compilation time limit is 30 seconds.
- There are 10 example test cases and 100 full submission (provisional) test cases. There will be 2000 test cases in the final testing.
- The match is rated.
Languages Supported
C#, Java, C++ and Python
Submission Format
Your submission must be a single ZIP file not larger than 500 MB, with your source code only.
Please Note: Please zip only the file. Do not put it inside a folder before zipping, you should directly zip the file.
Make sure you name your Source Code file as Reversi*.<appropriate extension>*
Sample Submissions
Here are example solutions for different languages, modified to be executed with the visualizer. You may modify and submit these example solutions:
- Java Source Code - Reversi.java.zip
- C++ Source Code - Reversi.cpp.zip
- Python3.6 Source Code - Reversi.py.zip
- C# Source Code - Reversi.cs.zip
Tools
An offline tester is available below. You can use it to test/debug your solution locally. You can also check its source code for an exact implementation of test case generation and score calculation. You can also find links to useful information and sample solutions in several languages.
Downloads
- Visualizer Source - tester.zip
- Visualizer Binary - tester.jar.zip
Offline Tester / Visualizer
Your solution should interact with the tester/visualizer by reading data from standard input and writing data to standard output.
To run the tester with your solution, you should run:
java -jar tester.jar -exec "<command>" -seed <seed>
Here, <command> is the command to execute your program, and <seed> is seed for test case generation.
If your compiled solution is an executable file, the command will be the full path to it, for example, "C:\TopCoder\Reversi.exe" or "~/topcoder/Reversi".
In case your compiled solution is to be run with the help of an interpreter, for example, if your program is in Java, the command will be something like "java -cp C:\TopCoder Reversi".
Additionally you can use the following options:
- -seed <seed> Sets the seed used for test case generation, default is seed 1.
- -debug. Print debug information.
- -novis. Turns off visualisation.
- -pause. Starts the visualizer in paused mode. See more information below.
- -delay <delay> Sets the delay (in milliseconds) between visualizing consecutive simulation steps, default is 1000.
- -noanimate. Only show the final state, no intermediate steps.
- -manual. Play the game manually. Press keys numbered 1 to C to select the desired colour. Use the left mouse click to place a token and the right mouse click to undo moves.
- -showDots. Shows the target colour of each cell with a circle. Note that the circles will not be visible for cells with the correct colour.
- -N <N> Sets a custom grid size.
- -C <C> Sets a custom number of colours.
- -P <P> Sets a custom wall probability.
The visualizer works in two modes. In regular mode, steps are visualized one after another with a delay specified with the -delay parameter. In paused mode, the next move will be visualized only when you press any key. The space key can be used to switch between regular and paused modes. The default starting mode is regular. You can use the -pause parameter to start in paused mode.
Marathon local testers have many useful options, including running a range of seeds with a single command, running more than one seed at time (multiple threads), controlling time limit, saving input/output/error and loading solution from a file. The usage of these options are described here.