basketball 0.0.22 → 0.0.23

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3a6709626d10c4b4c46fce577ec25ea57f28f89a12a40799bd625666d9c6a3b5
4
- data.tar.gz: ac30e12cb15484913ba3b58c0e96f130575a08111d572b87b77e490727c7a528
3
+ metadata.gz: e72d5e9ae7173e7906499f251db75f25d65ead4cf7cf6a8171f615a7821ba2fb
4
+ data.tar.gz: 744511e1ce1b8dce785cc3dfbf18cb8e5e1e355c9686226b03703ccaddc29468
5
5
  SHA512:
6
- metadata.gz: f2fd8e0024222767369b33abf749ba8b41d6320d181bc6e20144007bf1a6aedf6d67f42f0d6ce29fd995387b9540eed9c8c8ec6232809a35c56099389b33cada
7
- data.tar.gz: de054db63b667f81a118b2e917894bdb7667bc64801959529c74b9da2d19afc78889a3efa8ee95f68d098880fc82f449fd661a33f2eca668bcfe656b839a40ef
6
+ metadata.gz: '0868c8152e6e0c1e52554b0546d289678c23fd73a3b855c42b9fe48982ee2decfe9d6b6433b72632909bdee64debb16169288fc423f5f16368d98a90b85f33bd'
7
+ data.tar.gz: eb0e17d0273548cffbf3dde7b96dda4655461939997723619e5be125fd56ebe24d0ec6ce7c82edfefa76d529e022dafb2b703b533e9553b9a867e3ae9bf1aef8
data/README.md CHANGED
@@ -25,7 +25,6 @@ Element | Description
25
25
  **Game** | Matches up a date with two teams (home and away) to represent a coordinatord match-up.
26
26
  **League** | Describes a league in terms of structure composed of conferences, divisions, teams, and players.
27
27
  **Match** | When the Coordinator needs an Arena instance to select a game winner, it will send the Arena a Match. A match is Game but also includes the active roster (players) for both teams that will participate in the game.
28
- **Org** | Bounded context (sub-module) dealing with overall organizational structure of a sports assocation.
29
28
  **Pick** | Result event emitted when a player is automatically or manually selected.
30
29
  **Player** | Identitiable as a person able to be drafted. Meant to be subclassed and extended to include more intricate descriptions of a specific sport player, such as abilities, ratings, and statistics. Right now it has none of these types of traits and it meant to only serve as the base with only an overall attribute.
31
30
  **Record** | Represents a team's overall record.
@@ -57,26 +56,21 @@ bundle add basketball
57
56
 
58
57
  ### Draft Module
59
58
 
60
- The input for the main object `Basketball::Draft::Room` is an array of teams (`Basketball::Draft::FrontOffice`) and players (`Basketball::Org::Players`). Once instantiated there are four main methods:
59
+ The input for the main object `Basketball::Draft::Room` is an array of teams (`Basketball::Draft::FrontOffice`) and players (`Basketball::Draft::Players`). Once instantiated there are four main methods:
61
60
 
62
61
  * **Basketball::Draft::Room#sim!**: Simulate the next pick.
63
62
  * **Basketball::Draft::Room#skip!**: Skip the next pick.
64
63
  * **Basketball::Draft::Room#pick!(player)**: Pick an exact player for the current front office.
65
64
  * **Basketball::Draft::Room#sim_rest!**: Simulate the rest of the picks.
66
65
 
67
- ### Org Module
68
-
69
- The Org module contains all the structural and transactional for the basketball league as a whole. A League can be made up of free agents and conferences, conferences can have divisions, divisions can have teams, and teams can have players. The main object: `Basketball::Org::League` allows for the control through its API:
70
-
71
- * **Basketball::Org::League#sign!**: Sign a player to a team.
72
- * **Basketball::Org::League#release!**: Release a player from a team and place them in the free agent pool.
73
-
74
66
  ### Season Module
75
67
 
76
- The Season module knows how to execute a calendar of games for a League and generate results. The main object is the `Basketball::Season::Coordinator` class. Once instantiated there are four main methods:
68
+ The Season module knows how to execute a calendar of games for a League and generate results. The main object is the `Basketball::Season::Coordinator` class. Once instantiated the main methods are:
77
69
 
78
- * **Basketball::Season::Coordinator#sim!**: Simulate the next day of games.
70
+ * **Basketball::Season::Coordinator#release!**: Release a player from a team and place them in the free agent pool.
71
+ * **Basketball::Season::Coordinator#sign!**: Sign a player to a team.
79
72
  * **Basketball::Season::Coordinator#sim_rest!**: Simulate the rest of the games.
73
+ * **Basketball::Season::Coordinator#sim!**: Simulate the next day of games.
80
74
 
