Class: AIGames::FourInARow::Match
- Inherits:
-
Object
- Object
- AIGames::FourInARow::Match
- 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
- #bots ⇒ Object readonly
-
#enemy_bot ⇒ Object
readonly
The enemy’s bot.
-
#my_bot ⇒ Object
readonly
The player’s bot.
-
#parser ⇒ Object
readonly
The instance of the parser.
-
#playing_field ⇒ Object
readonly
The instance of the playing field.
-
#round ⇒ Object
The current round.
Instance Method Summary collapse
-
#initialize(bot = nil) ⇒ Match
constructor
Initializes a new match instance.
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 = .new(6, 7) end |
Instance Attribute Details
#bots ⇒ Object (readonly)
40 41 42 |
# File 'lib/ai_games/four_in_a_row/match.rb', line 40 def bots @bots end |
#enemy_bot ⇒ Object (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_bot ⇒ Object (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 |
#parser ⇒ Object (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_field ⇒ Object (readonly)
The instance of the playing field
55 56 57 |
# File 'lib/ai_games/four_in_a_row/match.rb', line 55 def end |
#round ⇒ Object
The current round
49 50 51 |
# File 'lib/ai_games/four_in_a_row/match.rb', line 49 def round @round end |