acpc_poker_player_proxy 1.1.3 → 1.2.0

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: a9d4acd91b92cb9198ae109a1cc655a9f98b3ac0
4
- data.tar.gz: f6c3e6741485a5b247c4195efd6e6d5b607c6b64
3
+ metadata.gz: 28c7fe64970dadc53c1be54bb537c41ed4ea88b8
4
+ data.tar.gz: 6c6c7cacd9a0ace29552cc7aaba9015b44dd664d
5
5
  SHA512:
6
- metadata.gz: 34b5fe01458eeac7ab19f913fcdc082125982e2b9b4f8f23327575ef84ef8df7a1d7e47eb539aa9bc481c6eaa19d1e9b4c5b452485f04c634f13bf35492bc3a2
7
- data.tar.gz: a4fb104df3b97cff04ac84b83bc559d7c2e0462ca17306165fd06af315fd7960f9d87453f9ab694ab28d9daacee255944d8a03567f40f5569a1a6973fa00b088
6
+ metadata.gz: c457fcdd2b66938335689b1bb09ab3c0e7e8619101f013174b6b6cc07036988aed2313de39de97b5d3a2a47fe9b58c6510d758a781fa1be78ffbbe12fae50f28
7
+ data.tar.gz: f7bc6000a7e58cb0bed053d322c5ea33ed492ba6ed10148c3b9b4de2d3857fb0e54cec2ffc1604716238ad6b05e3285e567e18deb8418d44bf81d906a177d827
@@ -11,9 +11,8 @@ Gem::Specification.new do |s|
11
11
  s.summary = %q{ACPC Poker Player Proxy}
12
12
  s.description = %q{A smart proxy for a poker player that connects to the ACPC Dealer and manages match state data}
13
13
 
14
- s.add_dependency 'acpc_poker_match_state', '~> 2.0'
15
14
  s.add_dependency 'acpc_poker_basic_proxy', '~> 3.0'
16
- s.add_dependency 'acpc_poker_types', '~> 5.0'
15
+ s.add_dependency 'acpc_poker_types', '~> 7.0'
17
16
  s.add_dependency 'contextual_exceptions', '~> 0.0'
18
17
  s.add_dependency 'methadone', '~> 1.2'
19
18
  s.add_dependency 'acpc_dealer', '~> 2.0'
@@ -25,10 +24,9 @@ Gem::Specification.new do |s|
25
24
  s.test_files = s.files.grep(%r{^(test|spec|features)/})
26
25
  s.require_paths = ["lib"]
27
26
 
28
- s.add_development_dependency 'turn', '~> 0.9'
29
- s.add_development_dependency 'minitest', '~> 4.7'
27
+ s.add_development_dependency 'minitest', '~> 5.0.6'
28
+ s.add_development_dependency 'mocha', '~> 0.13'
30
29
  s.add_development_dependency 'awesome_print', '~> 1.0'
31
30
  s.add_development_dependency 'pry-rescue', '~> 1.0'
32
31
  s.add_development_dependency 'simplecov', '~> 0.7'
33
- s.add_development_dependency 'mocha', '~> 0.13'
34
32
  end
@@ -1,4 +1,6 @@
1
- require 'acpc_poker_match_state/players_at_the_table'
1
+ require 'delegate'
2
+
3
+ require 'acpc_poker_types/players_at_the_table'
2
4
  require 'acpc_poker_types/player'
3
5
  require 'acpc_poker_types/game_definition'
4
6
  require 'acpc_poker_basic_proxy/basic_proxy'
@@ -7,101 +9,98 @@ require 'contextual_exceptions'
7
9
  using ContextualExceptions::ClassRefinement
8
10
 
9
11
  module AcpcPokerPlayerProxy
10
- class PlayerProxy
11
- include AcpcPokerTypes
12
- include AcpcPokerMatchState
13
- include AcpcPokerBasicProxy
14
12
 
15
- exceptions :match_ended
13
+ class PlayerProxy < DelegateClass(AcpcPokerTypes::PlayersAtTheTable)
14
+ include AcpcPokerTypes
15
+ include AcpcPokerBasicProxy
16
16
 
