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 +4 -4
- data/README.md +5 -11
- data/lib/basketball/{org → common}/player.rb +1 -1
- data/lib/basketball/{org → common}/position.rb +1 -1
- data/lib/basketball/common.rb +4 -0
- data/lib/basketball/draft/front_office.rb +7 -3
- data/lib/basketball/draft/player.rb +8 -0
- data/lib/basketball/draft/position.rb +8 -0
- data/lib/basketball/draft/room.rb +2 -15
- data/lib/basketball/draft.rb +2 -0
- data/lib/basketball/{org → season}/conference.rb +1 -1
- data/lib/basketball/season/coordinator.rb +18 -10
- data/lib/basketball/{org → season}/division.rb +1 -1
- data/lib/basketball/{org → season}/has_divisions.rb +1 -1
- data/lib/basketball/{org → season}/has_players.rb +1 -1
- data/lib/basketball/{org → season}/has_teams.rb +1 -1
- data/lib/basketball/{org → season}/league.rb +8 -5
- data/lib/basketball/season/player.rb +8 -0
- data/lib/basketball/season/position.rb +8 -0
- data/lib/basketball/{org → season}/team.rb +2 -3
- data/lib/basketball/season.rb +23 -1
- data/lib/basketball/version.rb +1 -1
- data/lib/basketball.rb +4 -4
- metadata +16 -12
- data/lib/basketball/org.rb +0 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e72d5e9ae7173e7906499f251db75f25d65ead4cf7cf6a8171f615a7821ba2fb
|
4
|
+
data.tar.gz: 744511e1ce1b8dce785cc3dfbf18cb8e5e1e355c9686226b03703ccaddc29468
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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::
|
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
|
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#
|
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
|
|
@@ -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
|
76
|
+
players
|
73
77
|
end
|
74
78
|
|
75
79
|
def all_random_positions
|
76
|
-
|
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 + [
|
84
|
+
all_random_positions + all_random_positions + [Position.random] + [Position.random]
|
81
85
|
end
|
82
86
|
|
83
87
|
def available_prioritized_positions(drafted_players)
|
@@ -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?
|
data/lib/basketball/draft.rb
CHANGED
@@ -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'
|
@@ -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
|
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
|
-
|
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 <<
|
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)
|
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!(
|
85
|
+
team_for(team.id).sign!(actual_player)
|
83
86
|
|
84
87
|
self
|
85
88
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Basketball
|
4
|
-
module
|
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)
|
data/lib/basketball/season.rb
CHANGED
@@ -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
|
data/lib/basketball/version.rb
CHANGED
data/lib/basketball.rb
CHANGED
@@ -5,13 +5,13 @@ require 'fileutils'
|
|
5
5
|
require 'forwardable'
|
6
6
|
require 'json'
|
7
7
|
|
8
|
-
#
|
8
|
+
# Foundational Domain Building Blocks
|
9
9
|
require_relative 'basketball/entity'
|
10
10
|
require_relative 'basketball/value_object'
|
11
11
|
|
12
|
-
#
|
13
|
-
require_relative 'basketball/
|
12
|
+
# Common (be careful!)
|
13
|
+
require_relative 'basketball/common'
|
14
14
|
|
15
|
-
#
|
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.
|
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-
|
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
|
data/lib/basketball/org.rb
DELETED
@@ -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
|