Class: AcpcPokerTypes::PokerAction

Inherits:
Object
  • Object
show all
Defined in:
lib/acpc_poker_types/poker_action.rb

Constant Summary collapse

BET =
'b'
CALL =
'c'
CHECK =
'k'
FOLD =
'f'
RAISE =
'r'
ACTIONS =
Set.new [BET, CALL, CHECK, FOLD, RAISE]
CANONICAL_ACTIONS =

Returns The set of legal ACPC action characters.

Returns:

  • (Set<String>)

    The set of legal ACPC action characters.

Set.new [CALL, FOLD, RAISE]
MODIFIABLE_ACTIONS =
Set.new [BET, RAISE]
CONCATONATED_ACTIONS =
ACTIONS.to_a.join

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(action, modifier: nil, cost: AcpcPokerTypes::ChipStack.new(0)) ⇒ PokerAction

Returns a new instance of PokerAction.

Parameters:

  • action (Symbol, String)

    A representation of this action.

  • context (Hash)

    The context in which this action is being made. Recognized keys include :modifier, :pot_gained_chips, and :cost.

Raises:

  • IllegalAction



70
71
72
73
# File 'lib/acpc_poker_types/poker_action.rb', line 70

def initialize(action, modifier: nil, cost: AcpcPokerTypes::ChipStack.new(0))
  validate_action!(action, modifier.strip)
  @cost = cost
end

Instance Attribute Details

#actionString (readonly) Also known as: to_acpc_character

Returns Action character.

Returns:

  • (String)

    Action character



60
61
62
# File 'lib/acpc_poker_types/poker_action.rb', line 60

def action
  @action
end

#costRational (readonly)

Returns The amount that the player taking this action needs to put in the pot. Could be negative to imply the acting player takes chips from the pot.

Returns:

  • (Rational)

    The amount that the player taking this action needs to put in the pot. Could be negative to imply the acting player takes chips from the pot.



54
55
56
# File 'lib/acpc_poker_types/poker_action.rb', line 54

def cost
  @cost
end

#modifierString (readonly)

Returns A modifier for the action (i.e. a bet or raise size).

Returns:

  • (String)

    A modifier for the action (i.e. a bet or raise size).



57
58
59
# File 'lib/acpc_poker_types/poker_action.rb', line 57

def modifier
  @modifier
end

#pot_gained_chipsBoolean (readonly)

Returns Whether or not the pot has been added to this round before this action.

Returns:

  • (Boolean)

    Whether or not the pot has been added to this round before this action.



64
65
66
# File 'lib/acpc_poker_types/poker_action.rb', line 64

def pot_gained_chips
  @pot_gained_chips
end

Instance Method Details

#==(other_action) ⇒ Object



75
76
77
# File 'lib/acpc_poker_types/poker_action.rb', line 75

def ==(other_action)
  to_s == other_action.to_s
end

#has_modifier?Boolean

Returns true if this action has a modifier, false otherwise.

Returns:

  • (Boolean)

    true if this action has a modifier, false otherwise.



98
99
100
# File 'lib/acpc_poker_types/poker_action.rb', line 98

def has_modifier?
  !@modifier.blank?
end

#to_s(pot_gained_chips: true, player_sees_wager: pot_gained_chips) ⇒ String Also known as: to_acpc

Returns String representation of this action.

Parameters:

  • pot_gained_chips (Boolean) (defaults to: true)

    Whether or not the pot had gained chips before this action. Defaults to true.

  • player_sees_wager (Boolean) (defaults to: pot_gained_chips)

    Whether or not the player is reacting to a wager. Defaults to the value of pot_gained_chips.

Returns:

  • (String)

    String representation of this action.



83
84
85
86
87
88
89
90
91
92
93
# File 'lib/acpc_poker_types/poker_action.rb', line 83

def to_s(pot_gained_chips: true, player_sees_wager: pot_gained_chips)
  combine_action_and_modifier(
    if @action == FOLD
      @action
    elsif @action == BET || @action == RAISE
      if pot_gained_chips then RAISE else BET end
    elsif @action == CALL || @action == CHECK
      if player_sees_wager then CALL else CHECK end
    end
  )
end