From 0cfbfcdc8d611e2fd6fb5a070bef79a188388d97 Mon Sep 17 00:00:00 2001 From: Carl Masak Date: Thu, 8 Jan 2009 22:54:35 +0100 Subject: [PATCH] generalized the move syntax regexes to arbritary board sizes --- druid | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/druid b/druid index d2c24dc..0171436 100644 --- a/druid +++ b/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 @@ -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