This is the archived CodeCup 2016 website.
Click here to go to the new CodeCup website.
CodeCup 2016 - An online programming competition  

CodeCup 2016 - An online programming competition

6561

The game 6561 is a cooperative two-player game. Players A and B take turns placing pieces on the board and then ‘tilting’ the board so all pieces slide towards a side of the board.

The score of the board is the sum of the values of all pieces on the board. The score of the game is the maximum score of the board during the entire game. Both players obtain the same score if they both play correctly (see Technical Information). Note that the maximum score may not be the final score on the board.

The game is played on a board with dimensions 4x4 that consists of 16 square fields. The game is played with pieces of different colors (red, blue and gray), and the different colors are used by both players.

The game 6561 is a variation of the single-player game 2048.

Rhythm

In the game 6561 the players alternate in making a move. There are four types of move: ‘place a red piece’, ‘place a blue piece’, ‘place a gray piece’ and ‘slide the board’. The 4 moves deliver a rhythm of 10 turns as shown in the following table:

turnplayertype of move
1Aplace a blue piece with value 1
2Bplace a red piece with value 1
3Aplace a gray piece with value 1
4Bslide the board
5Aslide the board
6Bplace a blue piece with value 1
7Aplace a red piece with value 1
8Bplace a gray piece with value 1
9Aslide the board
10Bslide the board

This rhythm keeps on repeating during the entire game until 1000 moves have been made. (So 100 times the full rhythm). The game ends earlier when no valid move can be made.

Game Play

A player can place a piece on any empty field. If there are no empty squares when the player must place a piece, the game ends.

When a player must slide the board, the player chooses a direction: up, down, left or right. A move to slide the board must change the board in order to be a valid move. If there is no valid slide move when a slide move is required, the game ends.

When sliding the board, the game looks at the pieces starting from the edge towards which you are sliding. When moving up or down the game looks only at consecutive pieces in the same column. When moving left or right the game looks only at consecutive pieces in the same row. Note that consecutive includes consecutive pieces that have one or more empty fields between them.

When two consecutive pieces have the same value but a different color they will both disappear.

When two consecutive pieces have both the same value and color they will be replaced by a single new piece that has the same color and as value 3 times the value on the original pieces.

A piece that is newly created in this manner will not be removed or changed within the same move.

At the end of a sliding move all pieces will be touching on the side that they have been slid to.

BeforeMoveAfter

In this example the board is slid up.

In the first column the two consecutive red 3-pieces are replaced with a single red 9-piece. The blue piece is not involved since we start looking from the edge towards which we are sliding.

In the second column the gray 1-piece and first blue 1-piece are consecutive pieces of similar value but different color so they will be removed. The same goes for the last two pieces.

In the third column there are two consecutive blue 9-pieces. They are replaced with a single blue 27-piece since the pieces have the same color and value.

In the last column the two gray 1-pieces are replaced with a single gray 3-piece. Even though there are now two consecutive gray 3-pieces they will not be replaced since a new piece is not changed within the same move. Only when the same board is slid up again the two 3-pieces in the last column will be replaced.

The requirement that the board must be changed during a slide move basically means that the game ends when the board is empty after the first slide, or when the board is completely full without any consecutive same value pieces. In any other situation you can make a slide move where the board changes.

The board

As shown in the example above, the board consists of 16 square fields arranged in a 4x4 grid. Every field is labeled with two coordinates. Those are shown in the lower left corner of each field in the example.

Your program

You should write a computer program that receives from the judging software the last move that your opponent has made. Your program then calculates its move, and writes that move back to the judging software.

You will communicate with the judging software using stdin (standard input) and stdout (standard output).

Your program should always start reading information from the judging software.

The judging software will start by sending you ‘A’ to indicate you are player A, or ‘B’ to indicate you are player B.

If your program reads ‘A’, you are the first player and the judging software will wait for your first move. If your program reads ‘B’, you are player 2 and should start by reading the first move of your opponent.

The judging software guarantees that any move it sends to you, is a valid move.

After the game starts you should alternate between reading the move from your opponent and writing back your move. Don’t forget the rhythm of the moves!

A move from your program is indicated as follows:

Type of moveMove
PlacementrkA number rk indicating row r and column k where a new piece (always a 1-piece, in the color prescribed by the rhythm) is placed.
SlideUA string indicating towards which edge the board slides. They are the first letters of (UP, DOWN, LEFT and RIGHT)
D
L
R

Technical Information

If you make an illegal move, your program crashes, or your program uses up the total allotted time, your program will score 0 points. The judging software will take over from you and will play random moves in a deterministic way. This gives your opponent still a chance to score points.

If the judging software sends you the command ‘Quit’, your program should terminate gracefully. If you do not terminate properly, your program will be killed.

When you write to the judging software you should end each string with a newline. You should also flush your output immediately.

Time Limit

The total time limit for your program is 60 seconds. This means that you cannot use more than 60 seconds of calculation time for all your moves together. The time that the judging software uses, and the time that your opponent uses, is not added to your time.

Tournament

All programs that work well with our judging software will be admitted to the competition.

The judging software historically talks about the ‘white player’ for the first player and the ‘black player’ for the second player. Because of the colors in this game we labelled the first player ‘Player A’ and the second player ‘Player B’.

About CodeCup

CodeCup is a computer programming competition that is organized the Nederlandse Informatica Olympiade (NIO), the Dutch Olympiad in Informatics. The competition is hosted online and can be followed live on the internet. Programmers from all over the world can enter the CodeCup competition. CodeCup staff and NIO staff do not participate.