Class: AIGames::FourInARow::Match

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/ai_games/four_in_a_row/match.rb

Overview

This class maintains a state of the current match and provides access to the bots, the playing field and the parser. It implements the singleton pattern to ensure that only a single instance of the match state exists at any given time.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bot = nil) ⇒ Match

Initializes a new match instance. If a custom bot is given, it is used as the player’s bot, else the default bot is used for both the player and the enemy.



60
61
62
63
64
65
66
67
68
# File 'lib/ai_games/four_in_a_row/match.rb', line 60

def initialize(bot = nil)
  @bots = {}
  @bots[0] = nil
  @my_bot = bot || Bot.new(self)
  @enemy_bot = Bot.new(self)
  @parser = Parser.new(self)
  @round = 0
  @playing_field = PlayingField.new(6, 7)
end

Instance Attribute Details

#botsObject (readonly)

A hash mapping the ids to the bots, with bots being nil and bots and bots containing the two players.



40
41
42
# File 'lib/ai_games/four_in_a_row/match.rb', line 40

def bots
  @bots
end

#enemy_botObject (readonly)

The enemy’s bot



46
47
48
# File 'lib/ai_games/four_in_a_row/match.rb', line 46

def enemy_bot
  @enemy_bot
end

#my_botObject (readonly)

The player’s bot



43
44
45
# File 'lib/ai_games/four_in_a_row/match.rb', line 43

def my_bot
  @my_bot
end

#parserObject (readonly)

The instance of the parser



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

def parser
  @parser
end

#playing_fieldObject (readonly)

The instance of the playing field



55
56
57
# File 'lib/ai_games/four_in_a_row/match.rb', line 55

def playing_field
  @playing_field
end

#roundObject

The current round



49
50
51
# File 'lib/ai_games/four_in_a_row/match.rb', line 49

def round
  @round
end