Skip to content
Browse files

generalized board generation for tests

  • Loading branch information...
1 parent ba4d528 commit 4d7a8bbf71920e7f0efcd3e2f6bc13a84714808a @masak committed Feb 14, 2009
Showing with 19 additions and 4 deletions.
  1. +19 −4 t/shorty/01-you-complete-me.t
View
23 t/shorty/01-you-complete-me.t
@@ -3,15 +3,30 @@ use Druid::Player::Computer::Shorty;
plan 9;
+sub pieces($board) {
+ my @result;
+ my $board_new = $board.subst(/\s+/, '');
+ my $size = +$board_new.split("\n");
+ for $board_new.split("\n").kv -> $row, $line {
+ for $line.subst(/\s+/, '').split('').kv -> $column, $cell {
+ if $cell eq 'V' {
+ push @result, chr(ord('a')+$column)~($size-$row), 1;
+ }
+ }
+ }
+ return @result;
+}
+
# RAKUDO: Unable to rename named params with parens
sub assert(:$that!, :$yields!, :$desc = '') {
my $input = $that;
my $expected = $yields;
- my $game = Druid::Game.new(:size(3));
+ my $size = +$input.subst(/\s+/, '').split("\n");
+ my $game = Druid::Game.new(:size($size));
$game.init();
- # TODO: Generalize
- $game.make_move('b3', 1);
- $game.make_move('b2', 1);
+ for pieces($input) -> $pos, $player {
+ $game.make_move($pos, $player);
+ }
my $shorty = Druid::Player::Computer::Shorty.new(:$game, :color(1));
my $received = $shorty.choose_move();
is($received, $expected, $desc);

0 comments on commit 4d7a8bb

Please sign in to comment.
Something went wrong with that request. Please try again.