From cbe5cf384a5fe0933fdf16099dad1bb7b928c00e Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Tue, 2 Jun 2009 01:24:13 -0500 Subject: use the CurrentPlayer role in the chess plugin --- lib/Bot/Games/Game/Chess.pm | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/Bot/Games/Game/Chess.pm b/lib/Bot/Games/Game/Chess.pm index fb32c9d..ad4549c 100644 --- a/lib/Bot/Games/Game/Chess.pm +++ b/lib/Bot/Games/Game/Chess.pm @@ -1,6 +1,7 @@ package Bot::Games::Game::Chess; use Bot::Games::OO::Game; extends 'Bot::Games::Game'; +with 'Bot::Games::Game::Role::CurrentPlayer'; use Chess::Rep; use App::Nopaste; @@ -31,9 +32,8 @@ augment turn => sub { $self->add_player($player) unless $self->has_player($player); return "The game has already begun between " . join ' and ', $self->players unless $self->has_player($player); - my $player_index = $self->game->to_move ? 0 : 1; return "It's not your turn" - if $player ne ($self->players->[$player_index] || ''); + if $player ne $self->current_player; my $status = eval { $self->game->go_move($move) }; return $@ if $@; @@ -41,6 +41,7 @@ augment turn => sub { $self->inc_turn if $self->game->to_move; $self->is_active(0) if $self->game->status->{mate} || $self->game->status->{stalemate}; + $self->current_player($self->next_player); return "$desc: " . App::Nopaste::nopaste(text => $self->game->dump_pos, desc => $desc, -- cgit v1.2.3