Class: AcpcPokerTypes::PokerAction

Inherits:
String
  • 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: 0) ⇒ PokerAction

Returns a new instance of PokerAction.

Parameters:

  • action (Symbol, String)

    A representation of this action.

  • modifier (String) (defaults to: nil)

    A modifier to attach to this action such as a wager size.

  • cost (#to_f) (defaults to: 0)

    The amount this action costs to the acting player.

Raises:

  • IllegalAction



73
74
75
76
77
78
79
# File 'lib/acpc_poker_types/poker_action.rb', line 73

def initialize(action, modifier: nil, cost: 0)
  @modifier = nil
  validate_action!(action, modifier.strip)
  @cost = cost.to_f

  super to_s
end

Instance Attribute Details

#actionString (readonly) Also known as: to_acpc_character

Returns Action character.

Returns:

  • (String)

    Action character



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

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.



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

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).



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

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.



67
68
69
# File 'lib/acpc_poker_types/poker_action.rb', line 67

def pot_gained_chips
  @pot_gained_chips
end

Instance Method Details

#has_modifier?Boolean

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

Returns:

  • (Boolean)

    true if this action has a modifier, false otherwise.



101
102
103
# File 'lib/acpc_poker_types/poker_action.rb', line 101

def has_modifier?
  @modifier && !@modifier.blank?
end

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

Defaults to pot_gained_chips?. Defaults to the value of player_sees_wager?.

Parameters:

  • pot_gained_chips (Boolean) (defaults to: pot_gained_chips?, )

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

  • player_sees_wager (Boolean) (defaults to: player_sees_wager?) )

    Whether or not the player is reacting to a wager.

Returns:

  • (String)

    String representation of this action.



86
87
88
89
90
91
92
93
94
95
96
# File 'lib/acpc_poker_types/poker_action.rb', line 86

def to_s(pot_gained_chips: pot_gained_chips?, player_sees_wager: player_sees_wager?)
  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