Class: AIGames::FourInARow::Bot

Inherits:
Object
  • Object
show all
Defined in:
lib/ai_games/four_in_a_row/bot.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(match = nil) ⇒ Bot

Initializes a new bot.



38
39
40
# File 'lib/ai_games/four_in_a_row/bot.rb', line 38

def initialize(match = nil)
  @match = match || Match.instance
end

Instance Attribute Details

#current_time_bankObject

Time in milliseconds that the bot has in its time bank



26
27
28
# File 'lib/ai_games/four_in_a_row/bot.rb', line 26

def current_time_bank
  @current_time_bank
end

#matchObject (readonly)

The match instance



35
36
37
# File 'lib/ai_games/four_in_a_row/bot.rb', line 35

def match
  @match
end

#maximum_time_bankObject

Maximum time in milliseconds that the bot can have in its time bank



29
30
31
# File 'lib/ai_games/four_in_a_row/bot.rb', line 29

def maximum_time_bank
  @maximum_time_bank
end

#time_per_moveObject

Time in milliseconds that is added to the bot’s time bank each move



32
33
34
# File 'lib/ai_games/four_in_a_row/bot.rb', line 32

def time_per_move
  @time_per_move
end

Instance Method Details

#place_discObject

Places a disk. This method MUST return a single integer value, denoting the column you want to drop a pin in. To customize your bot, overwrite this method with your own implementation.



45
46
47
# File 'lib/ai_games/four_in_a_row/bot.rb', line 45

def place_disc
  rand(0...match.playing_field.columns)
end

#runObject

Starts this bot.



56
57
58
# File 'lib/ai_games/four_in_a_row/bot.rb', line 56

def run
  @match.parser.run
end

#update(row, column, new_owner) ⇒ Object

Handles changes on the playing field. Whenever the “owner” of a cell changes, the bot gets notified about it via this method. Overwrite this method to add your own logic.



52
53
# File 'lib/ai_games/four_in_a_row/bot.rb', line 52

def update(row, column, new_owner)
end