Project 02 · Rust · In progress

mi8ess

mi → mik8 → hatesess → chessmik hates chess

A chess engine written in Rust.

Board representation and FEN parsing are in. Move generation comes next, then search. A project for learning Rust.

Roadmap ↓

Source goes public with move generation.

Position

rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq e3 0 1

To move
black
Search
—
Depth
—
Nodes
—

Reads the board. Can’t move on it yet.

Roadmap

Eight stages, from board representation to a playable engine. Two are done; move generation is next.

  1. 01Board
  2. 02FEN
  3. 03Move gen
  4. 04Perft
  5. 05Search
  6. 06Eval
  7. 07UCI
  8. 08Play here

Next up · 03

Move generation

Pseudo-legal moves first: every move each piece could make if checks didn’t exist. Then throw out the ones that leave the king in check. Perft comes straight after, to prove the counts are right.

  • Pawn pushes, captures, promotions
  • Knight and king jumps
  • Sliding pieces: bishop, rook, queen
  • Castling and en passant
  • Legality: does the king survive?

Planned work, not started

Internals

A FEN string is a whole chess position in one line. Six fields, split on spaces. from_fen reads them in order and refuses anything it doesn’t understand.

Anatomy of a FEN

1rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR2b3KQkq4e35061

  1. 1Placement8 ranks, top to bottom
  2. 2Side to movew or b
  3. 3Castlingwhich rooks can still castle
  4. 4En passanttarget square, or -
  5. 5Halfmoveclock for the 50-move rule
  6. 6Fullmovestarts at 1

Digits are runs of empty squares. Upper case is white, lower case is black.

board.rsrust
// handle the castling rights
let castling = parts.next().ok_or("Missing castling info in FEN")?;

if castling != "-" {
    for castling_char in castling.chars() {
        match castling_char {
            'K' => board.can_castle_king_white = true,
            'k' => board.can_castle_king_black = true,
            'Q' => board.can_castle_queen_white = true,
            'q' => board.can_castle_queen_black = true,
            _ => return Err("Invalid castling char in FEN".to_string()),
        };
    }
}

src/board.rs · lines 153–166, indentation trimmed

10 of its 20 error messages

  • Err "FEN is empty"
  • Err "Not 8 ranks in FEN"
  • Err "More than 8 files in FEN"
  • Err "Incomplete rank in FEN"
  • Err "Invalid notation used in FEN"
  • Err "Invalid color to move in FEN"
  • Err "Invalid castling char in FEN"
  • Err "Invalid file in en_passant in FEN"
  • Err "Invalid rank in en_passant in FEN"
  • Err "Extra input found in en_passant in FEN"

The name

mimik8h·ate·sessch·ess

The name reads mi-eight-ess, short for “mik hates chess”.

Jump to

↑ ↓ move↵ openesc close

You found the 8.

mi8ess can read this board but cannot generate moves yet, so both sides are moved by hand.

Play e4 to start

Open mi8ess

Click anywhere to close