acpc_poker_types 7.0.0 → 7.1.0
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
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7ca00e6a41dab80ef2f33c8f10c3ffaff6e2c0e1
|
4
|
+
data.tar.gz: c09333d7db8f948d5e328357a59536e70e44a68b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc1c019653c1e5671db05f44a355feb8a465052c83d2b8bd5b1930a5ece33d42b25128840de95ad717383136fd36a2a035e83670d5d3edd2e3661d729ae037ee
|
7
|
+
data.tar.gz: 412ac972e9c336b2dd5e6ff3b674372c799ea9f046ded2bb6f455bae1a173cf0f9a6d536feb4cbe7cd1205f311e28b14a1c062bc26785aa75c0cf51aa8961bc3
|
@@ -64,5 +64,23 @@ class HandPlayerGroup < DelegateClass(Array)
|
|
64
64
|
next_player_position(acting_player_position)
|
65
65
|
)
|
66
66
|
end
|
67
|
+
|
68
|
+
# @return [Integer] The number of wagers this round
|
69
|
+
def num_wagers(round)
|
70
|
+
inject(0) do |sum, pl|
|
71
|
+
sum += pl.actions[round].count do |ac|
|
72
|
+
PokerAction::MODIFIABLE_ACTIONS.include?(ac.action)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
# @return [Array<PokerAction>] The legal actions for the next player to act.
|
78
|
+
def legal_actions(acting_player_position, round, max_num_wagers)
|
79
|
+
@players[acting_player_position].legal_actions(
|
80
|
+
round: round,
|
81
|
+
amount_to_call: amount_to_call(acting_player_position),
|
82
|
+
wager_illegal: num_wagers(round) >= max_num_wagers
|
83
|
+
)
|
84
|
+
end
|
67
85
|
end
|
68
86
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'delegate'
|
2
|
+
|
1
3
|
require 'acpc_poker_types/board_cards'
|
2
4
|
require 'acpc_poker_types/hand'
|
3
5
|
require 'acpc_poker_types/rank'
|
@@ -35,7 +37,7 @@ using AcpcPokerTypes::Indices
|
|
35
37
|
module AcpcPokerTypes
|
36
38
|
|
37
39
|
# Model to parse and manage information from a given match state string.
|
38
|
-
class MatchState
|
40
|
+
class MatchState < DelegateClass(String)
|
39
41
|
# @return [Integer] The position relative to the dealer of the player that
|
40
42
|
# received the match state string, indexed from 0, modulo the
|
41
43
|
# number of players.
|
@@ -104,6 +106,8 @@ class MatchState
|
|
104
106
|
@community_cards_string = $5
|
105
107
|
end
|
106
108
|
@min_wager_by = nil
|
109
|
+
|
110
|
+
super to_s
|
107
111
|
end
|
108
112
|
|
109
113
|
# @return [String] The MatchState in raw text form.
|
@@ -319,6 +323,15 @@ class MatchState
|
|
319
323
|
@min_wager_by
|
320
324
|
end
|
321
325
|
|
326
|
+
# @return [Array<PokerAction>] The legal actions for the next player to act.
|
327
|
+
def legal_actions(game_def)
|
328
|
+
players(game_def).legal_actions(
|
329
|
+
next_to_act(game_def),
|
330
|
+
round,
|
331
|
+
game_def.max_number_of_wagers[round]
|
332
|
+
)
|
333
|
+
end
|
334
|
+
|
322
335
|
private
|
323
336
|
|
324
337
|
def walk_over_betting_sequence!(game_def)
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'delegate'
|
1
2
|
require 'set'
|
2
3
|
|
3
4
|
require 'acpc_poker_types/chip_stack'
|
@@ -30,115 +31,119 @@ module BlankRefinement
|
|
30
31
|
end
|
31
32
|
using BlankRefinement
|
32
33
|
|
34
|
+
|
33
35
|
module AcpcPokerTypes
|
34
|
-
class PokerAction
|
35
|
-
exceptions :illegal_action, :illegal_modification
|
36
36
|
|
37
|
-
|
38
|
-
|
39
|
-
CHECK = 'k'
|
40
|
-
FOLD = 'f'
|
41
|
-
RAISE = 'r'
|
37
|
+
class PokerAction < DelegateClass(String)
|
38
|
+
exceptions :illegal_action, :illegal_modification
|
42
39
|
|
43
|
-
|
40
|
+
BET = 'b'
|
41
|
+
CALL = 'c'
|
42
|
+
CHECK = 'k'
|
43
|
+
FOLD = 'f'
|
44
|
+
RAISE = 'r'
|
44
45
|
|
45
|
-
|
46
|
-
CANONICAL_ACTIONS = Set.new [CALL, FOLD, RAISE]
|
46
|
+
ACTIONS = Set.new [BET, CALL, CHECK, FOLD, RAISE]
|
47
47
|
|
48
|
-
|
48
|
+
# @return [Set<String>] The set of legal ACPC action characters.
|
49
|
+
CANONICAL_ACTIONS = Set.new [CALL, FOLD, RAISE]
|
49
50
|
|
50
|
-
|
51
|
+
MODIFIABLE_ACTIONS = Set.new [BET, RAISE]
|
51
52
|
|
52
|
-
|
53
|
-
# Could be negative to imply the acting player takes chips from the pot.
|
54
|
-
attr_reader :cost
|
53
|
+
CONCATONATED_ACTIONS = ACTIONS.to_a.join
|
55
54
|
|
56
|
-
|
57
|
-
|
55
|
+
# @return [Rational] The amount that the player taking this action needs to put in the pot.
|
56
|
+
# Could be negative to imply the acting player takes chips from the pot.
|
57
|
+
attr_reader :cost
|
58
58
|
|
59
|
-
|
60
|
-
|
61
|
-
alias_method :to_acpc_character, :action
|
59
|
+
# @return [String] A modifier for the action (i.e. a bet or raise size).
|
60
|
+
attr_reader :modifier
|
62
61
|
|
63
|
-
|
64
|
-
|
62
|
+
# @return [String] Action character
|
63
|
+
attr_reader :action
|
64
|
+
alias_method :to_acpc_character, :action
|
65
65
|
|
66
|
-
|
67
|
-
|
68
|
-
# @param cost [#to_f] The amount this action costs to the acting player.
|
69
|
-
# @raise IllegalAction
|
70
|
-
def initialize(action, modifier: nil, cost: 0)
|
71
|
-
validate_action!(action, modifier.strip)
|
72
|
-
@cost = cost.to_f
|
73
|
-
end
|
66
|
+
# @return [Boolean] Whether or not the pot has been added to this round before this action.
|
67
|
+
attr_reader :pot_gained_chips
|
74
68
|
|
75
|
-
|
76
|
-
|
77
|
-
|
69
|
+
# @param [Symbol, String] action A representation of this action.
|
70
|
+
# @param modifier [String] A modifier to attach to this action such as a wager size.
|
71
|
+
# @param cost [#to_f] The amount this action costs to the acting player.
|
72
|
+
# @raise IllegalAction
|
73
|
+
def initialize(action, modifier: nil, cost: 0)
|
74
|
+
validate_action!(action, modifier.strip)
|
75
|
+
@cost = cost.to_f
|
78
76
|
|
79
|
-
|
80
|
-
|
81
|
-
end
|
77
|
+
super to_s
|
78
|
+
end
|
82
79
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
80
|
+
# def ==(other_action)
|
81
|
+
# 0 == (self <=> other_action)
|
82
|
+
# end
|
83
|
+
|
84
|
+
# def <=>(other_action)
|
85
|
+
# to_s <=> other_action.to_s
|
86
|
+
# end
|
87
|
+
|
88
|
+
# @return [String] String representation of this action.
|
89
|
+
# @param pot_gained_chips [Boolean] Whether or not the pot had gained chips before this action. Defaults to true.
|
90
|
+
# @param player_sees_wager [Boolean] Whether or not the player is reacting to a wager.
|
91
|
+
# Defaults to the value of +pot_gained_chips+.
|
92
|
+
def to_s(pot_gained_chips: true, player_sees_wager: pot_gained_chips)
|
93
|
+
combine_action_and_modifier(
|
94
|
+
if @action == FOLD
|
95
|
+
@action
|
96
|
+
elsif @action == BET || @action == RAISE
|
97
|
+
if pot_gained_chips then RAISE else BET end
|
98
|
+
elsif @action == CALL || @action == CHECK
|
99
|
+
if player_sees_wager then CALL else CHECK end
|
100
|
+
end
|
101
|
+
)
|
102
|
+
end
|
98
103
|
|
99
|
-
|
100
|
-
|
104
|
+
alias_method :to_acpc, :to_s
|
105
|
+
alias_method :to_str, :to_s
|
101
106
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
107
|
+
# @return [Boolean] +true+ if this action has a modifier, +false+ otherwise.
|
108
|
+
def has_modifier?
|
109
|
+
!@modifier.blank?
|
110
|
+
end
|
106
111
|
|
107
|
-
|
112
|
+
private
|
108
113
|
|
109
|
-
|
110
|
-
|
111
|
-
|
114
|
+
def combine_action_and_modifier(action=@action, modifier=@modifier)
|
115
|
+
"#{action}#{modifier}"
|
116
|
+
end
|
112
117
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
118
|
+
def validate_action!(action, given_modifier)
|
119
|
+
action_string = action.to_s
|
120
|
+
raise IllegalAction if action_string.empty?
|
121
|
+
@action = action_string[0]
|
122
|
+
raise IllegalAction unless ACTIONS.include?(@action)
|
123
|
+
@modifier = action_string[1..-1].strip unless action_string.length < 2
|
124
|
+
|
125
|
+
if !given_modifier.blank? && !@modifier.blank?
|
126
|
+
raise(
|
127
|
+
IllegalModification,
|
128
|
+
"in-place modifier: #{@modifier}, explicit modifier: #{given_modifier}"
|
129
|
+
)
|
130
|
+
end
|
126
131
|
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
+
@modifier = if !@modifier.blank?
|
133
|
+
@modifier
|
134
|
+
elsif !given_modifier.blank?
|
135
|
+
given_modifier
|
136
|
+
end
|
132
137
|
|
133
|
-
|
138
|
+
validate_modifier
|
134
139
|
|
135
|
-
|
136
|
-
|
140
|
+
self
|
141
|
+
end
|
137
142
|
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
end
|
143
|
+
def validate_modifier
|
144
|
+
unless @modifier.blank? || MODIFIABLE_ACTIONS.include?(@action)
|
145
|
+
raise(IllegalModification, "Illegal modifier: #{@modifier}")
|
142
146
|
end
|
143
147
|
end
|
148
|
+
end
|
144
149
|
end
|
data/spec/match_state_spec.rb
CHANGED
@@ -222,7 +222,7 @@ describe MatchState do
|
|
222
222
|
log_description.results_file_path,
|
223
223
|
log_description.player_names,
|
224
224
|
AcpcDealer::DEALER_DIRECTORY,
|
225
|
-
|
225
|
+
10
|
226
226
|
)
|
227
227
|
match.for_every_seat! do |seat|
|
228
228
|
match.for_every_hand! do
|
@@ -878,6 +878,17 @@ describe MatchState do
|
|
878
878
|
end
|
879
879
|
end
|
880
880
|
end
|
881
|
+
describe 'players legal actions' do
|
882
|
+
it 'should work properly when facing a wager' do
|
883
|
+
game_definition = GameDefinition.parse_file(AcpcDealer::GAME_DEFINITION_FILE_PATHS[2][:limit])
|
884
|
+
MatchState.parse("MATCHSTATE:0:3:crc/rrrr:Qh9s|/KdQc7c").legal_actions(
|
885
|
+
game_definition
|
886
|
+
).must_equal [
|
887
|
+
PokerAction.new(PokerAction::CALL, cost: game_definition.min_wagers[2]),
|
888
|
+
PokerAction.new(PokerAction::FOLD)
|
889
|
+
]
|
890
|
+
end
|
891
|
+
end
|
881
892
|
end
|
882
893
|
|
883
894
|
def for_every_card
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acpc_poker_types
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 7.
|
4
|
+
version: 7.1.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-08-
|
11
|
+
date: 2013-08-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: process_runner
|