17
- # @return [PlayersAtTheTable] Summary of the progression of the match
18
- # in which, this player is participating, since this object's instantiation.
19
- attr_reader :players_at_the_table
17
+ exceptions :match_ended
20
18
 
21
- attr_reader :game_def
19
+ # @return [PlayersAtTheTable] Summary of the progression of the match
20
+ # in which, this player is participating, since this object's instantiation.
21
+ attr_reader :players_at_the_table
22
22
 
23
- attr_reader :users_seat
23
+ attr_reader :match_has_ended
24
24
 
25
- attr_reader :player_names
25
+ attr_reader :game_def
26
26
 
27
- attr_reader :number_of_hands
27
+ # @param [DealerInformation] dealer_information Information about the dealer to which this bot should connect.
28
+ # @param [GameDefinition, #to_s] game_definition_argument A game definition; either a +GameDefinition+ or the name of the file containing a game definition.
28
29
 
29
- # @param [DealerInformation] dealer_information Information about the dealer to which this bot should connect.
30
- # @param [GameDefinition, #to_s] game_definition_argument A game definition; either a +GameDefinition+ or the name of the file containing a game definition.
31
- # @param [String] player_names The names of the players in this match.
32
- # @param [Integer] number_of_hands The number of hands in this match.
33
- def initialize(
34
- dealer_information,
35
- users_seat,
36
- game_definition_argument,
37
- player_names='user p2',
38
- number_of_hands=1
30
+ def initialize(
31
+ dealer_information,
32
+ game_definition_argument,
33
+ users_seat = nil
34
+ )
35
+ game_def = if game_definition_argument.kind_of?(
36
+ GameDefinition
39
37
  )
40
- @game_def = if game_definition_argument.kind_of?(
41
- GameDefinition
42
- )
43
- game_definition_argument
44
- else
45
- GameDefinition.parse_file(game_definition_argument)
46
- end
47
- @basic_proxy = BasicProxy.new dealer_information
48
-
49
- @player_names = player_names.split(/,?\s+/)
50
-
51
- @users_seat = users_seat
38
+ game_definition_argument
39
+ else
40
+ GameDefinition.parse_file(game_definition_argument)
41
+ end
42
+ @basic_proxy = BasicProxy.new dealer_information
52
43
 
53
- @number_of_hands = number_of_hands
44
+ @players_at_the_table = if users_seat
45
+ PlayersAtTheTable.seat_players game_def, users_seat
46
+ else
47
+ PlayersAtTheTable.seat_players game_def
48
+ end
54
49
 
55
- @players_at_the_table = create_players_at_the_table
50
+ @match_has_ended = false
56
51
 
57
- yield @players_at_the_table if block_given?
52
+ yield @players_at_the_table if block_given?
58
53
 
59
- update_match_state_if_necessary! do |players_at_the_table|
60
- yield players_at_the_table if block_given?
61
- end
54
+ update_match_state_if_necessary! do |players_at_the_table|
55
+ yield players_at_the_table if block_given?
62
56
  end
63
57
 
64
- # Player action interface
65
- # @param [PokerAction] action The action to take.
66
- def play!(action)
67
- if @players_at_the_table.match_ended?
68
- raise MatchEnded, "Cannot take action #{action} because the match has ended!"
69
- end
58
+ super @players_at_the_table
59
+ end
70
60
 
61
+ # Player action interface
62
+ # @param [PokerAction] action The action to take.
63
+ def play!(action)
64
+ begin
71
65
  @basic_proxy.send_action action
72
-
73
- update_match_state! do |players_at_the_table|
74
- yield @players_at_the_table = players_at_the_table
75
- end
66
+ rescue AcpcPokerBasicProxy::DealerStream::UnableToWriteToDealer => e
67
+ raise MatchEnded.new.with_context(
68
+ "Cannot take action #{action} because the match has ended!",
69
+ e
70
+ )
76
71
  end
77
72
 
78
- private
73
+ update_match_state! do |players_at_the_table|
74
+ __setobj__ @players_at_the_table = players_at_the_table
79
75
 
80
- def update_match_state_if_necessary!
81
- return self if @players_at_the_table.users_turn_to_act? || @players_at_the_table.match_ended?
82
-
83
- update_match_state! do |players_at_the_table|
84
- yield players_at_the_table
85
- end
76
+ yield @players_at_the_table if block_given?
86
77
  end
78
+ end
79
+
80
+ def match_ended?
81
+ @match_has_ended
82
+ end
87
83
 
88
- def update_match_state!
89
- @players_at_the_table.update!(@basic_proxy.receive_match_state!)
84
+ private
90
85
 
91
- yield @players_at_the_table
86
+ def update_match_state_if_necessary!
87
+ return self if @players_at_the_table.users_turn_to_act? || match_ended?
92
88
 
93
- update_match_state_if_necessary! do |players_at_the_table|
94
- yield players_at_the_table
95
- end
89
+ update_match_state! do |players_at_the_table|
90
+ yield players_at_the_table if block_given?
96
91
  end
92
+ end
97
93
 
98
- def create_players_at_the_table
99
- PlayersAtTheTable.seat_players(
100
- @game_def,
101
- @player_names,
102
- @users_seat,
103
- @number_of_hands
104
- )
94
+ def update_match_state!
95
+ begin
96
+ yield @players_at_the_table.update!(@basic_proxy.receive_match_state!) if block_given?
97
+ rescue AcpcPokerBasicProxy::DealerStream::UnableToGetFromDealer
98
+ @match_has_ended = true
99
+ end
100
+
101
+ update_match_state_if_necessary! do |players_at_the_table|
102
+ yield players_at_the_table if block_given?
105
103
  end
106
104
  end
105
+ end
107
106
  end
@@ -1,3 +1,3 @@
1
1
  module AcpcPokerPlayerProxy
2
- VERSION = "1.1.3"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -9,14 +9,14 @@ require 'acpc_dealer'
9
9
  require 'acpc_poker_player_proxy/player_proxy'
10
10
 
11
11
  include AcpcPokerTypes
12
- include AcpcDealerData
12
+ include DealerData
13
13
  include AcpcPokerBasicProxy
14
14
  include AcpcPokerPlayerProxy
15
15
 
16
16
  describe PlayerProxy do
17
17
  PORT_NUMBER = 9001
18
18
  HOST_NAME = 'localhost'
19
- DEALER_INFO = AcpcDealer::ConnectionInformation.new HOST_NAME, PORT_NUMBER
19
+ DEALER_INFO = AcpcDealer::ConnectionInformation.new PORT_NUMBER, HOST_NAME
20
20
 
21
21
  describe '#update!' do
22
22
  describe "keeps track of state for a sequence of match states and actions in Doyle's game" do
@@ -25,28 +25,23 @@ describe PlayerProxy do
25
25
  # Some interesting three player hands occur after 120
26
26
  # Careful though, even 10 hands takes about 7 seconds,
27
27
  # and it scales more than linearly
28
- num_hands = 10
28
+ num_hands = 200
29
29
  each_match(num_hands) do |match|
30
30
  @match = match
31
31
  @match.for_every_seat! do |users_seat|
32
32
 
33
33
  @basic_proxy = init_basic_proxy
34
34
 
35
- @patient = PlayerProxy.new(
36
- DEALER_INFO,
37
- users_seat,
38
- @match.match_def.game_def,
39
- @match.players.map { |player| player.name }.join(' '),
40
- num_hands
41
- ) do |patt|
42
-
35
+ @patient = PlayerProxy.new(DEALER_INFO, @match.match_def.game_def, users_seat) do |patt|
43
36
  check_players_at_the_table patt
44
37
 
45
38
  @match.next_hand! unless @match.hand_number
46
39
 
47
40
  if @match.current_hand.final_turn?
48
41
  @match.current_hand.end_hand!
42
+
49
43
  break if @match.final_hand?
44
+
50
45
  @match.next_hand!
51
46
  end
52
47
  @match.next_turn!
@@ -104,87 +99,67 @@ describe PlayerProxy do
104
99
  def check_players_at_the_table(patient)
105
100
  patient.player_acting_sequence.must_equal @match.player_acting_sequence
106
101
  patient.players.length.must_equal @match.players.length
107
- check_last_action patient
108
102
  check_next_to_act patient
109
103
  check_last_turn patient
110
- patient.opponents_cards_visible?.must_equal @match.opponents_cards_visible?
111
- patient.reached_showdown?.must_equal @match.opponents_cards_visible?
112
- patient.less_than_two_non_folded_players?.must_equal @match.non_folded_players.length < 2
104
+ patient.player_acting_sequence_string.must_equal @match.player_acting_sequence_string
105
+ patient.users_turn_to_act?.must_equal @match.users_turn_to_act?
106
+ check_betting_sequence patient
113
107
 
114
108
  if @match.current_hand
115
109
  patient.hand_ended?.must_equal @match.current_hand.final_turn?
116
- patient.match_ended?.must_equal (@match.final_hand? && @match.current_hand.final_turn?)
117
- end
118
- patient.last_hand?.must_equal (
119
- if @match.final_hand?.nil?
120
- false
121
- else
122
- @match.final_hand?
110
+ unless @match.current_hand.final_turn?
111
+ patient.match_state.all_hands.each do |hand|
112
+ hand.each do |card|
113
+ card.must_be_kind_of AcpcPokerTypes::Card
114
+ end
115
+ end
123
116
  end
124
- )
125
- patient.player_acting_sequence_string.must_equal @match.player_acting_sequence_string
126
- patient.users_turn_to_act?.must_equal @match.users_turn_to_act?
127
- check_betting_sequence patient
117
+ end
128
118
  # @todo Test this eventually
129
119
  # patient.min_wager.to_i.must_equal @min_wager.to_i
130
120
  end
121
+
131
122
  def check_player_blind_relation(patient)
132
- expected_player_blind_relation = @match.player_blind_relation
133
- patient.player_blind_relation.each do |player, blind|
134
- expected_player_and_blind = expected_player_blind_relation.to_a.find do |player_and_blind|
135
- player_and_blind.first.seat == player.seat
123
+ patient.position_relative_to_dealer(patient.big_blind_payer).must_equal(
124
+ @match.match_def.game_def.blinds.index(@match.match_def.game_def.blinds.max)
125
+ )
126
+ patient.position_relative_to_dealer(patient.small_blind_payer).must_equal(
127
+ @match.match_def.game_def.blinds.index do |blind|
128
+ blind < @match.match_def.game_def.blinds.max && blind > 0
136
129
  end
137
-
138
- expected_player = expected_player_and_blind.first
139
- expected_blind = expected_player_and_blind.last
140
-
141
- player.close_enough?(expected_player).must_equal true
142
- blind.must_equal expected_blind
143
- end
130
+ )
144
131
  end
145
132
  def check_betting_sequence(patient)
146
- patient_betting_sequence = patient.betting_sequence.map do |actions|
147
- actions.map { |action| PokerAction.new(action.to_s).to_s }
148
- end
149
- expected_betting_sequence = @match.betting_sequence.map do |actions|
150
- actions.map { |action| action.to_s }
133
+ x_betting_sequence = @match.betting_sequence.map do |actions|
134
+ actions.map { |action| AcpcPokerTypes::PokerAction.new(action).to_s }
151
135
  end
152
- patient_betting_sequence.must_equal expected_betting_sequence
153
136
 
154
- patient.betting_sequence_string.scan(/([a-z]\d*|\/)/).flatten.map do |action|
137
+ return x_betting_sequence.flatten.empty?.must_equal(true) unless patient.match_state
138
+
139
+ patient.match_state.betting_sequence.map do |actions|
140
+ actions.map { |action| AcpcPokerTypes::PokerAction.new(action).to_s }
141
+ end.must_equal x_betting_sequence
142
+
143
+ patient.match_state.betting_sequence_string.scan(/([a-z]\d*|\/)/).flatten.map do |action|
155
144
  if action.match(/\//)
156
145
  action
157
146
  else
158
- PokerAction.new(action).to_s
147
+ AcpcPokerTypes::PokerAction.new(action).to_s
159
148
  end
160
149
  end.join('').must_equal @match.betting_sequence_string
161
150
  end
162
- def check_last_action(patient)
163
- if @match.current_hand && @match.current_hand.last_action
164
- patient.player_who_acted_last.seat.must_equal @match.current_hand.last_action.seat
165
- else
166
- patient.player_who_acted_last.must_be_nil
167
- end
168
- end
169
151
  def check_next_to_act(patient)
170
152
  if @match.current_hand && @match.current_hand.next_action
171
153
  patient.next_player_to_act.seat.must_equal @match.current_hand.next_action.seat
172
154
  else
173
- patient.next_player_to_act.must_be_nil
155
+ patient.next_player_to_act.seat.must_be_nil
174
156
  end
175
157
  end
176
158
  def check_last_turn(patient)
177
159
  return unless @match.current_hand && @match.current_hand.final_turn?
160
+
178
161
  patient.players.players_close_enough?(@match.players).must_equal true
179
- patient.user_player.close_enough?(@match.player).must_equal true
180
- patient.opponents.players_close_enough?(@match.opponents).must_equal true
181
- patient.non_folded_players.players_close_enough?(@match.non_folded_players).must_equal true
182
- patient.active_players.players_close_enough?(@match.active_players).must_equal true
183
- patient.player_with_dealer_button.close_enough?(@match.player_with_dealer_button).must_equal true
184
- check_player_blind_relation patient
185
- patient.chip_stacks.must_equal @match.chip_stacks
186
- patient.chip_balances.must_equal @match.chip_balances
187
- patient.chip_contributions.flatten.inject(:+).must_equal @match.chip_contributions.flatten.inject(:+)
162
+ check_player_blind_relation(patient)
188
163
  end
189
164
  end
190
165
 
@@ -204,22 +179,8 @@ class Array
204
179
  end
205
180
 
206
181
  class AcpcPokerTypes::Player
207
- def acpc_actions_taken_this_hand
208
- acpc_actions = @actions_taken_this_hand.map do |actions_per_turn|
209
- actions_per_turn.map { |action| AcpcPokerTypes::PokerAction.new(action).to_s }
210
- end
211
- if acpc_actions.first.empty?
212
- acpc_actions
213
- else
214
- acpc_actions.reject_empty_elements
215
- end
216
- end
217
-
218
182
  def close_enough?(other)
219
- @name == other.name &&
220
183
  @seat == other.seat &&
221
- @chip_stack == other.chip_stack &&
222
- @chip_balance == other.chip_balance &&
223
- acpc_actions_taken_this_hand == other.acpc_actions_taken_this_hand
184
+ balance == other.balance
224
185
  end
225
- end
186
+ end
@@ -1,24 +1,10 @@
1
1
  require 'simplecov'
2
2
  SimpleCov.start
3
3
 
4
+ require 'minitest/autorun'
4
5
  require 'minitest/spec'
5
- require 'minitest/pride'
6
6
  require 'minitest/mock'
7
7
 
8
- require 'turn'
9
- Turn.config do |c|
10
- # use one of output formats:
11
- # :outline - turn's original case/test outline mode [default]
12
- # :progress - indicates progress with progress bar
13
- # :dotted - test/unit's traditional dot-progress mode
14
- # :pretty - new pretty reporter
15
- # :marshal - dump output as YAML (normal run mode only)
16
- # :cue - interactive testing
17
- c.format = :dotted
18
- # use humanized test names (works only with :outline format)
19
- c.natural = true
20
- end
21
-
22
8
  require 'awesome_print'
23
9
  module Minitest::Assertions
24
10
  def mu_pp(obj)
@@ -27,7 +13,6 @@ module Minitest::Assertions
27
13
  end
28
14
 
29
15
  require 'mocha/setup'
30
- require 'pry-rescue/minitest'
31
16
 
32
17
  # Match log information in dealer_logs
33
18
  class MatchLog
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acpc_poker_player_proxy
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.2.0
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-06-07 00:00:00.000000000 Z
11
+ date: 2013-08-07 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: acpc_poker_match_state
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ~>
18
- - !ruby/object:Gem::Version
19
- version: '2.0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ~>
25
- - !ruby/object:Gem::Version
26
- version: '2.0'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: acpc_poker_basic_proxy
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -44,14 +30,14 @@ dependencies:
44
30
  requirements:
45
31
  - - ~>
46
32
  - !ruby/object:Gem::Version
47
- version: '5.0'
33
+ version: '7.0'
48
34
  type: :runtime
49
35
  prerelease: false
50
36
  version_requirements: !ruby/object:Gem::Requirement
51
37
  requirements:
52
38
  - - ~>
53
39
  - !ruby/object:Gem::Version
54
- version: '5.0'
40
+ version: '7.0'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: contextual_exceptions
57
43
  requirement: !ruby/object:Gem::Requirement
@@ -95,33 +81,33 @@ dependencies:
95
81
  - !ruby/object:Gem::Version
96
82
  version: '2.0'
97
83
  - !ruby/object:Gem::Dependency
98
- name: turn
84
+ name: minitest
99
85
  requirement: !ruby/object:Gem::Requirement
100
86
  requirements:
101
87
  - - ~>
102
88
  - !ruby/object:Gem::Version
103
- version: '0.9'
89
+ version: 5.0.6
104
90
  type: :development
105
91
  prerelease: false
106
92
  version_requirements: !ruby/object:Gem::Requirement
107
93
  requirements:
108
94
  - - ~>
109
95
  - !ruby/object:Gem::Version
110
- version: '0.9'
96
+ version: 5.0.6
111
97
  - !ruby/object:Gem::Dependency
112
- name: minitest
98
+ name: mocha
113
99
  requirement: !ruby/object:Gem::Requirement
114
100
  requirements:
115
101
  - - ~>
116
102
  - !ruby/object:Gem::Version
117
- version: '4.7'
103
+ version: '0.13'
118
104
  type: :development
119
105
  prerelease: false
120
106
  version_requirements: !ruby/object:Gem::Requirement
121
107
  requirements:
122
108
  - - ~>
123
109
  - !ruby/object:Gem::Version
124
- version: '4.7'
110
+ version: '0.13'
125
111
  - !ruby/object:Gem::Dependency
126
112
  name: awesome_print
127
113
  requirement: !ruby/object:Gem::Requirement
@@ -164,20 +150,6 @@ dependencies:
164
150
  - - ~>
165
151
  - !ruby/object:Gem::Version
166
152
  version: '0.7'
167
- - !ruby/object:Gem::Dependency
168
- name: mocha
169
- requirement: !ruby/object:Gem::Requirement
170
- requirements:
171
- - - ~>
172
- - !ruby/object:Gem::Version
173
- version: '0.13'
174
- type: :development
175
- prerelease: false
176
- version_requirements: !ruby/object:Gem::Requirement
177
- requirements:
178
- - - ~>
179
- - !ruby/object:Gem::Version
180
- version: '0.13'
181
153
  description: A smart proxy for a poker player that connects to the ACPC Dealer and
182
154
  manages match state data
183
155
  email:
@@ -227,7 +199,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
227
199
  version: '0'
228
200
  requirements: []
229
201
  rubyforge_project: acpc_poker_player_proxy
230
- rubygems_version: 2.0.0.rc.2
202
+ rubygems_version: 2.0.3
231
203
  signing_key:
232
204
  specification_version: 4
233
205
  summary: ACPC Poker Player Proxy
@@ -242,3 +214,4 @@ test_files:
242
214
  - spec/support/dealer_logs/3p.nolimit.h1000.r0.actions.log
243
215
  - spec/support/dealer_logs/3p.nolimit.h1000.r0.log
244
216
  - spec/support/spec_helper.rb
217
+ has_rdoc: