basketball 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +15 -7
  3. data/README.md +26 -24
  4. data/basketball.gemspec +2 -2
  5. data/exe/basketball-draft +1 -1
  6. data/exe/{basketball-schedule → basketball-season-scheduling} +1 -1
  7. data/lib/basketball/{drafting → draft}/cli.rb +34 -34
  8. data/lib/basketball/{drafting → draft}/event.rb +1 -1
  9. data/lib/basketball/{drafting → draft}/front_office.rb +1 -1
  10. data/lib/basketball/{drafting → draft}/league.rb +1 -1
  11. data/lib/basketball/{drafting → draft}/pick_event.rb +1 -1
  12. data/lib/basketball/{drafting → draft}/player.rb +1 -1
  13. data/lib/basketball/{drafting → draft}/player_search.rb +1 -1
  14. data/lib/basketball/{drafting → draft}/position.rb +1 -1
  15. data/lib/basketball/{drafting/engine.rb → draft/room.rb} +2 -2
  16. data/lib/basketball/{drafting/engine_serializer.rb → draft/room_serializer.rb} +33 -33
  17. data/lib/basketball/{drafting → draft}/roster.rb +1 -1
  18. data/lib/basketball/{drafting → draft}/sim_event.rb +1 -1
  19. data/lib/basketball/{drafting → draft}/skip_event.rb +1 -1
  20. data/lib/basketball/{drafting.rb → draft.rb} +2 -2
  21. data/lib/basketball/{scheduling → season}/calendar.rb +1 -1
  22. data/lib/basketball/{scheduling → season}/calendar_serializer.rb +1 -1
  23. data/lib/basketball/{scheduling → season}/conference.rb +1 -1
  24. data/lib/basketball/{scheduling → season}/coordinator.rb +2 -2
  25. data/lib/basketball/{scheduling → season}/division.rb +1 -1
  26. data/lib/basketball/{scheduling → season}/game.rb +1 -1
  27. data/lib/basketball/{scheduling → season}/league.rb +1 -1
  28. data/lib/basketball/{scheduling → season}/league_serializer.rb +1 -1
  29. data/lib/basketball/{scheduling → season}/preseason_game.rb +1 -1
  30. data/lib/basketball/{scheduling/cli.rb → season/scheduling_cli.rb} +9 -9
  31. data/lib/basketball/{scheduling → season}/season_game.rb +1 -1
  32. data/lib/basketball/{scheduling → season}/team.rb +1 -1
  33. data/lib/basketball/{scheduling.rb → season.rb} +2 -2
  34. data/lib/basketball/version.rb +1 -1
  35. data/lib/basketball.rb +2 -2
  36. metadata +32 -32
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 00ac0278bb2e786c5a68b3cc7ac8fd5d49005f9f9a01fad32501c75a00880dce
4
- data.tar.gz: 4b76f9d42a702a206c837346de20396c6948c9bcb071a4143610e8179ba93c64
3
+ metadata.gz: c6417577ab066cf68ac376551774f538e5ba1d018139e2d2e99af4a607acf10e
4
+ data.tar.gz: 2bf491b44bfb3591e411e105c33353f20044933662dc8f4a64999144f943bd3d
5
5
  SHA512:
6
- metadata.gz: 806f800744de18f81e590cd712adf83592e372b8f1b19c3b8f9a6e702c7fbc04981380ba784b63436f2cc34d5f80238c0fce53366eed8a2a8a63eb9b64cb69c4
7
- data.tar.gz: acffa65b0315e7d5ec6638cd92c217e9aa665787114935d0859a4b6b02cfb0c8afd6e66d7914de6b147d6878d83ca210b2d5f5bfbdeb748784f559300fe79d46
6
+ metadata.gz: bbc69e448e39af4cb2a1df48d2e1fa729cc3eb85868b15eb8127aaac32ed57672c3c16cc1afa38cc147b2e9770e06bf89df9325a737ee1ea4f067afb253ced92
7
+ data.tar.gz: 1b0046ce516d37e5d1b86f818213b2e0dd1197be910338bc380a653aecb9158bdb85f5647452f2889ebba4fe2dc7b02b85ce2df4d32bae814d7ea10563bb1204
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+
2
+ #### 0.0.8 - May 15th, 2023
3
+
4
+ * Renamed Drafting to Draft to match bounded context word form.
5
+ * Renamed Drafting::Engine to Draft::Room for better language.
6
+ * Renamed Scheduling to Season to include more things other than scheduling.
7
+ * Issued README warning for 0.0.X releases not having stable APIs.
8
+
1
9
  #### 0.0.7 - May 14th, 2023
2
10
 
3
11
  * Added #to_hash and #from_hash serializer methods to allow larger consumer json constructions more directly.
@@ -5,22 +13,22 @@
5
13
 
6
14
  #### 0.0.6 - May 11th, 2023
7
15
 
8
- * Added Scheduling module that can generate full schedules for entire league.
9
- * Drafting::Event does not have identity anymore (no current tangible benefit).
16
+ * Added Season module that can generate full schedules for entire league.
17
+ * Draft::Event does not have identity anymore (no current tangible benefit).
10
18
 
