- You complete both matches having more points than your opponent.
- Your opponent loses.
This puzzle can be solved using the following concepts. Practice using these concepts and improve your skills.
Chess, the Game of Kings, is a classical board game that has been played for centuries, and has also been a cornerstone of artificial intelligence development for decades. You can easily learn all about how this game is played by doing an online search or reading this Wikipedia article.
This Codingame implementation makes use of the Chess960 rules, also known as Fischer Random Chess, where the initial starting position is randomly shuffled among 960 possibilities. This is done to promote variety as well as to prevent the hardcoding of initial moves using an opening book.
If any of the following happens, the current game will result into a draw:
- A player is unable to make a legal move while their king is not being under check, a Stalemate occurs.
- The same position occurring for the third time, also known as a Threefold Repetition.
- There is insufficient material for either player to deliver a checkmate. This includes:
- King vs king
- King+knight vs king
- King+bishop vs king
- King+bishop vs king+bishop if both bishops are on the same square color.
- No piece capture and no pawn has moved for 50 moves, using the Fifty-Move rule.
- After maxMoves moves are played.
- If one side offers a draw and the other side accepts it, also known as a draw by agreement.
- You attempt to make an illegal move.
- You do not provide an output in the alloted time.
- The current game state is encoded as a single line using the Forsyth–Edwards Notation, hereby referred to as FEN.
- Game moves are internally encoded as done in the Universal Chess Interface protocol, hereby referred to as UCI.
- Game moves are displayed in the viewer using the Algebraic Notation.
- Piece characters are using the english language, therefore P for pawns, N for knights, B for bishops, R for rooks, Q for queens and K for kings.
- You can access and copy/paste the FEN of the current position and PGN (Portable Game Notation) of both games by opening the settings panel ().
- You can force the initial position to be the classical one by specifying
seed=0in the game options.
The source code of this game is available on GitHub.
Notes and examples
Draw offers only last for one turn. If the opponent does not accept it, it is revoked.
Because of Chess960, the castling field of the FEN string does not make use of
The presence of an en-passant square in the FEN does not mean that a legal en-passant capture is possible.
As mentioned above, specifying the move to make is done through the UCI protocol. It is simply the source square immediately followed by the destination square. For example, the classical king's pawn opening 1. e4 would be encoded as
Piece promotion is specified by appending the piece character at the end. For example,
Castling is done as a king moving to its own rook. In a classical starting position, a king-side castling would be
You can make use of the moves input to validate your own move generation and the move you make as output.
Line 1: constantsCount, the number of constants communicated by the game referee.
Next constantsCount lines:
Currently defined constants are:
- crazyHouse: Boolean integer with
0as false and 1as true, indicating whether crazyhouse rules are enabled. Always 0for this arena.
- maxMoves: Integer indicating the maximum number of moves per player per game. After this, a draw will be forced as a game result. Currently set at
125. fen: The FEN representation of the current game. Strongly recommended. moves: The list of legal moves. lastmove: The last move made by the opponent. draw: Whether the opponent has made a draw offer. game: The game number currently being played. score: The current score for each player.
The values sent are in accordance with the configuration sent on the first turn, in the same order they were given.
- fen: A line containing
6fields board color castling enPassant halfMoveClock fullMove separated with spaces, representing a FEN string.
- moves: A line containing an integer movesCount, followed by movesCount lines having one move per line, a string with a UCI move.
- lastmove: A line with a string containing the UCI move played by the opponent last turn, or
noneif it is the first turn of the game.
- draw: A line containing a boolean integer,
1if a draw was offered last turn by the opponent, 0otherwise.
- game: A line containing an integer representing the current game number, starting at
1for the first game.
- score: A line containing
2integers separated by a space, the score of the current player followed by the score of the opponent. The score is given in half-points, so ½= 1.
- A comment can be added to be displayed in the viewer by adding a space after the move and writing its content.
- You can offer a draw to your opponent by adding
=right after the move, without a space.
- You can accept a draw offer by outputting
drawinstead of a move. Note that this is only legal if a draw offer was made the previous turn! Make sure to check the input first.
- You can resign the current game by outputting
resigninstead of a move. This will proceed to the next game or end the match if no more is to be played.
- You can play a random move by outputting
randominstead of a move. This is admittedly only useful for stub code generation.
Response time for the first turn ≤
A higher resolution is required to access the IDE