2012-10-01

Yes, finally, this is firming up

This will be a very short blog post because it’s 1 in the bloody morning and the day job awaits a few hours from now, but finally I have a real chess board, for some definition of real.”

See GitHub if you want the latest code.

Here’s an example of how things work now. White on top for the board display.

94> Board = newboard:init().
<0.527.0>
95> Board ! { self(), move, { 2, 1 }, {3, 3} }.
{<0.493.0>,move,{2,1},{3,3}}
96> flush().
Shell got {move,true,none}
ok
97> Board ! { self(), showboard }.


| R | N | B | K | Q | B |   | R |

| p | p | p | p | p | p | p | p |

|   |   |   |   |   | N |   |   |

|   |   |   |   |   |   |   |   |

|   |   |   |   |   |   |   |   |

|   |   |   |   |   |   |   |   |

| p | p | p | p | p | p | p | p |

| R | N | B | K | Q | B | N | R |

Great! We can move a knight and show it properly on the board.

Now let’s look at a failed move: I’ll try to move the white queen out of her starting square. (Yes, obviously I shouldn’t be able to move two white pieces consecutively.)

98> Board ! { self(), move, { 4, 1 }, {4, 3} }.
{<0.493.0>,move,{4,1},{4,3}}
99> flush().
Shell got {false,[66,108,111,99,107,105,110,103,32,112,105,101,99,101,32,40,
                  "pawn",41,32,97,116,32,
                  [123,["4",44,"3"],125]]}

Well, that wasn’t useful; the fact that a string in Erlang is just a list makes this a little more burdensome. Let’s try again by receiving the message and formatting it.

100> Board ! { self(), move, { 4, 1 }, {4, 3} }.
{<0.493.0>,move,{4,1},{4,3}}
101> receive { false, Explanation } -> io:format(Explanation) end.
Blocking piece (pawn) at {4,3}

So I goofed somewhere: it should read Blocking piece (pawn) at {4,2}. Nonetheless, I’m thrilled that I can’t move a queen through another piece!

erlang chessboard
Previous post
Chessboard: Day 12 It's a trap!
Next post
Noughts and Crosses When at chess you can't succeed, fall back to something simpler