81
75
  ## Contributing
82
76
 
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Basketball
4
- module Org
4
+ module Common
5
5
  # Base class describing a player.
6
6
  # A consumer application should extend these specific to their specific sports traits.
7
7
  class Player < Entity
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Basketball
4
- module Org
4
+ module Common
5
5
  # Describes a player position.
6
6
  class Position < ValueObject
7
7
  extend Forwardable
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'common/player'
4
+ require_relative 'common/position'
@@ -52,6 +52,10 @@ module Basketball
52
52
 
53
53
  private
54
54
 
55
+ def top_players(assessment)
56
+ scout.top_for(players: assessment.undrafted_players)
57
+ end
58
+
55
59
  def adaptive_search(assessment)
56
60
  drafted_positions = assessment.drafted_players.map(&:position)
57
61
 
@@ -69,15 +73,15 @@ module Basketball
69
73
  break if players.any?
70
74
  end
71
75
 
72
- players = players.any? ? players : scout.top_for
76
+ players
73
77
  end
74
78
 
75
79
  def all_random_positions
76
- Org::Position::ALL_VALUES.to_a.shuffle.map { |v| Org::Position.new(v) }
80
+ Position::ALL_VALUES.to_a.shuffle.map { |v| Position.new(v) }
77
81
  end
78
82
 
79
83
  def random_positions_queue
80
- all_random_positions + all_random_positions + [Org::Position.random] + [Org::Position.random]
84
+ all_random_positions + all_random_positions + [Position.random] + [Position.random]
81
85
  end
82
86
 
83
87
  def available_prioritized_positions(drafted_players)
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Basketball
4
+ module Draft
5
+ # Defines a player currently in the draft.
6
+ class Player < Common::Player; end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Basketball
4
+ module Draft
5
+ # Defines a position a player can hold.
6
+ class Position < Common::Position; end
7
+ end
8
+ end
@@ -32,19 +32,6 @@ module Basketball
32
32
  events.each { |event| add_event!(event) }
33
33
  end
34
34
 
35
- # This method will return a materialized list of teams and their selections.
36
- def teams
37
- front_offices.each_with_object([]) do |front_office, memo|
38
- team = Org::Team.new(id: front_office.id)
39
-
40
- drafted_players(front_office).each do |player|
41
- team.sign!(player)
42
- end
43
-
44
- memo << team
45
- end
46
- end
47
-
48
35
  ### Peek Methods
49
36
 
50
37
  def assessment
@@ -188,12 +175,12 @@ module Basketball
188
175
  add_event!(event)
189
176
  end
190
177
 
191
- private
192
-
193
178
  def player_events
194
179
  events.select { |e| e.respond_to?(:player) }
195
180
  end
196
181
 
182
+ private
183
+
197
184
  # rubocop:disable Metrics/AbcSize
198
185
  def add_event!(event)
199
186
  raise EndOfDraftError, "#{total_picks} pick limit reached" if done?
@@ -7,6 +7,8 @@ require_relative 'draft/scout'
7
7
  require_relative 'draft/assessment'
8
8
  require_relative 'draft/event'
9
9
  require_relative 'draft/front_office'
10
+ require_relative 'draft/player'
11
+ require_relative 'draft/position'
10
12
 
11
13
  # Event Subclasses
12
14
  require_relative 'draft/pick'
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Basketball
4
- module Org
4
+ module Season
5
5
  # A collection of divisions, teams, and players.
6
6
  class Conference < Entity
7
7
  include HasDivisions
@@ -50,6 +50,14 @@ module Basketball
50
50
  assert_all_known_teams
51
51
  end
52
52
 
53
+ def release!(player)
54
+ tap { league.release!(player) }
55
+ end
56
+
57
+ def sign!(player:, team:)
58
+ tap { league.sign!(player:, team:) }
59
+ end
60
+
53
61
  def sim_rest!(&)
54
62
  events = []
55
63
 
@@ -62,16 +70,6 @@ module Basketball
62
70
  events
63
71
  end
64
72
 
65
- def assert_current_date
66
- if current_date < exhibition_start_date
67
- raise OutOfBoundsError, "current date #{current_date} should be on or after #{exhibition_start_date}"
68
- end
69
-
70
- return unless current_date > regular_end_date
71
-
72
- raise OutOfBoundsError, "current date #{current_date} should be on or after #{exhibition_start_date}"
73
- end
74
-
75
73
  def sim!
76
74
  raise ArgumentError, 'league is required' unless league
77
75
 
@@ -160,6 +158,16 @@ module Basketball
160
158
 
161
159
  attr_writer :arena
162
160
 
