acpc_poker_types 3.1.0 → 3.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 360776ad7098c8fdb25bb82e62ada4ae80ae65ae
4
- data.tar.gz: 8fb88c8dad1c962c95aca4926cb927b53d4570cc
3
+ metadata.gz: 1ac1edc74df20ff22ce321770a24c508acf29ad2
4
+ data.tar.gz: 7efe0248ddd843e586d9941af349282f3e001672
5
5
  SHA512:
6
- metadata.gz: 31d5a12377b31af437d306e48735a66131beb7f4b435ad874e37cbf539a10a722e273ca50aacf22774d470b5b0dc994120d0157417688c1510dfa778643ca35a
7
- data.tar.gz: 12516ae9be8561af5b8bbcdab9a36119756008f5af961530edbd6ed85336c52a39b51d646051913bea96fe86e4359194b09ab8d0d4f349ad1af15f3175a7999f
6
+ metadata.gz: d50024fe199e9e81ab4200b59937c83e0f24f3864265e1727632d493a865cd7880877e7892137d3e835798f024093e41734306790f9e02282f2fa40445493cfb
7
+ data.tar.gz: fbac09f6a3e5370e2bb96b9634de30d80b84877acf41b9f9a627f7ba1da5068d6388f0034633fc47043c3b9b263e755203ff5c37b6f5b0502d03a024957f7000
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
10
10
  s.summary = %q{ACPC Poker Types}
11
11
  s.description = %q{Poker classes and constants that conform to the standards of the Annual Computer Poker Competition.}
12
12
 
13
- s.add_dependency 'dmorrill10-utils', '~> 1.0'
13
+ s.add_dependency 'process_runner', '~> 0.0'
14
14
  s.add_dependency 'acpc_dealer', '~> 1.0'
15
15
  s.add_dependency 'celluloid', '~> 0.14'
16
16
  s.add_dependency 'contextual_exceptions', '~> 0.0'
@@ -11,6 +11,7 @@ require "acpc_poker_types/player"
11
11
  require "acpc_poker_types/rank"
12
12
  require "acpc_poker_types/suit"
13
13
  require "acpc_poker_types/acpc_dealer_data"
14
+ require 'acpc_poker_types/integer_as_seat'
14
15
 
15
16
  module AcpcPokerTypes
16
17
  end
@@ -1,4 +1,3 @@
1
-
2
1
  require 'acpc_poker_types/match_state'
3
2
  require 'acpc_poker_types/poker_action'
4
3
 
@@ -93,7 +92,7 @@ module AcpcPokerTypes::AcpcDealerData
93
92
  end
94
93
  end
95
94
 
96
- alias_new :parse
95
+ class << self; alias_method(:parse, :new) end
97
96
 
