Written for readability, hopefully.
Currently is doing all the basic moves, but no fancy ones like casteling.
I don't plan on finishing it, I'm just interested in some of the challenges related to modelling the rules of the game. I have "played refactoring" after adding the queen, when I switched focus away from features.
It's a good expression of my current (2019) modelling skills using Object Oriented languages.
There is no frontend, the specs are the only consumers, and it's been developed TDD.
Take a peek starting at spec/game_spec.rb:40
and follow the code along.
Feel free to contact me for design questions or lessons.
puts Board.new
.A .B .C .D .E .F .G .H
| .8 Pa Kn Bi Pa Ki Bi Kn Pa 8. |
| .7 Pa Pa Pa Pa Pa Pa Pa Pa 7. |
| .6 __ __ __ __ __ __ __ __ 6. |
| .5 __ __ __ __ __ __ __ __ 5. |
| .4 __ __ __ __ __ __ __ __ 4. |
| .3 __ __ __ __ __ __ __ __ 3. |
| .2 Pa Pa Pa Pa Pa Pa Pa Pa 2. |
| .1 Pa Kn Bi Pa Ki Bi Kn Pa 1. |
.A .B .C .D .E .F .G .H
- I've been careful with dependency direction
- Naming, modularity and readability is to my satisfaction
- It's almost TDD
- I usually don't leave TODOs in the master branch when working in a team
I am using a sequence diagram instead of a class diagram because I like sequencediagram.org (thank you guys).
Below is the list of dependencies of every model, paste them in the website above.
title ChessOO
participant Game
participant Hand
participant Moves
participant Move
participant Board
participant Tile
participant Pieces
participant Position
Game->Hand:
Game->Move:
Game->Board:
Game->Pieces:
Hand->Moves:
Hand->Move:
Hand->Tile:
Hand->Pieces:
Moves->Move:
Moves->Tile:
Moves->Position:
Move->Board:
Move->Tile:
Move->Pieces:
Move->Position:
Board->Tile:
Board->Pieces:
Board->Position:
Tile->Pieces:
Tile->Position:
bin/bundle
bin/rspec --format documentation
That's it, there are only specs.
Keep guard up, write a spec and make it green.
bin/guard
- Don't create new tiles, define position values and use
board.tile_at
- Print the board with
puts board
(and other objects) binding.pry
is available
Most of the calculations can be found in Move, Moves, Position
, here's a breakdown:
- Start in
game_spec
kills the king with the bishop
game
checks the game is not over- Uses the
hand
to make the move - The
move
links the board to the pieces on the board Board
tracks where the pieces are- In
moves
is where the logic for the pieces is Position
has the math to navigate the board
- COLORS!!
- Castelling
- Pawns enpassant
- Pawn enpassant kill
- Pawn promotion
- Pawn opening of 2
- King under attack
- Draw rules
- Can you write it without:
Hand Tile Moves
? - Test Rook two axes
- Bishop other diagonal
- Review private methods
- Rename
start -> beginning
orinitial, final
,a, b
or... - Chainable
move.call
- Immutable
- Engage here
Licence: See the MIT-LICENCE file, no surprises there.
Contributions: Sure, why not, follow any template.
Have a good day!