class ConnectNGame::JustRandom
The JustRandom
player simply make random moves.
Public Class Methods
new(name = "Random")
click to toggle source
Build the player
Calls superclass method
ConnectNGame::Player::new
# File lib/connect_n_game/players/just_random.rb, line 9 def initialize(name = "Random") super(name, "Moves randomly.", :silicon) end
Public Instance Methods
losers_comments()
click to toggle source
The agony of defeat
# File lib/connect_n_game/players/just_random.rb, line 33 def losers_comments "#{name} says 'No comment.'" end
make_move(game, _piece)
click to toggle source
Make a move. This bot moves randomly.
Parameters
-
game - the game being played.
-
_piece - the piece to be played, 1 or 2. (Not used here)
Returns
-
A move, 1 .. rack.width
# File lib/connect_n_game/players/just_random.rb, line 19 def make_move(game, _piece) begin channel = rand(1..(game.rack.width)) end while game.rack.channel_full?(channel) channel end
winners_comments()
click to toggle source
The thrill of victory.
# File lib/connect_n_game/players/just_random.rb, line 28 def winners_comments "#{name} says 'It was all up to pure skill!'" end