Module: ApplicationDefs

Included in:
MatchStartController
Defined in:
lib/application_defs.rb

Overview

Assortment of constant definitions.

Constant Summary collapse

LOG_DIRECTORY =
Rails.root.join('log')
MATCH_LOG_DIRECTORY =
File.join(LOG_DIRECTORY, 'match_logs')

Class Method Summary collapse

Class Method Details

.bots(game_def_key, player_names) ⇒ Array<Class>

Returns only the names that correspond to bot runner classes as those classes.

Returns:

  • (Array<Class>)

    Returns only the names that correspond to bot runner classes as those classes.



35
36
37
38
39
# File 'lib/application_defs.rb', line 35

def self.bots(game_def_key, player_names)
  player_names.map do |name|
    game_definitions[game_def_key][:opponents][name]
  end.reject { |elem| elem.nil? }
end

.game_definitionsObject

Human opponent names map to nil



23
24
25
26
27
28
29
30
31
# File 'lib/application_defs.rb', line 23

def self.game_definitions
  lcl_game_defs = Bots::STATIC_GAME_DEFINITIONS.dup
  # Uncomment these lines to include user names in the opponent selection menu.
  #lcl_game_defs.each do |type, prop|
  #User.each do |user|
  #    prop[:opponents].merge! user.name => nil
  #  end
  #end
end

.included(klass) ⇒ Object

TODO:

Not sure if this is necessary



8
9
10
11
12
# File 'lib/application_defs.rb', line 8

def self.included(klass)
  klass.class_eval do
    include Bots
  end
end

.random_seat(num_players) ⇒ Object



40
41
42
# File 'lib/application_defs.rb', line 40

def self.random_seat(num_players)
  rand(num_players) + 1
end

.random_seedObject



43
44
45
46
# File 'lib/application_defs.rb', line 43

def self.random_seed
  random_float = rand
  random_int = (random_float * 10**random_float.to_s.length).to_i
end