Class: ConnectNGame::BasicMoves

Inherits:
Player
  • Object
show all
Defined in:
lib/connect_n_game/players/basic.rb

Overview

The EchoMoves echoes moves when possible.

Instance Attribute Summary

Attributes inherited from Player

#description, #name, #type

Instance Method Summary collapse

Methods inherited from Player

#carbon?, #silicon?

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_commentsObject

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_commentsObject

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