Skip to content

Commit

Permalink
various changes
Browse files Browse the repository at this point in the history
  • Loading branch information
grondilu committed Dec 31, 2014
1 parent adfa530 commit fce51fb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 34 deletions.
19 changes: 6 additions & 13 deletions lib/Chess/FEN.pm6
@@ -1,18 +1,9 @@
grammar Chess::FEN;

rule TOP {
<rank> ** 8 % '/'
<active-color>
<castling>
<en-passant>
<half-move-clock>
<full-move-number>
}

token rank {
[ <piece> | <empty-squares> ] ** 1..8
}
rule TOP { <board> <active-color> <castling> <en-passant> <half-move-clock> <full-move-number> }

token board { <rank> ** 8 % '/' }
token rank { ( <piece> | <empty-squares> ) ** 1..8 }
token active-color { w | b }
token castling { '-' | < K k Q q > ** 1..4 }
token en-passant { '-' | <file>< 3 6 > }
Expand All @@ -21,5 +12,7 @@ token full-move-number { <number>+ }
token number { '0' | <[1..9]><digit>* }

token file { < a b c d e f g h > }
token piece { < K Q R B N P k q r b n p > }
token piece { <black-piece> | <white-piece> }
token white-piece { < K Q R B N P > }
token black-piece { < k q r b n p > }
token empty-squares { <[1..8]> }
2 changes: 2 additions & 0 deletions t/fen.t
Expand Up @@ -11,3 +11,5 @@ for
{
ok Chess::FEN.parse(.value), .key;
}

# vim: ft=perl6
22 changes: 1 addition & 21 deletions t/pgn.t
@@ -1,7 +1,7 @@
use Chess::PGN;

use Test;
plan 10;
plan 8;

ok Chess::PGN.parse('1. e4'), "simple first move";
ok Chess::PGN.parse('2... e5'), "black to move";
Expand All @@ -12,25 +12,5 @@ ok Chess::PGN.parse('1. e4 g5 2. d4 f5 3. Qh5#'), "dumb mate";
ok Chess::PGN.parse('1. e4 g5?! 2. d4 f5?? 3. Qh5#'), "dumb mate with comments";
ok Chess::PGN.parse('1. e4 g5?! 2. d4 f5?? 3. Qh5# 1-0'), "dumb mate with adjudication";

ok Chess::PGN.parse(q :to /§/), "full game example from Wikipedia";
[Event "F/S Return Match"]
[Site "Belgrade, Serbia Yugoslavia|JUG"]
[Date "1992.11.04"]
[Round "29"]
[White "Fischer, Robert J."]
[Black "Spassky, Boris V."]
[Result "1/2-1/2"]
1. e4 e5 2. Nf3 Nc6 3. Bb5 a6 {This opening is called the Ruy Lopez.}
4. Ba4 Nf6 5. O-O Be7 6. Re1 b5 7. Bb3 d6 8. c3 O-O 9. h3 Nb8 10. d4 Nbd7
11. c4 c6 12. cxb5 axb5 13. Nc3 Bb7 14. Bg5 b4 15. Nb1 h6 16. Bh4 c5 17. dxe5
Nxe4 18. Bxe7 Qxe7 19. exd6 Qf6 20. Nbd2 Nxd6 21. Nc4 Nxc4 22. Bxc4 Nb6
23. Ne5 Rae8 24. Bxf7+ Rxf7 25. Nxf7 Rxe1+ 26. Qxe1 Kxf7 27. Qe3 Qg5 28. Qxg5
hxg5 29. b3 Ke6 30. a3 Kd6 31. axb4 cxb4 32. Ra5 Nd5 33. f3 Bc8 34. Kf2 Bf5
35. Ra7 g6 36. Ra6+ Kc5 37. Ke1 Nf4 38. g3 Nxh3 39. Kd2 Kb5 40. Rd6 Kc5 41. Ra6
Nf2 42. g4 Bd3 43. Re6 1/2-1/2
§

ok Chess::PGN.parse: slurp 't/world-chess-2013-anand-carlsen.pgn';

# vim: ft=perl6

0 comments on commit fce51fb

Please sign in to comment.