An implementation of chess in ruby, without AI
loop do
ruby chess.rb
enjoy
end
Chess pieces are weird because there are many different ways they move.
- Knights and kings are jumpers: they have a list of places they can go, and can't do anything about it.
- Queens, Rooks and Bishops are sliders: they pick a direction and can go until they run into something.
- Pawns are ... well, pawns. They can move in one direction, unless they are attacking and then they move in an entirely different direction.
In addition to knowing how to move, they also know how to render themselves. It's cute, and uses Unicode.
The chess board does a fair bit of lifting for us.
- It reports back subsets of the pieces still on it
- It can see if a color is in check.
- It actually removes pieces and places them an a new square for us.
- Renders prettily with color scheme.
- Keep track of and displays captured pieces.
The Chess class does all of the game logic.
- It checks to see if we're in checkmate.
- It does error handling for user input.
- It parses 'nice' input (e.g.
E4 => [4, 4]
) - Can save/load/quit during gameplay.
Created specific errors for all possible bad outcomes during a game.
All carry own messages, but also some take data necessary for message from game class.
- Add castling
- Add en pessant
- Add promotion
- Maybe play with
curses
gem to make the interface swank in shell.
- Port code to
jruby
and make the interface swank in an 'embeddable in a webpage' sorta way.