Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
first step at generalizing the board size from 8: a sub that produces an
empty board of a given size
  • Loading branch information
masak committed Dec 28, 2008
1 parent ba59db8 commit 18ebc4b
Showing 1 changed file with 33 additions and 29 deletions.
62 changes: 33 additions & 29 deletions druid.p6
Expand Up @@ -284,35 +284,39 @@ sub move_was_winning($move, @colors) {
return False;
}

my $empty_board = '
A B C D E F G H
+-----+-----+-----+-----+-----+-----+-----+-----+
8 | | 8
| |
+ + + + + + + + +
7 | | 7
| |
+ + + + + + + + +
6 | | 6
| |
+ + + + + + + + +
5 | | 5
| |
+ + + + + + + + +
4 | | 4
| |
+ + + + + + + + +
3 | | 3
| |
+ + + + + + + + +
2 | | 2
| |
+ + + + + + + + +
1 | | 1
| |
+-----+-----+-----+-----+-----+-----+-----+-----+
A B C D E F G H
';
# Returns a string containing an ASCII picture of an empty druid board of the
# given size.
sub make_empty_board($size) {
return join "\n", gather {
take '';
take my $heading
= join '',
' ',
map { " $_ " },
map { chr($_+ord('A')) },
^$size;
take my $line
= join '', ' ', '+-----' x $size, '+';
for (1..$size).reverse -> $r {
# NB: This will not work for sizes >= 10
take join '',
(sprintf '%2d |', $r),
' ' x ($size) - 1,
" | $r";
take join '', ' |', ' ' x ($size) - 1, ' |';
if $r > 1 {
take join '', ' +', ' +' x $size;
}
}
take $line;
take $heading;
take '';
};
}


my $board_size = 8;
my $empty_board = make_empty_board($board_size);

my $v_piece = '
+-----+
Expand Down

0 comments on commit 18ebc4b

Please sign in to comment.