11
19
  #### 0.0.5 - May 5th, 2023
12
20
 
13
21
  * Remove the notion of Team in favor of a flat front office.
14
22
  #### 0.0.4 - May 5th, 2023
15
23
 
16
- * Add ability to skip draft picks using `Basketball::Drafting::Engine#skip!`
17
- * Add ability to output event full drafting event log using CLI: `basketball-draft -i tmp/draft-wip.json -l`
24
+ * Add ability to skip draft picks using `Basketball::Draft::Room#skip!`
25
+ * Add ability to output event full draft event log using CLI: `basketball-draft -i tmp/draft-wip.json -l`
18
26
  * Add ability to skip draft picks using CLI: `basketball-draft -i tmp/draft-wip.json -x 1`
19
27
 
20
28
  #### 0.0.3 - May 5th, 2023
21
29
 
22
- * `Drafting::Engine#sim!` should return events
23
- * Added `Drafting::Engine#undrafted_player_search`
30
+ * `Draft::Room#sim!` should return events
31
+ * Added `Draft::Room#undrafted_player_search`
24
32
 
25
33
  #### 0.0.2 - May 4th, 2023
26
34
 
@@ -28,4 +36,4 @@
28
36
 
29
37
  #### 0.0.1 - May 4th, 2023
30
38
 
