← Questions

Validate chess moves from the starting position

0
OpenAICodingLast asked Oct 2026

Start from the standard chess position with White to move. You receive a list of attempted moves such as e2e4 (from-square, to-square). For each one, decide whether it is legal and, if it is, apply it and pass the turn; an illegal move changes nothing.

Implement normal movement for every piece: sliding pieces can't jump, knights can, pawns move one square (two from their starting rank through an empty square) and capture diagonally. A move may not capture a king or leave your own king in check. Castling, en passant and promotion are out of scope. At the end, print the board.

Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding