Use the JavaScript target of the Gleam compiler to build a chess-move service. Work through the opening, test positions and move selection. The original event track is archived.
Set up your project
Choose a starter for your language. Gleam.
Use the examples in each stage to check your implementation locally. CodeCrafters operates its hosted runner separately.
- Starter templates
- Reference solutions
- Language environments
- Download the source snapshot (ZIP)
- Upstream test runner
Contents
Core project
1. Respond to /move request
This challenge is specifically for building your bot using Gleam targeting JavaScript. If you’re interested in building your bot using Gleam targeting Erlang/OTP, you can find that option here.
In this stage, you’ll implement a basic HTTP server that responds to POST requests at the /move endpoint.
The /move endpoint
The server should accept JSON requests in the following format:
{
"fen": "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1",
"turn": "white",
"failed_moves": []
}
Here are what the fields mean:
fen: The current state of the board in Forsyth-Edwards Notation.turn: Whose turn it is to move. Either “white” or “black”.failed_moves: A list of moves that your bot attempted to make for this turn, but were not legal moves.
To pass this stage you can respond with a hardcoded legal chess move in SAN notation, such as “e4”.
Tests
The tester will send a POST request to your server at http://localhost:8000/move with a valid chess position.
Your server should respond with a 200 OK status code and a valid chess move in the response body.
Notes
- The server must listen on port 8000
- The response should be a plain text string containing just the move
2. Respond with an opening
In this stage, you’ll implement a simple opening strategy.
How to respond with an opening
Your bot should:
- Parse the FEN string to understand the current board position
- Check if it’s playing as white or black
- Make a valid opening move based on the position
For example, as white you might want to play 1.e4, and as black you might respond to 1.e4 with 1…e5.
Tests
The tester will send multiple positions from common chess openings. Your bot must respond with legal moves that follow basic chess rules.
Notes
- The move must be legal according to chess rules
- The move must be in SAN notation
- If a move is not legal, it will be added to the
failed_moveslist in subsequent requests
3. Bratko-Kopec test
In this stage, your bot will be tested against some of the Bratko-Kopec test positions.
Bratko-Kopec test
The Bratko-Kopec test is a famous test position set used to evaluate chess engines.
To pass these tests, you’ll need to implement more sophisticated move selection logic. Some approaches you might consider:
- Material counting
- Position evaluation
- Simple search algorithms
- Pattern matching for tactical motifs
Tests
Your bot will be tested against a selection of Bratko-Kopec test positions. It must find valid moves.
Notes
- The positions will be complex tactical positions
- Your bot should aim to find moves that maintain material equality or gain material
- Simple material counting may not be sufficient – consider piece activity and position
4. Win at Chess
In this final stage, your bot will be tested against some of the Win at Chess positions.
Win at Chess
The Win at Chess positions are a set of test positions that are commonly used to evaluate chess engines.
Some techniques you might want to implement to pass these tests:
- Minimax search with alpha-beta pruning
- Position evaluation considering:
- Material
- Piece activity
- King safety
- Pawn structure
- Opening book
- Endgame tablebases
Tests
The tester will test your bot against a selection of Win at Chess positions.
Notes
- Games will be played with standard chess time controls
- Your bot must make moves within the 5 second time limit
5. Submit your bot
In this stage, you’ll finalize your submission for the tournament.
There is an example.ENTRY.md file in the starter code that was provided. You will need to rename the file to ENTRY.md and fill in the required fields. You need to mention your name and email.
If you don’t intend to participate in the tournament, you don’t need to fill the details.
Tests
The tester will test for the presence of the ENTRY.md file in your repository.
Notes
- Please do not remove the
example.ENTRY.mdfile, before you are ready to submit.
Source and licence
Stage material by CodeCrafters. Source snapshot · Original licence.
MIT License Copyright (c) 2022 CodeCrafters Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.