31
- * Initial release with Drafting module only
39
+ * Initial release with Draft module only
data/README.md CHANGED
@@ -2,7 +2,9 @@
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/basketball.svg)](https://badge.fury.io/rb/basketball) [![CI](https://github.com/mattruggio/basketball/actions/workflows/ci.yaml/badge.svg)](https://github.com/mattruggio/basketball/actions/workflows/ci.yaml) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
4
4
 
5
- #### Basketball League Game Engine
5
+ :warning: **Note:** This is currently in the early phases of initial development. Consider all 0.0.X releases as having unstable APIs between versions. A formal 0.1 minor release will be eventually releases which will honor [Semver](https://semver.org/).
6
+
7
+ #### Basketball League Game Room
6
8
 
7
9
  This library is meant to serve as the domain for a basketball league/season simulator/turn-based game. It models core ideas such as: players, general managers, draft strategy, drafting, season generation, season simultation, playoff generation, playoff simulation, and more.
8
10
 
@@ -30,24 +32,24 @@ bundle binstubs basketball
30
32
 
31
33
  This library is broken down into several bounded contexts that can be consumed either via its Ruby API's or CLI through provided executable scripts:
32
34
 
33
- ![Basketball Architecture - Overview](/docs/architecture/overview.png)
35
+ ![Basketball Architecture - Overview](/docs/architecture/Basketball%20Architecture%20-%20Overview.png)
34
36
 
35
37
  #### Command Line Interfaces
36
38
 
37
39
  Each module is meant to be interfaced with using its Ruby API by consuming applications. Each module also ships with a CLI script (backed by a module service) which a user can interact with to emulate different portions of the league management process. Technically speaking, the CLI provides an example application built on top of the each individual core module. Each module section below should contain with it example CLI calls.
38
40
 
39
- ## Drafting Module
41
+ ## Draft Module
40
42
 
41
- The drafting module is responsible for providing a turn-based iterator allowing the consumer to either manually pick or simulate picks. Here is a cartoon showing the major components:
43
+ The draft module is responsible for providing a turn-based iterator allowing the consumer to either manually pick or simulate picks. Here is a cartoon showing the major components:
42
44
 
43
- ![Basketball Architecture - Drafting](/docs/architecture/drafting.png)
45
+ ![Basketball Architecture - Draft](/docs/architecture/Basketball%20Architecture%20-%20Draft.png)
44
46
 
45
47
  Element | Description
46
48
  :------------ | :-----------
47
- **Drafting** | Bounded context (sub-module) dealing with executing an asynchronous draft.
48
- **Engine** | Aggregate root responsible for providing an iterable interface capable of executing a draft, pick by pick.
49
- **Event** | Represents one cycle execution result from the Engine.
50
- **External Ruby App** | An example consumer for the Drafting context.
49
+ **Draft** | Bounded context (sub-module) dealing with executing an asynchronous draft.
50
+ **Room** | Aggregate root responsible for providing an iterable interface capable of executing a draft, pick by pick.
51
+ **Event** | Represents one cycle execution result from the Room.
52
+ **External Ruby App** | An example consumer for the Draft context.
51
53
  **Front Office** | Identifiable as a team, contains configuration for how to auto-pick draft selections.
52
54
  **League** | Set of rosters that together form a cohesive league.
53
55
  **Pick Event** | Result event emitted when a player is manually selected.
@@ -57,9 +59,9 @@ Element | Description
57
59
  **Sim Event** | Result event emitted when a player is automatically selected by a front office.
58
60
  **Skip Event** | Result event emitted when a front office decides to skip a round.
59
61
 
60
- #### The Drafting CLI
62
+ #### The Draft CLI
61
63
 
62
- The drafting module's main object: `Basketball::Drafting::Engine` is a stateful iterator. Each time a CLI command is executed, it's results will be re-saved to disk so the output file can then be used as the next command's input file to string together commands.
64
+ The draft module's main object: `Basketball::Draft::Room` is a stateful iterator. Each time a CLI command is executed, it's results will be re-saved to disk so the output file can then be used as the next command's input file to string together commands.
63
65
 
64
66
  ###### Generate a Fresh Draft
65
67
 
@@ -121,11 +123,11 @@ basketball-draft -i tmp/draft.json -a
121
123
  basketball-draft -h
122
124
  ```
123
125
 
124
- ## Scheduling Module
126
+ ## Season Module
125
127
 
126
- The Scheduling module is meant to take a League (conferences/divisions/teams) and turn it into a Calendar. This Calendar creation is atomic - the full calendar will be generated completely all in one call. Here is a cartoon showing the major components:
128
+ The Season module is meant to take a League (conferences/divisions/teams) and turn it into a Calendar. This Calendar creation is atomic - the full calendar will be generated completely all in one call. Here is a cartoon showing the major components:
127
129
 
128
- ![Basketball Architecture - Scheduling](/docs/architecture/scheduling.png)
130
+ ![Basketball Architecture - Season](/docs/architecture/Basketball%20Architecture%20-%20Season.png)
129
131
 
130
132
  Element | Description
131
133
  :------------ | :-----------
@@ -139,57 +141,57 @@ Element | Description
139
141
  **Home Team** | Team object designated as the home team for a Game.
140
142
  **League Serializer** | Understands how to serialize and deserialize a League object.
141
143
  **League** | Describes a league in terms of structure; composed of an array conferences (there can only be 2).
142
- **Scheduling** | Bounded context (sub-module) dealing with matchup and calendar generation.
144
+ **Season** | Bounded context (sub-module) dealing with calendar and matchup generation.
143
145
  **Team** | Identified by an ID and described by a name: represents a basketball team that can be scheduled.
144
146
 
145
- #### The Scheduling CLI
147
+ #### The Season CLI
146
148
 
147
149
  ###### Generate League
148
150
 
149
151
  ```zsh
150
- basketball-schedule -o tmp/league.json
152
+ basketball-season-scheduling -o tmp/league.json
151
153
  ```
152
154
 
153
155
  ###### Generate Calendar From League
154
156
 
155
157
  ```zsh
156
- basketball-schedule -i tmp/league.json -o tmp/calendar.json
158
+ basketball-season-scheduling -i tmp/league.json -o tmp/calendar.json
157
159
  ```
158
160
 
159
161
  ###### Generate Calendar From League For a Specific Year
160
162
 
161
163
  ```zsh
162
- basketball-schedule -i tmp/league.json -o tmp/calendar.json -y 2005
164
+ basketball-season-scheduling -i tmp/league.json -o tmp/calendar.json -y 2005
163
165
  ```
164
166
 
165
167
  ###### Output a Generated Calendar's Matchups
166
168
 
167
169
  ```zsh
168
- basketball-schedule -c tmp/calendar.json
170
+ basketball-season-scheduling -c tmp/calendar.json
169
171
  ```
170
172
 
171
173
  ###### Output a Generated Calendar's Matchups For a Specific Team
172
174
 
173
175
  ```zsh
174
- basketball-schedule -c tmp/calendar.json -t C0-D0-T0
176
+ basketball-season-scheduling -c tmp/calendar.json -t C0-D0-T0
175
177
  ```
176
178
 
177
179
  ###### Output a Generated Calendar's Matchups For a Specific Date
178
180
 
179
181
  ```zsh
180
- basketball-schedule -c tmp/calendar.json -d 2005-02-03
182
+ basketball-season-scheduling -c tmp/calendar.json -d 2005-02-03
181
183
  ```
182
184
 
183
185
  ###### Output a Generated Calendar's Matchups For a Specific Team and Date
184
186
 
185
187
  ```zsh
186
- basketball-schedule -c tmp/calendar.json -d 2005-02-03 -t C0-D0-T0
188
+ basketball-season-scheduling -c tmp/calendar.json -d 2005-02-03 -t C0-D0-T0
187
189
  ```
188
190
 
189
191
  ###### Help Menu
190
192
 
191
193
  ```zsh
192
- basketball-schedule -h
194
+ basketball-season-scheduling -h
193
195
  ```
194
196
 
195
197
  ## Contributing
data/basketball.gemspec CHANGED
@@ -5,7 +5,7 @@ require './lib/basketball/version'
5
5
  Gem::Specification.new do |s|
6
6
  s.name = 'basketball'
7
7
  s.version = Basketball::VERSION
8
- s.summary = 'Basketball League Game Engine'
8
+ s.summary = 'Basketball League Game Room'
9
9
 
10
10
  s.description = <<-DESC
11
11
  This library is meant to serve as the domain for a basketball league/season simulator/turn-based game.
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|
17
17
  s.email = ['mattruggio@icloud.com']
18
18
  s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(.github|bin|docs|spec)/}) }
19
19
  s.bindir = 'exe'
20
- s.executables = %w[basketball-draft basketball-schedule]
20
+ s.executables = %w[basketball-draft basketball-season-scheduling]
21
21
  s.homepage = 'https://github.com/mattruggio/basketball'
22
22
  s.license = 'MIT'
23
23
  s.metadata = {
data/exe/basketball-draft CHANGED
@@ -4,4 +4,4 @@
4
4
  require 'bundler/setup'
5
5
  require 'basketball'
6
6
 
7
- Basketball::Drafting::CLI.new(args: ARGV).invoke!
7
+ Basketball::Draft::CLI.new(args: ARGV).invoke!
@@ -4,4 +4,4 @@
4
4
  require 'bundler/setup'
5
5
  require 'basketball'
6
6
 
7
- Basketball::Scheduling::CLI.new(args: ARGV).invoke!
7
+ Basketball::Season::SchedulingCLI.new(args: ARGV).invoke!
@@ -1,12 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'engine'
4
- require_relative 'engine_serializer'
3
+ require_relative 'room'
4
+ require_relative 'room_serializer'
5
5
  require_relative 'player_search'
6
6
  require_relative 'position'
7
7
 
8
8
  module Basketball
9
- module Drafting
9
+ module Draft
10
10
  # Examples:
11
11
  # exe/basketball-draft -o tmp/draft.json
12
12
  # exe/basketball-draft -i tmp/draft.json -o tmp/draft-wip.json -s 26 -p P-5,P-10 -t 10 -q PG
@@ -23,7 +23,7 @@ module Basketball
23
23
 
24
24
  def initialize(args:, io: $stdout)
25
25
  @io = io
26
- @serializer = EngineSerializer.new
26
+ @serializer = RoomSerializer.new
27
27
  @opts = slop_parse(args)
28
28
 
29
29
  if opts[:input].to_s.empty? && opts[:output].to_s.empty?
@@ -36,31 +36,31 @@ module Basketball
36
36
  end
37
37
 
38
38
  def invoke!
39
- engine = load_engine
39
+ room = load_room
40
40
 
41
- execute(engine)
41
+ execute(room)
42
42
 
43
43
  io.puts
44
44
  io.puts('Status')
45
45
 
46
- if engine.done?
46
+ if room.done?
47
47
  io.puts('Draft is complete!')
48
48
  else
49
- current_round = engine.current_round
50
- current_round_pick = engine.current_round_pick
51
- current_front_office = engine.current_front_office
49
+ current_round = room.current_round
50
+ current_round_pick = room.current_round_pick
51
+ current_front_office = room.current_front_office
52
52
 
53
- io.puts("#{engine.remaining_picks} Remaining pick(s)")
53
+ io.puts("#{room.remaining_picks} Remaining pick(s)")
54
54
  io.puts("Up Next: Round #{current_round} pick #{current_round_pick} for #{current_front_office}")
55
55
  end
56
56
 
57
- write(engine)
57
+ write(room)
58
58
 
59
- log(engine)
59
+ log(room)
60
60
 
61
- league(engine)
61
+ league(room)
62
62
 
63
- query(engine)
63
+ query(room)
64
64
 
65
65
  self
66
66
  end
@@ -72,8 +72,8 @@ module Basketball
72
72
  o.banner = 'Usage: basketball-draft [options] ...'
73
73
 
74
74
  o.string '-i', '--input',
75
- 'Path to load the engine from. If omitted then a new draft will be generated.'
76
- o.string '-o', '--output', 'Path to write the engine to (if omitted then input path will be used)'
75
+ 'Path to load the room from. If omitted then a new draft will be generated.'
76
+ o.string '-o', '--output', 'Path to write the room to (if omitted then input path will be used)'
77
77
  o.integer '-s', '--simulate', 'Number of picks to simulate (default is 0).', default: 0
78
78
  o.bool '-a', '--simulate-all', 'Simulate the rest of the draft', default: false
79
79
  o.array '-p', '--picks', 'Comma-separated list of ordered player IDs to pick.', delimiter: ','
@@ -90,7 +90,7 @@ module Basketball
90
90
  end.to_h
91
91
  end
92
92
 
93
- def load_engine
93
+ def load_room
94
94
  if opts[:input].to_s.empty?
95
95
  io.puts('Input path was not provided, generating fresh front_offices and players')
96
96
 
@@ -119,32 +119,32 @@ module Basketball
119
119
  )
120
120
  end
121
121
 
122
- Engine.new(players:, front_offices:)
122
+ Room.new(players:, front_offices:)
123
123
  end
124
124
 
125
- def league(engine)
125
+ def league(room)
126
126
  return unless opts[:rosters]
127
127
 
128
128
  io.puts
129
- io.puts(engine.to_league)
129
+ io.puts(room.to_league)
130
130
  end
131
131
 
132
- def log(engine)
132
+ def log(room)
133
133
  return unless opts[:log]
134
134
 
135
135
  io.puts
136
136
  io.puts('Event Log')
137
137
 
138
- puts engine.events
138
+ puts room.events
139
139
  end
140
140
 
141
141
  # rubocop:disable Metrics/AbcSize
142
- def query(engine)
142
+ def query(room)
143
143
  top = opts[:top]
144
144
 
145
145
  return if top <= 0
146
146
 
147
- search = PlayerSearch.new(engine.undrafted_players)
147
+ search = PlayerSearch.new(room.undrafted_players)
148
148
  position = opts[:query].to_s.empty? ? nil : Position.new(opts[:query])
149
149
  players = search.query(position:).take(opts[:top])
150
150
 
@@ -167,20 +167,20 @@ module Basketball
167
167
  end
168
168
 
169
169
  # rubocop:disable Metrics/AbcSize
170
- def execute(engine)
170
+ def execute(room)
171
171
  event_count = 0
172
172
 
173
173
  io.puts
174
174
  io.puts('New Events')
175
175
 
176
176
  (opts[:picks] || []).each do |id|
177
- break if engine.done?
177
+ break if room.done?
178
178
 
179
- player = engine.players.find { |p| p.id == id.to_s.upcase }
179
+ player = room.players.find { |p| p.id == id.to_s.upcase }
180
180
 
181
181
  raise PlayerNotFound, "player not found by id: #{id}" unless player
182
182
 
183
- event = engine.pick!(player)
183
+ event = room.pick!(player)
184
184
 
185
185
  io.puts(event)
186
186
 
@@ -188,21 +188,21 @@ module Basketball
188
188
  end
189
189
 
190
190
  opts[:skip].times do
191
- event = engine.skip!
191
+ event = room.skip!
192
192
 
193
193
  io.puts(event)
194
194
 
195
195
  event_count += 1
196
196
  end
197
197
 
198
- engine.sim!(opts[:simulate]) do |event|
198
+ room.sim!(opts[:simulate]) do |event|
199
199
  io.puts(event)
200
200
 
201
201
  event_count += 1
202
202
  end
203
203
 
204
204
  if opts[:simulate_all]
205
- engine.sim! do |event|
205
+ room.sim! do |event|
206
206
  io.puts(event)
207
207
 
208
208
  event_count += 1
@@ -215,10 +215,10 @@ module Basketball
215
215
  end
216
216
  # rubocop:enable Metrics/AbcSize
217
217
 
218
- def write(engine)
218
+ def write(room)
219
219
  output = opts[:output].to_s.empty? ? opts[:input] : opts[:output]
220
220
 
221
- contents = serializer.serialize(engine)
221
+ contents = serializer.serialize(room)
222
222
  out_dir = File.dirname(output)
223
223
 
224
224
  FileUtils.mkdir_p(out_dir)
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Basketball
4
- module Drafting
4
+ module Draft
5
5
  class Event < ValueObject
6
6
  attr_reader_value :pick, :round, :round_pick, :front_office
7
7
 
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Basketball
4
- module Drafting
4
+ module Draft
5
5
  class FrontOffice < Entity
6
6
  MAX_DEPTH = 3
7
7
  MAX_FUZZ = 2
@@ -3,7 +3,7 @@
3
3
  require_relative 'roster'
4
4
 
5
5
  module Basketball
6
- module Drafting
6
+ module Draft
7
7
  class League
8
8
  class RosterNotFoundError < StandardError; end
9
9
  class RosterAlreadyAddedError < StandardError; end
@@ -3,7 +3,7 @@
3
3
  require_relative 'event'
4
4
 
5
5
  module Basketball
6
- module Drafting
6
+ module Draft
7
7
  class PickEvent < Event
8
8
  attr_reader_value :player
9
9
 
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Basketball
4
- module Drafting
4
+ module Draft
5
5
  class Player < Entity
6
6
  STAR_THRESHOLD = 75
7
7
  OVERALL_STAR_INDICATOR = '⭐'
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Basketball
4
- module Drafting
4
+ module Draft
5
5
  class PlayerSearch
6
6
  attr_reader :players
7
7
 
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Basketball
4
- module Drafting
4
+ module Draft
5
5
  class Position < ValueObject
6
6
  extend Forwardable
7
7
 
@@ -3,8 +3,8 @@
3
3
  require_relative 'league'
4
4
 
5
5
  module Basketball
6
- module Drafting
7
- class Engine
6
+ module Draft
7
+ class Room
8
8
  class AlreadyPickedError < StandardError; end
9
9
  class DupeEventError < StandardError; end
10
10
  class EventOutOfOrderError < StandardError; end
@@ -7,8 +7,8 @@ require_relative 'sim_event'
7
7
  require_relative 'skip_event'
8
8
 
9
9
  module Basketball
10
- module Drafting
11
- class EngineSerializer
10
+ module Draft
11
+ class RoomSerializer
12
12
  EVENT_CLASSES = {
13
13
  'PickEvent' => PickEvent,
14
14
  'SimEvent' => SimEvent,
@@ -17,11 +17,11 @@ module Basketball
17
17
 
18
18
  private_constant :EVENT_CLASSES
19
19
 
20
- def to_hash(engine)
20
+ def to_hash(room)
21
21
  {
22
- 'info' => serialize_info(engine),
23
- 'engine' => serialize_engine(engine),
24
- 'league' => serialize_league(engine)
22
+ 'info' => serialize_info(room),
23
+ 'room' => serialize_room(room),
24
+ 'league' => serialize_league(room)
25
25
  }
26
26
  end
27
27
 
@@ -30,15 +30,15 @@ module Basketball
30
30
  players = deserialize_players(json)
31
31
  events = deserialize_events(json, players, front_offices)
32
32
 
33
- engine_opts = {
33
+ room_opts = {
34
34
  players:,
35
35
  front_offices:,
36
36
  events:
37
37
  }
38
38
 
39
- engine_opts[:rounds] = json.dig('engine', 'rounds') if json.dig('engine', 'rounds')
39
+ room_opts[:rounds] = json.dig('room', 'rounds') if json.dig('room', 'rounds')
40
40
 
41
- Engine.new(**engine_opts)
41
+ Room.new(**room_opts)
42
42
  end
43
43
 
44
44
  def deserialize(string)
@@ -47,35 +47,35 @@ module Basketball
47
47
  from_hash(json)
48
48
  end
49
49
 
50
- def serialize(engine)
51
- to_hash(engine).to_json
50
+ def serialize(room)
51
+ to_hash(room).to_json
52
52
  end
53
53
 
54
54
  private
55
55
 
56
- def serialize_engine(engine)
56
+ def serialize_room(room)
57
57
  {
58
- 'rounds' => engine.rounds,
59
- 'front_offices' => serialize_front_offices(engine),
60
- 'players' => serialize_players(engine),
61
- 'events' => serialize_events(engine.events)
58
+ 'rounds' => room.rounds,
59
+ 'front_offices' => serialize_front_offices(room),
60
+ 'players' => serialize_players(room),
61
+ 'events' => serialize_events(room.events)
62
62
  }
63
63
  end
64
64
 
65
- def serialize_info(engine)
65
+ def serialize_info(room)
66
66
  {
67
- 'total_picks' => engine.total_picks,
68
- 'current_round' => engine.current_round,
69
- 'current_round_pick' => engine.current_round_pick,
70
- 'current_front_office' => engine.current_front_office&.id,
71
- 'current_pick' => engine.current_pick,
72
- 'remaining_picks' => engine.remaining_picks,
73
- 'done' => engine.done?
67
+ 'total_picks' => room.total_picks,
68
+ 'current_round' => room.current_round,
69
+ 'current_round_pick' => room.current_round_pick,
70
+ 'current_front_office' => room.current_front_office&.id,
71
+ 'current_pick' => room.current_pick,
72
+ 'remaining_picks' => room.remaining_picks,
73
+ 'done' => room.done?
74
74
  }
75
75
  end
76
76
 
77
- def serialize_league(engine)
78
- league = engine.to_league
77
+ def serialize_league(room)
78
+ league = room.to_league
79
79
 
80
80
  rosters = league.rosters.to_h do |roster|
81
81
  [
@@ -92,8 +92,8 @@ module Basketball
92
92
  }
93
93
  end
94
94
 
95
- def serialize_front_offices(engine)
96
- engine.front_offices.to_h do |front_office|
95
+ def serialize_front_offices(room)
96
+ room.front_offices.to_h do |front_office|
97
97
  [
98
98
  front_office.id,
99
99
  {
@@ -106,8 +106,8 @@ module Basketball
106
106
  end
107
107
  end
108
108
 
109
- def serialize_players(engine)
110
- engine.players.to_h do |player|
109
+ def serialize_players(room)
110
+ room.players.to_h do |player|
111
111
  [
112
112
  player.id,
113
113
  {
@@ -135,7 +135,7 @@ module Basketball
135
135
  end
136
136
 
137
137
  def deserialize_front_offices(json)
138
- (json.dig('engine', 'front_offices') || []).map do |id, front_office_hash|
138
+ (json.dig('room', 'front_offices') || []).map do |id, front_office_hash|
139
139
  prioritized_positions = (front_office_hash['prioritized_positions'] || []).map do |v|
140
140
  Position.new(v)
141
141
  end
@@ -153,7 +153,7 @@ module Basketball
153
153
  end
154
154
 
155
155
  def deserialize_players(json)
156
- (json.dig('engine', 'players') || []).map do |id, player_hash|
156
+ (json.dig('room', 'players') || []).map do |id, player_hash|
157
157
  player_opts = {
158
158
  id:,
159
159
  first_name: player_hash['first_name'],
@@ -167,7 +167,7 @@ module Basketball
167
167
  end
168
168
 
169
169
  def deserialize_events(json, players, front_offices)
170
- (json.dig('engine', 'events') || []).map do |event_hash|
170
+ (json.dig('room', 'events') || []).map do |event_hash|
171
171
  event_opts = event_hash.slice('pick', 'round', 'round_pick').merge(
172
172
  front_office: front_offices.find { |t| t.id == event_hash['front_office'] }
173
173
  )
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Basketball
4
- module Drafting
4
+ module Draft
5
5
  class Roster < Entity
6
6
  class PlayerRequiredError < StandardError; end
7
7
 
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Basketball
4
- module Drafting
4
+ module Draft
5
5
  class SimEvent < Event
6
6
  attr_reader_value :player
7
7
 
@@ -3,7 +3,7 @@
3
3
  require_relative 'event'
4
4
 
5
5
  module Basketball
6
- module Drafting
6
+ module Draft
7
7
  class SkipEvent < Event
8
8
  def to_s
9
9
  "skipped #{super}"
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'drafting/cli'
3
+ require_relative 'draft/cli'
4
4
 
5
5
  module Basketball
6
- module Drafting
6
+ module Draft
7
7
  class PlayerAlreadyRegisteredError < StandardError; end
8
8
  end
9
9
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Basketball
4
- module Scheduling
4
+ module Season
5
5
  class Calendar < ValueObject
6
6
  class TeamAlreadyBookedError < StandardError; end
7
7
  class InvalidGameOrderError < StandardError; end
@@ -5,7 +5,7 @@ require_relative 'preseason_game'
5
5
  require_relative 'season_game'
6
6
 
7
7
  module Basketball
8
- module Scheduling
8
+ module Season
9
9
  class CalendarSerializer
10
10
  GAME_CLASSES = {
11
11
  'PreseasonGame' => PreseasonGame,
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Basketball
4
- module Scheduling
4
+ module Season
5
5
  class Conference < Entity
6
6
  DIVISIONS_SIZE = 3
7
7
 
@@ -3,12 +3,12 @@
3
3
  require_relative 'calendar'
4
4
 
5
5
  module Basketball
6
- module Scheduling
6
+ module Season
7
7
  # This is the service class responsible for actually picking out free dates ane pairing up teams to
8
8
  # play each other. This is a reasonable naive first pass at some underlying match-making algorithms
9
9
  # but could definitely use some help with the complexity/runtime/etc.
10
10
  class Coordinator
11
- MIN_PRESEASON_GAMES_PER_TEAM = 4
11
+ MIN_PRESEASON_GAMES_PER_TEAM = 3
12
12
  MAX_PRESEASON_GAMES_PER_TEAM = 6
13
13
 
14
14
  private_constant :MIN_PRESEASON_GAMES_PER_TEAM,
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Basketball
4
- module Scheduling
4
+ module Season
5
5
  class Division < Entity
6
6
  TEAMS_SIZE = 5
7
7
 
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Basketball
4
- module Scheduling
4
+ module Season
5
5
  class Game < ValueObject
6
6
  attr_reader_value :date, :home_team, :away_team
7
7
 
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Basketball
4
- module Scheduling
4
+ module Season
5
5
  class League
6
6
  class UnknownTeamError < StandardError; end
7
7
 
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Basketball
4
- module Scheduling
4
+ module Season
5
5
  class LeagueSerializer
6
6
  def to_hash(league)
7
7
  {
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Basketball
4
- module Scheduling
4
+ module Season
5
5
  class PreseasonGame < Game
6
6
  def to_s
7
7
  "#{super} (preseason)"
@@ -9,16 +9,16 @@ require_relative 'league_serializer'
9
9
  require_relative 'team'
10
10
 
11
11
  module Basketball
12
- module Scheduling
12
+ module Season
13
13
  # Examples:
14
- # exe/basketball-schedule -o tmp/league.json
15
- # exe/basketball-schedule -i tmp/league.json -o tmp/calendar.json
16
- # exe/basketball-schedule -i tmp/league.json -o tmp/calendar.json -y 2005
17
- # exe/basketball-schedule -c tmp/calendar.json
18
- # exe/basketball-schedule -c tmp/calendar.json -t C0-D0-T0
19
- # exe/basketball-schedule -c tmp/calendar.json -d 2005-02-03
20
- # exe/basketball-schedule -c tmp/calendar.json -d 2005-02-03 -t C0-D0-T0
21
- class CLI
14
+ # exe/basketball-season-scheduling -o tmp/league.json
15
+ # exe/basketball-season-scheduling -i tmp/league.json -o tmp/calendar.json
16
+ # exe/basketball-season-scheduling -i tmp/league.json -o tmp/calendar.json -y 2005
17
+ # exe/basketball-season-scheduling -c tmp/calendar.json
18
+ # exe/basketball-season-scheduling -c tmp/calendar.json -t C0-D0-T0
19
+ # exe/basketball-season-scheduling -c tmp/calendar.json -d 2005-02-03
20
+ # exe/basketball-season-scheduling -c tmp/calendar.json -d 2005-02-03 -t C0-D0-T0
21
+ class SchedulingCLI
22
22
  attr_reader :opts,
23
23
  :league_serializer,
24
24
  :calendar_serializer,
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Basketball
4
- module Scheduling
4
+ module Season
5
5
  class SeasonGame < Game
6
6
  end
7
7
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Basketball
4
- module Scheduling
4
+ module Season
5
5
  class Team < Entity
6
6
  attr_reader :name
7
7
 
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'scheduling/cli'
3
+ require_relative 'season/scheduling_cli'
4
4
 
5
5
  module Basketball
6
- module Scheduling
6
+ module Season
7
7
  class ConferenceAlreadyRegisteredError < StandardError; end
8
8
  class DivisionAlreadyRegisteredError < StandardError; end
9
9
  class TeamAlreadyRegisteredError < StandardError; end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Basketball
4
- VERSION = '0.0.7'
4
+ VERSION = '0.0.8'
5
5
  end
data/lib/basketball.rb CHANGED
@@ -12,5 +12,5 @@ require_relative 'basketball/entity'
12
12
  require_relative 'basketball/value_object'
13
13
 
14
14
  # Submodules
15
- require_relative 'basketball/drafting'
16
- require_relative 'basketball/scheduling'
15
+ require_relative 'basketball/draft'
16
+ require_relative 'basketball/season'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: basketball
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Ruggio
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-05-14 00:00:00.000000000 Z
11
+ date: 2023-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faker
@@ -46,7 +46,7 @@ email:
46
46
  - mattruggio@icloud.com
47
47
  executables:
48
48
  - basketball-draft
49
- - basketball-schedule
49
+ - basketball-season-scheduling
50
50
  extensions: []
51
51
  extra_rdoc_files: []
52
52
  files:
@@ -63,36 +63,36 @@ files:
63
63
  - Rakefile
64
64
  - basketball.gemspec
65
65
  - exe/basketball-draft
66
- - exe/basketball-schedule
66
+ - exe/basketball-season-scheduling
67
67
  - lib/basketball.rb
68
- - lib/basketball/drafting.rb
69
- - lib/basketball/drafting/cli.rb
70
- - lib/basketball/drafting/engine.rb
71
- - lib/basketball/drafting/engine_serializer.rb
72
- - lib/basketball/drafting/event.rb
73
- - lib/basketball/drafting/front_office.rb
74
- - lib/basketball/drafting/league.rb
75
- - lib/basketball/drafting/pick_event.rb
76
- - lib/basketball/drafting/player.rb
77
- - lib/basketball/drafting/player_search.rb
78
- - lib/basketball/drafting/position.rb
79
- - lib/basketball/drafting/roster.rb
80
- - lib/basketball/drafting/sim_event.rb
81
- - lib/basketball/drafting/skip_event.rb
68
+ - lib/basketball/draft.rb
69
+ - lib/basketball/draft/cli.rb
70
+ - lib/basketball/draft/event.rb
71
+ - lib/basketball/draft/front_office.rb
72
+ - lib/basketball/draft/league.rb
73
+ - lib/basketball/draft/pick_event.rb
74
+ - lib/basketball/draft/player.rb
75
+ - lib/basketball/draft/player_search.rb
76
+ - lib/basketball/draft/position.rb
77
+ - lib/basketball/draft/room.rb
78
+ - lib/basketball/draft/room_serializer.rb
79
+ - lib/basketball/draft/roster.rb
80
+ - lib/basketball/draft/sim_event.rb
81
+ - lib/basketball/draft/skip_event.rb
82
82
  - lib/basketball/entity.rb
83
- - lib/basketball/scheduling.rb
84
- - lib/basketball/scheduling/calendar.rb
85
- - lib/basketball/scheduling/calendar_serializer.rb
86
- - lib/basketball/scheduling/cli.rb
87
- - lib/basketball/scheduling/conference.rb
88
- - lib/basketball/scheduling/coordinator.rb
89
- - lib/basketball/scheduling/division.rb
90
- - lib/basketball/scheduling/game.rb
91
- - lib/basketball/scheduling/league.rb
92
- - lib/basketball/scheduling/league_serializer.rb
93
- - lib/basketball/scheduling/preseason_game.rb
94
- - lib/basketball/scheduling/season_game.rb
95
- - lib/basketball/scheduling/team.rb
83
+ - lib/basketball/season.rb
84
+ - lib/basketball/season/calendar.rb
85
+ - lib/basketball/season/calendar_serializer.rb
86
+ - lib/basketball/season/conference.rb
87
+ - lib/basketball/season/coordinator.rb
88
+ - lib/basketball/season/division.rb
89
+ - lib/basketball/season/game.rb
90
+ - lib/basketball/season/league.rb
91
+ - lib/basketball/season/league_serializer.rb
92
+ - lib/basketball/season/preseason_game.rb
93
+ - lib/basketball/season/scheduling_cli.rb
94
+ - lib/basketball/season/season_game.rb
95
+ - lib/basketball/season/team.rb
96
96
  - lib/basketball/value_object.rb
97
97
  - lib/basketball/version.rb
98
98
  homepage: https://github.com/mattruggio/basketball
@@ -123,5 +123,5 @@ requirements: []
123
123
  rubygems_version: 3.4.6
124
124
  signing_key:
125
125
  specification_version: 4
126
- summary: Basketball League Game Engine
126
+ summary: Basketball League Game Room
127
127
  test_files: []