Back

Mushroom Game

NYPC CODE BATTLE · Online Round Practice Problems

Problem Description

In the peaceful forest of Maple World, Yeti and Pink Bean were tending to their mushroom grid together as usual.
One day, they discovered that every mushroom had a digit written on it, so they decided to create a new game using these digits.
They made a game where they compete to own parts of the mushroom grid, alternating turns using following rules.

Game Rules

Become a Yeti or Pink Bean and own as many cells as possible in the mushroom grid by writing a program.

Input/Output Protocol

Your program must read input line by line and follow the protocol of each command. Commands requiring the output are denoted with red color with their time limit specified. If your program fails to output within specified time limit, you will receive Time Limit Exceeded (TLE) verdict and will result forfeiting the game.

CommandInput FormatDescription
READYREADY (FIRST|SECOND)Indicates whether your program takes first or second player. Must output OK within 3 seconds as a response.
INITINIT ...Indicates the game board information. ... consists of 1010 strings, each consisting of 1717 digits.
Each digit is an integer between 11 and 99 inclusive, representing the number on the mushroom at corresponding position. Output is not required
Each digit is drawn independent and identically from digits 11 through 99.
TIMETIME t₁ t₂Indicates it is your program's turn. Also provides remaining time for both players; t1t_1 is yours, t2t_2 is the opponent's (in ms).
Upon receiving this command, the player must output the coordinates of the rectangle selected for this turn in the format r1r_1 c1c_1 r2r_2 c2c_2.
The top-left coordinate of the board is (r,c)=(0,0)(r, c) = (0, 0), and the bottom-right is (9,16)(9, 16).
To pass, output r1=c1=r2=c2=1r_1 = c_1 = r_2 = c_2 = -1. Output values must satisfy:

1r1r29-1 \le r_1 \le r_2 \le 9
1c1c216-1 \le c_1 \le c_2 \le 16
The initial t1,t2t_1, t_2 is given as 1000010\,000ms, regardless of time used for READY command.
OPPOPP x₁ y₁ x₂ y₂ tIndiciates the coordinates r1r_1 c1c_1 r2r_2 c2c_2 selected by the opponent, while taking tt ms during their turn.
If the opponent passed, r1=c1=r2=c2=1r_1 = c_1 = r_2 = c_2 = -1 is given. Output is not required.
FINISHFINISHIndicates the end of the game. The program must terminate properly and immediately, regardless of the current status of the game. Output is not required.

All commands must be processed line by line. When you output, make sure you print a newline character and then flush the buffer. Please refer to the reference document or sample code of your programming language on how to flush the buffer.

Sample Code

The following are sample codes provided for each language:

The sample code selects and outputs the rectangle (r1,c1,r2,c2)(r_1, c_1, r_2, c_2) that is lexicographically smallest among all valid rectangles, i.e. the top-left rectangle. If no selectable rectangle exists, it passes the turn.

Matches with Sample AIs

If the submitted code compiles successfully, it will compete against a total of 7 sample AIs.
The program will play 2 matches against each sample AI, alternating between going first and second. Scores based on wins and losses are as follows:

The strategies of the sample AIs are as follows:

Battle No.DescriptionCode
1 / 2Always "Passes" on its turn.Code
3 / 4Uses the same strategy as provided in the sample code.Code
5 / 6Uses the strategy of the game simulator sample AI, Pink Bean.Code
7 / 8Uses a medium-level defensive strategy.Code
9 / 10Uses a medium-level offensive strategy.Code
11 / 12Uses a high-level defensive strategy.Code
13 / 14Uses a high-level offensive strategy.Code

Note: Sample AI codes were not provided during the actual contest.

Visualization Tools (Sample AI / Two-Player / Log Analysis)

You can play the game against sample AIs, play with two people alternating turns, and use a visualization tool to visualize logs generated by the game simulator and testing tools.

You can download log files for each battle from the Sample AI matches. Use the Log Visualization Tool to examine how the game progressed and refine your strategy.

Testing Tool (GUI)

A testing tool, testing-tool-mushroom, is provided to test the program. You can test your compiled executable or script locally, using python, java, node, or lua in your envinroment.

Testing Tool (Command Line, Python Script)

A CLI testing tool, testing_tool.py (Download), is provided to test the program. The testing tool is a program written in Python 3.12. Regarding the execution of this program, please refer to [Python Setup and Usage].

You can freely modify the CLI testing tool and discuss its execution methods with others. However, you must not share modified tools or log files generated by the tool with anyone outside your team, nor discuss them.

You will receive log files having same format with testing tool, in the submission result dialogue. However, actual grading program is implemented differently from the testing tool, a successful execution in the testing tool does not always guarantee a successful execution in the actual grading.

To use the testing tool, create a setting.ini file in the same location as testing_tool.py. The content should be as follows:

INPUT=<Path to input file>
LOG=<Path to log file>
EXEC1=<Command to run the first player's program>
EXEC2=<Command to run the second player's program>

For example, if the input is input.txt in the same folder, the log is output to log.txt, the command for the first player is ./Main.exe, and the command for the second player is python3 main.py --test, you would write:

INPUT=./input.txt
LOG=./log.txt
EXEC1=./Main.exe
EXEC2=python3 main.py --test

Testing Tool Input Format and Log Interpretation

The input file for the testing tool represents the initial state of the board. The board must consist of 1010 lines, each containing 1717 digits from 11 to 99. Then, run testing_tool.py. After execution, the logs will be output to the specified log file ./log.txt.

The logs output the following information:

You are free to modify testing_tool.py, but you must not share or discuss the modified testing_tool.py or the testing tool's log files with anyone other than your teammates.

In the grading results, you can receive execution logs in the same format as those output by the testing tool. However, since the actual grading program is implemented differently from the testing tool, successful operation in the testing tool does not guarantee normal operation on the grading server.

Example

Example Input (Used in Testing Tool)

52466443835422223
13254826938785712
87598398564241564
72722154162442227
43968227685821641
27727492381231148
56138649164249527
36281415328768234
62682694189422313
62269566965435457

Example Interaction

The string written as INIT ... below represents the board input and is provided as follows:

INIT 52466443835422223 13254826938785712 87598398564241564 72722154162442227 43968227685821641 27727492381231148 56138649164249527 36281415328768234 62682694189422313 62269566965435457
First Player InputFirst Player OutputSecond Player InputSecond Player OutputLog
READY FIRSTREADY SECOND
OKOK
INIT ...INIT ...INIT ...
TIME 10000 10000
(Took 70ms)0 11 0 14
OPP 0 11 0 14 70FIRST 0 11 0 14 70
TIME 10000 9930
(Took 40ms)1 13 5 13
OPP 1 13 5 13 40SECOND 1 13 5 13 40
TIME 9930 9960
(Took 20ms)-1 -1 -1 -1
OPP -1 -1 -1 -1 20FIRST -1 -1 -1 -1 20
TIME 9960 9910
(Took 10ms)-1 -1 -1 -1
OPP -1 -1 -1 -1 10SECOND -1 -1 -1 -1 10
FINISH(Program terminated)FINISH(Program terminated)FINISH
SCOREFIRST 4
SCORESECOND 5