Skip to content

Commit

Permalink
generalized the move syntax regexes to arbritary board sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
Carl Masak committed Jan 8, 2009
1 parent 1204491 commit 0cfbfcd
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions druid
@@ -1,4 +1,4 @@
#!perl6
use v6;

# Given a string (assumed to contain no newlines), replaces a section of that
# string, starting from $column, with the contents of $new_section. When
Expand Down Expand Up @@ -339,8 +339,20 @@ my $h_piece = '
/-----/
';

my $sarsen_move = /^ <[a..h]><[1..8]> $/;
my $lintel_move = /^ <[a..h]><[1..8]> '-' <[a..h]><[1..8]> $/;
# This didn't come out at all the way I wanted it to. I thought I'd use
# assertions to check for the board limits, but that didn't work; I wanted
# to declare the letter, number and coords things as regexes, but that didn't
# work; I thought I'd call the regexes in the variables from the regexes in
# $sarsen_move and $lintel_move, but that didn't work. Finally I had to
# settle for the following: creating strings and eval'ing them.
my $max_l = chr(ord('a') + $board_size - 1);
my $col_letter = "<[a..$max_l]>";
my $row_number = '[' ~ (1..$board_size).join('|') ~ ']';
my $coords = $col_letter ~ $row_number;

# Note that the dollar sign has to be backwhacked.
my $sarsen_move = eval("/^ $coords \$/");
my $lintel_move = eval("/^ $coords '-' $coords \$/");

# A three-dimensional array. Each item is a layer in on the board, starting
# from the ground. The number of elements in this array always corresponds to
Expand Down

0 comments on commit 0cfbfcd

Please sign in to comment.