Class: ConnectNGame::BasicMoves
- Defined in:
- lib/connect_n_game/players/basic.rb
Overview
The EchoMoves echoes moves when possible.
Instance Attribute Summary
Attributes inherited from Player
Instance Method Summary collapse
-
#initialize(name = "Basic") ⇒ BasicMoves
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 = "Basic") ⇒ BasicMoves
Build the player
9 10 11 |
# File 'lib/connect_n_game/players/basic.rb', line 9 def initialize(name = "Basic") super(name, "Minimum tactical analysis.", :silicon) end |
Instance Method Details
#losers_comments ⇒ Object
The agony of defeat
32 33 34 |
# File 'lib/connect_n_game/players/basic.rb', line 32 def losers_comments "#{name} says 'Hmmm... What did I miss?'" end |
#make_move(game, piece) ⇒ Object
Make a move. This bot picks the move with the highest score.
Parameters
-
game - the game being played.
-
piece - the piece to be played, 1 or 2.
Returns
-
A move, 1 .. rack.width
19 20 21 22 23 24 |
# File 'lib/connect_n_game/players/basic.rb', line 19 def make_move(game, piece) (game.rack.weights.each_with_index.map do |weight, index| channel = index + 1 [weight + game.rack.score_move(channel, piece), channel] end).sort.show_weights("Scan").last[1] end |
#winners_comments ⇒ Object
The thrill of victory.
27 28 29 |
# File 'lib/connect_n_game/players/basic.rb', line 27 def winners_comments "#{name} says 'A genius in my own mind!'" end |