Class: Basketball::Season::Arena

Inherits:
Object
  • Object
show all
Defined in:
lib/basketball/season/arena.rb

Overview

A very, very, very basic starting point for a “semi-randomized” game simulator.

Constant Summary collapse

RANDOM =
:random
TOP_ONE =
:top_one
TOP_TWO =
:top_two
TOP_THREE =
:top_three
TOP_SIX =
:top_six
DEFAULT_MAX_HOME_ADVANTAGE =
5
DEFAULT_STRATEGY_FREQUENCIES =
{
  RANDOM => 3,
  TOP_ONE => 1,
  TOP_TWO => 1,
  TOP_THREE => 1,
  TOP_SIX => 1
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(strategy_frquencies: DEFAULT_STRATEGY_FREQUENCIES, max_home_advantage: DEFAULT_MAX_HOME_ADVANTAGE) ⇒ Arena

Returns a new instance of Arena.



24
25
26
27
28
29
30
31
32
# File 'lib/basketball/season/arena.rb', line 24

def initialize(
  strategy_frquencies: DEFAULT_STRATEGY_FREQUENCIES,
  max_home_advantage: DEFAULT_MAX_HOME_ADVANTAGE
)
  @max_home_advantage = max_home_advantage
  @lotto              = make_lotto(strategy_frquencies)

  freeze
end

Instance Attribute Details

#lottoObject (readonly)

Returns the value of attribute lotto.



22
23
24
# File 'lib/basketball/season/arena.rb', line 22

def lotto
  @lotto
end

#max_home_advantageObject (readonly)

Returns the value of attribute max_home_advantage.



22
23
24
# File 'lib/basketball/season/arena.rb', line 22

def max_home_advantage
  @max_home_advantage
end

Instance Method Details

#play(matchup) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/basketball/season/arena.rb', line 34

def play(matchup)
  scores        = generate_scores
  winning_score = scores.max
  losing_score  = scores.min
  strategy      = pick_strategy

  if home_wins?(matchup, strategy)
    Result.new(
      game: matchup.game,
      home_score: winning_score,
      away_score: losing_score
    )
  else
    Result.new(
      game: matchup.game,
      home_score: losing_score,
      away_score: winning_score
    )
  end
end