Class: 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'}
Set.new LEGAL_ACTIONS.keys
Set.new LEGAL_ACTIONS.keys.map { |action| action.to_s }
Set.new LEGAL_ACTIONS.values
MODIFIABLE_ACTIONS =

Returns Representations of the legal ACPC action characters that may be accompanied by a modifier.

Returns:

  • (Hash<Symbol, String>)

    Representations of the legal ACPC action characters that may be accompanied by a modifier.

LEGAL_ACTIONS.select { |sym, char| 'r' == char || 'b' == char }
HIGH_RESOLUTION_ACTION_CONVERSION =

Returns Map of general actions to more specific actions (e.g. call to check and raise to bet).

Returns:

  • (Hash)

    Map of general actions to more specific actions (e.g. call to check and raise to bet).

{call: :check, raise: :bet, fold: :fold, check: :check, bet: :bet}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(action, context = {}) ⇒ PokerAction

Returns a new instance of PokerAction.

Parameters:

  • action (Symbol, String)

    A representation of this action.

  • context (Hash) (defaults to: {})

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

Raises:

  • IllegalPokerAction



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/acpc_poker_types/poker_action.rb', line 40

def initialize(action, context={})
  (@symbol, @modifier) = validate_action(
    action, 
    context[:modifier], 
    if context[:acting_player_sees_wager].nil?
      true
    else
      context[:acting_player_sees_wager]
    end
  )
  @amount_to_put_in_pot = context[:amount_to_put_in_pot].to_i
end

Instance Attribute Details

#amount_to_put_in_potObject (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:

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



13
14
15
# File 'lib/acpc_poker_types/poker_action.rb', line 13

def amount_to_put_in_pot
  @amount_to_put_in_pot
end

#modifierObject (readonly)

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

Returns:

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



16
17
18
# File 'lib/acpc_poker_types/poker_action.rb', line 16

def modifier
  @modifier
end

Instance Method Details

#==(other_action) ⇒ Object



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

def ==(other_action)
  to_sym == other_action.to_sym && to_s == other_action.to_s && to_acpc == other_action.to_acpc && @modifier == other_action.modifier
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.



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

def has_modifier?
  !@modifier.nil?
end

#to_acpcString

Returns Full ACPC representation of this action.

Returns:

  • (String)

    Full ACPC representation of this action.



73
74
75
# File 'lib/acpc_poker_types/poker_action.rb', line 73

def to_acpc
  LEGAL_ACTIONS[@symbol] + @modifier.to_s
end

#to_acpc_characterString

Returns ACPC character representation of this action.

Returns:

  • (String)

    ACPC character representation of this action.



78
79
80
# File 'lib/acpc_poker_types/poker_action.rb', line 78

def to_acpc_character
  LEGAL_ACTIONS[@symbol]
end

#to_sString

Returns String representation of this action.

Returns:

  • (String)

    String representation of this action.



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

def to_s
  @symbol.to_s + @modifier.to_s
end

#to_symSymbol

Returns:

  • (Symbol)


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

def to_sym
  @symbol
end