## Making chess

Doug’s commented on my “Practicing chess” post, saying that he’d like to write a program to show where the “dangerous” moves are — the ones where your piece could be captured — started me thinking about the whole process of writing computer programs to implement games.

The thing about programming computers is that you always find yourself not just wanting to solve one problem, but rather to say “hmm, this is an interesting kind of problem. I wonder what general set of problems it falls into.” That’s also the thing about doing math, by the way.

So as I started thinking today about what Doug said, I found myself wondering “how could you make it possible for somebody to define the rules for a whole bunch of games — even their own original games?”

Thinking about it that way, I realized that defining the rules for chess isn’t all that complicated. There is “core chess”, which has almost ridiculously simple rules. And then there is “evolved chess” — those extra rules that got added over time to make the game more interesting. Evolved chess has added just the five following rules:

— Pawns can move two spaces forward on their first move.
— The en passant rule for pawns capturing pawns.
— Pawns capture on the diagonal.
— The “castling” move for a king and rook.
— Promoting a pawn when it gets to the end of the board.

Except for the above few extra rules, chess has only the following few core rules for how its pieces move:

–Which directions a piece can move.
–Whether a piece moves (i) to the nearest space, or (ii) any distance.

That’s because chess pieces always move in some regular pattern of compass directions around a circle. For example, a Rook or Bishop can move in only four directions, whereas a Knight or King or Queen can move in eight directions, and a Pawn can only move in one direction.

The complete set of rules for core chess can be expressed as a simple table:

 Rook: 4, even, any Bishop: 4, odd, any Queen: 8, even, any King: 8, even, nearest Knight: 8, odd, nearest Pawn: 1, even, nearest

What the above table says is that the Rook moves in any of four even compass directions (North, East, West, South), to any distance. The Bishop moves in any of four odd compass directions (NE, NW, SW, SE), to any distance. The Queen moves in any of eight even compass directions (N, NE, E, SE, S, SW, W, SW) to any distance.

Meanwhile, the King moves in any of eight even compass directions to the nearest square. The Knight moves in any of eight odd compass directions (NNE, ENE, ESE, SSE, SSW, WSW, WNW, NNW) to the nearest square. The Pawn moves in only one compass direction (North) to the nearest square.

So if you wanted to give somebody a way to create their own original board game, you could mostly just let them fill out their own version of the above table, one for each kind of piece they want to have.

If we did that, then who knows? Maybe some natural game-making genius out there will come up with an original game that’s incredibly cool.

### One Response to “Making chess”

1. Noah says:

Great post! Any thoughts on exposing the win condition of Chess to a similar treatment?

Our hypothetical game-making genius could make a number of different types of pieces vulnerable to checkmate, or even all of them. It would even be pretty easy to uncouple the idea of “capturing” from pieces and extend it to territory, allowing the player to define parts of the board to become vulnerable to checkmate.

Sounds like a lot of fun, both to program and to play with!