Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Make games/connect4.p6 work again
A few hacks to work around lack of certain features in the past could be
removed such that the game now works again as expected.
  • Loading branch information
Paul Cochrane committed Feb 24, 2015
1 parent e302aa2 commit cf8595c
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions games/connect4.p6
@@ -1,13 +1,14 @@
# pre-declare types
# XXX should actually be 'class Game { ... }' with the three periods
class Game { };
class Move { };
class Game { ... };
class Move { ... };

class Player {
method token { ... }
method highlighter_token { ... }
has Str $.token;
has Str $.highlighter_token;
#method token { ... }
#method highlighter_token { ... }

method get_move( Game $game ) { ... }
method get_move( Game $game ) { ... };
}

class HumanPlayer is Player {
Expand Down Expand Up @@ -67,7 +68,7 @@ class ComputerPlayer is Player {
}
}

class Game is also {
class Game {
has @board;
has Int @current_levels;

Expand Down Expand Up @@ -176,7 +177,7 @@ class Game is also {
method legal_moves (Player $who) {
my @moves;
for ^7 -> $column {
push @moves, Move.new( game => self, who => $who, column => int $column) unless @board[6][int $column];
push @moves, Move.new( game => self, who => $who, column => $column) unless @board[6][$column];
}
return @moves;
}
Expand All @@ -186,24 +187,22 @@ class Game is also {
self.display;

for ^49 -> $move_num {
my $who = @players[ int( $move_num % 2 ) ];
my $who = @players[ Int($move_num % 2) ];
my Move $where = $who.get_move( self );
my $win = $where.is_winning_move;
say "";
$where.play;
self.display;
if $win {
say "{$who.token} WINS on move { int($move_num/2) + 1 }!";
say "{$who.token} WINS on move { Int($move_num/2) + 1 }!";
return;
}
}
say "DRAW"
}
}

# the 'is also' is a hack because rakudo doesn't allow
# redeclaration of stubbed classes without it
class Move is also {
class Move {
has Game $.game;

has Player $.who;
Expand Down

0 comments on commit cf8595c

Please sign in to comment.