161
+ def assert_current_date
162
+ if current_date < exhibition_start_date
163
+ raise OutOfBoundsError, "current date #{current_date} should be on or after #{exhibition_start_date}"
164
+ end
165
+
166
+ return unless current_date > regular_end_date
167
+
168
+ raise OutOfBoundsError, "current date #{current_date} should be on or after #{exhibition_start_date}"
169
+ end
170
+
163
171
  def opponent_team(opponent)
164
172
  league.teams.find { |t| t == opponent }
165
173
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Basketball
4
- module Org
4
+ module Season
5
5
  # A collection of teams and players.
6
6
  class Division < Entity
7
7
  include HasTeams
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Basketball
4
- module Org
4
+ module Season
5
5
  # Helper methods for objects that can be composed of divisions which are also composed of teams
6
6
  # and players.
7
7
  module HasDivisions
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Basketball
4
- module Org
4
+ module Season
5
5
  # Helper methods for objects that can be composed of players.
6
6
  module HasPlayers
7
7
  def player?(player)
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Basketball
4
- module Org
4
+ module Season
5
5
  # Helper methods for objects that can be composed of teams which are also made up of players.
6
6
  module HasTeams
7
7
  include HasPlayers
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Basketball
4
- module Org
4
+ module Season
5
5
  # Describes a collection of conferences, divisions, teams, and players.
6
6
  # Holds the rules which support adding teams and players to ensure the all the
7
7
  # teams are cohesive, such as:
@@ -52,9 +52,12 @@ module Basketball
52
52
 
53
53
  raise NotSignedError, 'player was not found to be signed by any team' unless team
54
54
 
55
- team.release!(player)
55
+ # We will use player as a comparable object but we will keep the same
56
+ # player instance already in the league's object graph instead of replacing it
57
+ # with the passed in instance.
58
+ actual_player = team.release!(player)
56
59
 
57
- free_agents << player
60
+ free_agents << actual_player
58
61
 
59
62
  self
60
63
  end
@@ -75,11 +78,11 @@ module Basketball
75
78
 
76
79
  # If this player was a free agent then make sure we remove them from the free agent pool.
77
80
  # It is OK if they weren't, they can still be directly signed.
78
- free_agents.delete(player) if free_agent?(player)
81
+ actual_player = free_agent?(player) ? free_agents.delete(player) : player
79
82
 
80
83
  # It is OK to pass in a detached team as long as its equivalent resides in this
81
84
  # League's object graph.
82
- team_for(team.id).sign!(player)
85
+ team_for(team.id).sign!(actual_player)
83
86
 
84
87
  self
85
88
  end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Basketball
4
+ module Season
5
+ # A player in context of a Season.
6
+ class Player < Common::Player; end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Basketball
4
+ module Season
5
+ # Describes a player position in context of a Season.
6
+ class Position < Common::Position; end
7
+ end
8
+ end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Basketball
4
- module Org
4
+ module Season
5
5
  # Base class describing a team. A team here is bare metal and is just described by an ID
6
6
  # and a collection of Player objects.
7
7
  class Team < Entity
@@ -35,9 +35,8 @@ module Basketball
35
35
  raise ArgumentError, 'player is required' unless player
36
36
  raise PlayerNotSignedError, "#{player} id not signed by #{self}" unless signed?(player)
37
37
 
38
+ # Returns deleted player
38
39
  players.delete(player)
39
-
40
- self
41
40
  end
42
41
 
43
42
  def sign!(player)
@@ -3,10 +3,23 @@
3
3
  # Common
4
4
  require_relative 'season/arena'
5
5
  require_relative 'season/calendar'
6
- require_relative 'season/result'
7
6
  require_relative 'season/game'
8
7
  require_relative 'season/matchup'
9
8
  require_relative 'season/opponent'
9
+ require_relative 'season/result'
10
+
11
+ # League Common
12
+ require_relative 'season/has_players'
13
+ require_relative 'season/has_teams' # uses has_players
14
+ require_relative 'season/has_divisions' # uses has_teams
15
+
16
+ # League Object Graph
17
+ require_relative 'season/conference'
18
+ require_relative 'season/division'
19
+ require_relative 'season/league'
20
+ require_relative 'season/player'
21
+ require_relative 'season/position'
22
+ require_relative 'season/team'
10
23
 
11
24
  # Game Subclasses
12
25
  require_relative 'season/exhibition'
@@ -20,3 +33,12 @@ require_relative 'season/standings'
20
33
  # Specific
21
34
  require_relative 'season/coordinator'
22
35
  require_relative 'season/scheduler'
