Class: ConnectNGame::MiddleMoves
- Defined in:
- lib/connect_n_game/players/middle.rb
Overview
The EchoMoves echoes moves when possible.
Instance Attribute Summary
Attributes inherited from Player
Instance Method Summary collapse
-
#initialize(name = "Middle") ⇒ MiddleMoves
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 = "Middle") ⇒ MiddleMoves
Build the player
9 10 11 |
# File 'lib/connect_n_game/players/middle.rb', line 9 def initialize(name = "Middle") super(name, "Moves toward the middle", :silicon) end |
Instance Method Details
#losers_comments ⇒ Object
The agony of defeat
34 35 36 |
# File 'lib/connect_n_game/players/middle.rb', line 34 def losers_comments "#{name} says 'I lost to the lunatic fringe!'" end |
#make_move(game, _piece) ⇒ Object
Make a move. This bot prefers to play the middle.
Parameters
-
game - the game being played.
-
_piece - the piece to be played, 1 or 2. (Not used here)
Returns
-
A move, 1 .. rack.width
19 20 21 22 23 24 25 26 |
# File 'lib/connect_n_game/players/middle.rb', line 19 def make_move(game, _piece) weights = game.rack.weights.each_with_index.to_a weights.sort.reverse_each do |weight, index| channel = index + 1 return channel unless game.rack.channel_full?(channel) end end |
#winners_comments ⇒ Object
The thrill of victory.
29 30 31 |
# File 'lib/connect_n_game/players/middle.rb', line 29 def winners_comments "#{name} says 'Slow and steady wins the race!'" end |