98
97
  def initialize(
99
98
  acpc_log_statements,
@@ -111,13 +110,14 @@ module AcpcPokerTypes::AcpcDealerData
111
110
  if parsed_message
112
111
  if (
113
112
  accumulating_data.empty? ||
114
- accumulating_data.last.first[:state].hand_number != parsed_message[:state].hand_number
113
+ (
114
+ accumulating_data.last.first[:state].hand_number !=
115
+ parsed_message[:state].hand_number
116
+ )
115
117
  )
116
118
  break accumulating_data if accumulating_data.length == num_hands
117
-
118
119
  accumulating_data << []
119
120
  end
120
-
121
121
  accumulating_data.last << parsed_message
122
122
  else
123
123
  @final_score = AcpcPokerTypes::AcpcDealerData::ActionMessages.parse_score(log_line) unless @final_score
@@ -1,5 +1,3 @@
1
- require 'dmorrill10-utils/class' # For alias_new
2
-
3
1
  require 'acpc_poker_types/acpc_dealer_data/match_definition'
4
2
  require 'acpc_poker_types/acpc_dealer_data/log_file'
5
3
 
@@ -52,7 +50,7 @@ module AcpcPokerTypes::AcpcDealerData
52
50
  end
53
51
  end
54
52
 
55
- alias_new :parse
53
+ class << self; alias_method(:parse, :new); end
56
54
 
57
55
  def initialize(acpc_log_statements, player_names, game_def_directory, num_hands=nil)
58
56
  @final_score = nil
@@ -64,8 +62,11 @@ module AcpcPokerTypes::AcpcDealerData
64
62
  else
65
63
  parsed_message = AcpcPokerTypes::AcpcDealerData::HandResults.parse_state(log_line)
66
64
  if parsed_message
67
- accumulating_data << parsed_message
65
+ # Yes, this causes one more result to be parsed than is saved as long as
66
+ # the number of hands is less than the total number in the log, but this
67
+ # keeps behavior consistent between this class and ActionMessages.
68
68
  break accumulating_data if accumulating_data.length == num_hands
69
+ accumulating_data << parsed_message
69
70
  else
70
71
  @final_score = AcpcPokerTypes::AcpcDealerData::HandResults.parse_score(log_line) unless @final_score
71
72
  end
@@ -111,9 +111,7 @@ module AcpcPokerTypes::AcpcDealerData
111
111
  raise MatchDefinitionsDoNotMatch
112
112
  end
113
113
 
114
- if (
115
- parsed_action_messages.final_score != parsed_hand_results.final_score
116
- )
114
+ if parsed_action_messages.final_score != parsed_hand_results.final_score
117
115
  raise FinalScoresDoNotMatch
118
116
  end
119
117
 
@@ -1,6 +1,3 @@
1
-
2
- require 'dmorrill10-utils' # For alias_new
3
-
4
1
  require 'acpc_poker_types/rank'
5
2
  require 'acpc_poker_types/suit'
6
3
 
@@ -33,7 +30,7 @@ module AcpcPokerTypes
33
30
  AcpcPokerTypes::Card.from_components rank, suit
34
31
  end
35
32
 
36
- alias_new :from_components
33
+ class << self; alias_method(:from_components, :new) end
37
34
 
38
35
  def initialize(rank, suit)
39
36
  @rank = AcpcPokerTypes::Rank.new rank
@@ -1,12 +1,15 @@
1
- require 'dmorrill10-utils/class'
2
- require 'dmorrill10-utils/enumerable'
3
- require 'dmorrill10-utils/integer'
4
1
  require 'set'
5
2
 
6
3
  require 'acpc_poker_types/chip_stack'
7
4
  require 'acpc_poker_types/suit'
8
5
  require 'acpc_poker_types/rank'
9
6
 
7
+ require 'acpc_poker_types/integer_as_seat'
8
+ using AcpcPokerTypes::IntegerAsSeat
9
+
10
+ require 'contextual_exceptions'
11
+ using ContextualExceptions::ClassRefinement
12
+
10
13
  # Class that parses and manages game definition information from a game definition file.
11
14
  module AcpcPokerTypes
12
15
  class GameDefinition
@@ -165,7 +168,7 @@ module AcpcPokerTypes
165
168
  File.open(game_definition_file_name, 'r') { |file| parse file }
166
169
  end
167
170
 
168
- alias_new :parse
171
+ class << self; alias_method(:parse, :new); end
169
172
 
170
173
  def initialize(definitions)
171
174
  initialize_members!
@@ -317,7 +320,7 @@ module AcpcPokerTypes
317
320
  end
318
321
  end
319
322
 
320
- number_of_cards_required = (@number_of_hole_cards * @number_of_players) + @number_of_board_cards.sum
323
+ number_of_cards_required = (@number_of_hole_cards * @number_of_players) + @number_of_board_cards.inject(:+)
321
324
 
322
325
  if number_of_cards_required > (@number_of_suits * @number_of_ranks)
323
326
  raise(
@@ -0,0 +1,72 @@
1
+ module AcpcPokerTypes
2
+ module IntegerAsSeat
3
+ refine Integer do
4
+ # @param [Integer] seat The seat to which the relative position is desired.
5
+ # @param [Integer] number_of_players The number of players at the table.
6
+ # @return [Integer] The relative position of +self+ to +seat+, given the
7
+ # number of players at the table, +number_of_players+, indexed such that
8
+ # the seat immediately to the left of +seat+ has a +position_relative_to+ of
9
+ # zero.
10
+ # @example <code>1.position_relative_to 0, 3</code> == 0
11
+ # @example <code>1.position_relative_to 1, 3</code> == 2
12
+ def position_relative_to(seat, number_of_players)
13
+ unless seat.seat_in_bounds?(number_of_players) &&
14
+ seat_in_bounds?(number_of_players)
15
+ raise "Seat #{seat} out of bounds for #{number_of_players} players"
16
+ end
17
+
18
+ adjusted_seat = if self > seat
19
+ self
20
+ else
21
+ self + number_of_players
22
+ end
23
+ adjusted_seat - seat - 1
24
+ end
25
+
26
+ # Inverse operation of +position_relative_to+.
27
+ # Given
28
+ # <code>relative_position = seat.position_relative_to to_seat, number_of_players</code>
29
+ # then
30
+ # <code>to_seat = seat.seat_from_relative_position relative_position, number_of_players</code>
31
+ #
32
+ # @param [Integer] relative_position_of_self_to_result The relative position
33
+ # of seat +self+ to the seat that is returned by this function.
34
+ # @param [Integer] number_of_players The number of players at the table.
35
+ # @return [Integer] The seat to which the relative position,
36
+ # +relative_position_of_self_to_result+, of +self+ was derived, given the
37
+ # number of players at the table, +number_of_players+, indexed such that
38
+ # the seat immediately to the left of +from_seat+ has a
39
+ # +position_relative_to+ of zero.
40
+ # @example <code>1.seat_from_relative_position 0, 3</code> == 0
41
+ # @example <code>1.seat_from_relative_position 2, 3</code> == 1
42
+ def seat_from_relative_position(relative_position_of_self_to_result,
43
+ number_of_players)
44
+ unless seat_in_bounds?(number_of_players)
45
+ raise "Seat #{seat} out of bounds for #{number_of_players} players"
46
+ end
47
+
48
+ unless relative_position_of_self_to_result.seat_in_bounds?(
49
+ number_of_players
50
+ )
51
+ raise "Relative position #{relative_position_of_self_to_result} out of bounds for #{number_of_players} players"
52
+ end
53
+
54
+ position_adjustment = relative_position_of_self_to_result + 1
55
+
56
+ to_seat = self + number_of_players - position_adjustment
57
+ if self > to_seat || !to_seat.seat_in_bounds?(number_of_players)
58
+ self - position_adjustment
59
+ else
60
+ to_seat
61
+ end
62
+ end
63
+
64
+ # @param [Integer] number_of_players The number of players at the table.
65
+ # @return [Bool] Reports whether or not +self+ represents an out of bounds
66
+ # seat.
67
+ def seat_in_bounds?(number_of_players)
68
+ self < number_of_players && self >= 0
69
+ end
70
+ end
71
+ end
72
+ end
@@ -1,12 +1,12 @@
1
-
2
- require 'dmorrill10-utils'
3
-
4
1
  require 'acpc_poker_types/board_cards'
5
2
  require 'acpc_poker_types/hand'
6
3
  require 'acpc_poker_types/rank'
7
4
  require 'acpc_poker_types/suit'
8
5
  require 'acpc_poker_types/poker_action'
9
6
 
7
+ require 'contextual_exceptions'
8
+ using ContextualExceptions::ClassRefinement
9
+
10
10
  # Model to parse and manage information from a given match state string.
11
11
  module AcpcPokerTypes
12
12
  class MatchState
@@ -39,7 +39,7 @@ module AcpcPokerTypes
39
39
  # @return [String] Label for match state strings.
40
40
  LABEL = 'MATCHSTATE'
41
41
 
42
- alias_new :parse
42
+ class << self; alias_method(:parse, :new) end
43
43
 
44
44
  # Builds a match state string from its given component parts.
45
45
  #
@@ -1,9 +1,9 @@
1
-
2
- require 'dmorrill10-utils'
3
-
4
1
  require 'acpc_poker_types/chip_stack'
5
2
  require 'acpc_poker_types/hand'
6
3
 
4
+ require 'contextual_exceptions'
5
+ using ContextualExceptions::ClassRefinement
6
+
7
7
  # Class to model a player.
8
8
  module AcpcPokerTypes
9
9
  class Player
@@ -54,7 +54,7 @@ module AcpcPokerTypes
54
54
  # the current hand, separated by round.
55
55
  attr_reader :actions_taken_this_hand
56
56
 
57
- alias_new :join_match
57
+ class << self; alias_method(:join_match, :new) end
58
58
 
59
59
  # @todo These comments don't work as expected
60
60
  # @param [String] name This players name.
@@ -1,3 +1,3 @@
1
1
  module AcpcPokerTypes
2
- VERSION = '3.1.0'
2
+ VERSION = '3.1.1'
3
3
  end
@@ -14,7 +14,7 @@
14
14
  <img src="./assets/0.7.1/loading.gif" alt="loading"/>
15
15
  </div>
16
16
  <div id="wrapper" style="display:none;">
17
- <div class="timestamp">Generated <abbr class="timeago" title="2013-05-08T18:30:05-06:00">2013-05-08T18:30:05-06:00</abbr></div>
17
+ <div class="timestamp">Generated <abbr class="timeago" title="2013-05-10T16:18:07-06:00">2013-05-10T16:18:07-06:00</abbr></div>
18
18
  <ul class="group_tabs"></ul>
19
19
 
20
20
  <div id="content">
data/spec/player_spec.rb CHANGED
@@ -4,7 +4,6 @@ require_relative 'support/spec_helper'
4
4
 
5
5
  require 'acpc_dealer'
6
6
  require 'acpc_poker_types/acpc_dealer_data/poker_match_data'
7
- require 'dmorrill10-utils'
8
7
 
9
8
  require 'acpc_poker_types/player'
10
9
  require 'acpc_poker_types/poker_action'
@@ -186,7 +185,7 @@ describe AcpcPokerTypes::Player do
186
185
  "#{dealer_log_directory}/#{log_description.results_file_name}",
187
186
  log_description.player_names,
188
187
  AcpcDealer::DEALER_DIRECTORY,
189
- 120
188
+ 10
190
189
  )
191
190
  match.for_every_seat! do |seat|
192
191
  @patient = AcpcPokerTypes::Player.join_match(
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acpc_poker_types
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0
4
+ version: 3.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dustin Morrill
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-05-09 00:00:00.000000000 Z
11
+ date: 2013-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: dmorrill10-utils
14
+ name: process_runner
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ~>
18
18
  - !ruby/object:Gem::Version
19
- version: '1.0'
19
+ version: '0.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ~>
25
25
  - !ruby/object:Gem::Version
26
- version: '1.0'
26
+ version: '0.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: acpc_dealer
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -172,6 +172,7 @@ files:
172
172
  - lib/acpc_poker_types/pile_of_cards.rb
173
173
  - lib/acpc_poker_types/game_definition.rb
174
174
  - lib/acpc_poker_types/rank.rb
175
+ - lib/acpc_poker_types/integer_as_seat.rb
175
176
  - lib/acpc_poker_types/suit.rb
176
177
  - lib/acpc_poker_types/chip_stack.rb
177
178
  - lib/acpc_poker_types/version.rb