36
+
37
+ module Basketball
38
+ module Season
39
+ class DivisionAlreadyRegisteredError < StandardError; end
40
+ class PlayerAlreadySignedError < StandardError; end
41
+ class TeamAlreadyRegisteredError < StandardError; end
42
+ class UnregisteredTeamError < StandardError; end
43
+ end
44
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Basketball
4
- VERSION = '0.0.22'
4
+ VERSION = '0.0.23'
5
5
  end
data/lib/basketball.rb CHANGED
@@ -5,13 +5,13 @@ require 'fileutils'
5
5
  require 'forwardable'
6
6
  require 'json'
7
7
 
8
- # Generic
8
+ # Foundational Domain Building Blocks
9
9
  require_relative 'basketball/entity'
10
10
  require_relative 'basketball/value_object'
11
11
 
12
- # Dependent on Generic
13
- require_relative 'basketball/org'
12
+ # Common (be careful!)
13
+ require_relative 'basketball/common'
14
14
 
15
- # Dependent on Org
15
+ # Bounded Contexts
16
16
  require_relative 'basketball/draft'
17
17
  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.22
4
+ version: 0.0.23
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-06-17 00:00:00.000000000 Z
11
+ date: 2023-06-24 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: " This library is meant to serve as the domain for a basketball league/season
14
14
  simulator/turn-based game. It models core ideas such as: players, general managers,
@@ -33,39 +33,43 @@ files:
33
33
  - Rakefile
34
34
  - basketball.gemspec
35
35
  - lib/basketball.rb
36
+ - lib/basketball/common.rb
37
+ - lib/basketball/common/player.rb
38
+ - lib/basketball/common/position.rb
36
39
  - lib/basketball/draft.rb
37
40
  - lib/basketball/draft/assessment.rb
38
41
  - lib/basketball/draft/event.rb
39
42
  - lib/basketball/draft/front_office.rb
40
43
  - lib/basketball/draft/pick.rb
44
+ - lib/basketball/draft/player.rb
45
+ - lib/basketball/draft/position.rb
41
46
  - lib/basketball/draft/room.rb
42
47
  - lib/basketball/draft/scout.rb
43
48
  - lib/basketball/draft/skip.rb
44
49
  - lib/basketball/entity.rb
45
- - lib/basketball/org.rb
46
- - lib/basketball/org/conference.rb
47
- - lib/basketball/org/division.rb
48
- - lib/basketball/org/has_divisions.rb
49
- - lib/basketball/org/has_players.rb
50
- - lib/basketball/org/has_teams.rb
51
- - lib/basketball/org/league.rb
52
- - lib/basketball/org/player.rb
53
- - lib/basketball/org/position.rb
54
- - lib/basketball/org/team.rb
55
50
  - lib/basketball/season.rb
56
51
  - lib/basketball/season/arena.rb
57
52
  - lib/basketball/season/calendar.rb
53
+ - lib/basketball/season/conference.rb
58
54
  - lib/basketball/season/coordinator.rb
59
55
  - lib/basketball/season/detail.rb
56
+ - lib/basketball/season/division.rb
60
57
  - lib/basketball/season/exhibition.rb
61
58
  - lib/basketball/season/game.rb
59
+ - lib/basketball/season/has_divisions.rb
60
+ - lib/basketball/season/has_players.rb
61
+ - lib/basketball/season/has_teams.rb
62
+ - lib/basketball/season/league.rb
62
63
  - lib/basketball/season/matchup.rb
63
64
  - lib/basketball/season/opponent.rb
65
+ - lib/basketball/season/player.rb
66
+ - lib/basketball/season/position.rb
64
67
  - lib/basketball/season/record.rb
65
68
  - lib/basketball/season/regular.rb
66
69
  - lib/basketball/season/result.rb
67
70
  - lib/basketball/season/scheduler.rb
68
71
  - lib/basketball/season/standings.rb
72
+ - lib/basketball/season/team.rb
69
73
  - lib/basketball/value_object.rb
70
74
  - lib/basketball/value_object_dsl.rb
71
75
  - lib/basketball/version.rb
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Cross-cutting Concerns
4
- require_relative 'org/has_players'
5
- require_relative 'org/has_teams'
6
- require_relative 'org/has_divisions'
7
-
8
- # Domain Models
9
- require_relative 'org/conference'
10
- require_relative 'org/division'
11
- require_relative 'org/league'
12
- require_relative 'org/player'
13
- require_relative 'org/position'
14
- require_relative 'org/team'
15
-
16
- module Basketball
17
- module Org
18
- class DivisionAlreadyRegisteredError < StandardError; end
19
- class PlayerAlreadySignedError < StandardError; end
20
- class TeamAlreadyRegisteredError < StandardError; end
21
- class UnregisteredTeamError < StandardError; end
22
- end
23
- end