Class: ConnectNGame::EchoMoves
- Defined in:
- lib/connect_n_game/players/echo.rb
Overview
The EchoMoves echoes moves when possible.
Instance Attribute Summary
Attributes inherited from Player
Instance Method Summary collapse
-
#initialize(name = "Echo") ⇒ EchoMoves
constructor
Build the player.
-
#losers_comments ⇒ Object
The agony of defeat.
-
#make_move(game, _piece) ⇒ Object
Make a move.
-
#winners_comments ⇒ Object
The thrill of victory.
Methods inherited from Player
Constructor Details
#initialize(name = "Echo") ⇒ EchoMoves
Build the player
9 10 11 |
# File 'lib/connect_n_game/players/echo.rb', line 9 def initialize(name = "Echo") super(name, "Really unoriginal.", :silicon) end |
Instance Method Details
#losers_comments ⇒ Object
The agony of defeat
38 39 40 |
# File 'lib/connect_n_game/players/echo.rb', line 38 def losers_comments "#{name} says 'Yes! I came in second!'" end |
#make_move(game, _piece) ⇒ Object
Make a move. This bot parrots the previous move when it can, and moves randomly when it cannot.
Parameters
-
game - the game being played.
-
_piece - the piece to be played, 1 or 2. (Not used here)
Returns
-
A move, 1 .. rack.width
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/connect_n_game/players/echo.rb', line 20 def make_move(game, _piece) channel = game.last_move unless channel && !game.rack.channel_full?(channel) begin channel = rand(1..(game.rack.width)) end while game.rack.channel_full?(channel) end channel end |
#winners_comments ⇒ Object
The thrill of victory.
33 34 35 |
# File 'lib/connect_n_game/players/echo.rb', line 33 def winners_comments "#{name} says 'How did this happen?'" end |