Class: AcpcPokerTypes::DealerData::MatchDefinition

Inherits:
Object
  • Object
show all
Defined in:
lib/acpc_poker_types/dealer_data/match_definition.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, game_def, number_of_hands, random_seed, player_names) ⇒ MatchDefinition

Returns a new instance of MatchDefinition.



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/acpc_poker_types/dealer_data/match_definition.rb', line 32

def initialize(name, game_def, number_of_hands, random_seed, player_names)
  if game_def.number_of_players != player_names.length
    raise IncorrectNumberOfPlayerNames, "number of players: #{game_def.number_of_players}, number of names: #{player_names.length}"
  end

  @name = name.to_s
  @game_def = game_def
  @number_of_hands = number_of_hands.to_i
  @random_seed = random_seed.to_i
  @player_names = player_names
end

Instance Attribute Details

#game_defObject (readonly)

Returns the value of attribute game_def.



13
14
15
# File 'lib/acpc_poker_types/dealer_data/match_definition.rb', line 13

def game_def
  @game_def
end

#nameObject (readonly)

Returns the value of attribute name.



13
14
15
# File 'lib/acpc_poker_types/dealer_data/match_definition.rb', line 13

def name
  @name
end

#number_of_handsObject (readonly)

Returns the value of attribute number_of_hands.



13
14
15
# File 'lib/acpc_poker_types/dealer_data/match_definition.rb', line 13

def number_of_hands
  @number_of_hands
end

#player_namesObject (readonly)

Returns the value of attribute player_names.



13
14
15
# File 'lib/acpc_poker_types/dealer_data/match_definition.rb', line 13

def player_names
  @player_names
end

#random_seedObject (readonly)

Returns the value of attribute random_seed.



13
14
15
# File 'lib/acpc_poker_types/dealer_data/match_definition.rb', line 13

def random_seed
  @random_seed
end

Class Method Details

.parse(acpc_log_string, player_names, game_def_directory) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/acpc_poker_types/dealer_data/match_definition.rb', line 15

def self.parse(acpc_log_string, player_names, game_def_directory)
  if acpc_log_string.strip.match(
    '^\s*#\s*name/game/hands/seed\s+(\S+)\s+(\S+)\s+(\d+)\s+(\d+)\s*$'
  )
    name = $1
    game_def = AcpcPokerTypes::GameDefinition.parse_file(
      File.join(game_def_directory, File.basename($2))
    )
    number_of_hands = $3
    random_seed = $4

    new(name, game_def, number_of_hands, random_seed, player_names)
  else
    nil
  end
end

Instance Method Details

#==(other) ⇒ Object



44
45
46
47
48
49
50
51
52
# File 'lib/acpc_poker_types/dealer_data/match_definition.rb', line 44

def ==(other)
  (
    @name == other.name &&
    Set.new(@game_def.to_a) == Set.new(other.game_def.to_a) &&
    @number_of_hands == other.number_of_hands &&
    @random_seed == other.random_seed &&
    @player_names == other.player_names
  )
end