class RubyHoldem::Round::MoveValidator

Attributes

move[R]
round[R]

Public Class Methods

new(round, move) click to toggle source
# File lib/ruby_holdem/round/move_validator.rb, line 6
def initialize(round, move)
  @round = round
  @move = move
end

Public Instance Methods

validate() click to toggle source
# File lib/ruby_holdem/round/move_validator.rb, line 11
def validate
  if blinds_turn? && blinds_not_met?
    raise MinRaiseNotMeet, "You must bet blinds."
  end

  send("validate_#{move_type}")
end

Private Instance Methods

amount() click to toggle source

Dependencies on MoveFactory

# File lib/ruby_holdem/round/move_validator.rb, line 97
def amount
  move[:amount]
end
big_blinds() click to toggle source
# File lib/ruby_holdem/round/move_validator.rb, line 83
def big_blinds
  @big_blinds ||= round.big_blinds
end
blinds_not_met?() click to toggle source
# File lib/ruby_holdem/round/move_validator.rb, line 60
def blinds_not_met?
  if turns_played == 0
    amount < small_blinds
  elsif turns_played == 1
    amount < big_blinds
  end
end
blinds_turn?() click to toggle source
# File lib/ruby_holdem/round/move_validator.rb, line 56
def blinds_turn?
  turns_played == 0 || turns_played == 1
end
current_bet_amount() click to toggle source

Dependencies on Player class

# File lib/ruby_holdem/round/move_validator.rb, line 90
def current_bet_amount
  @current_bet_amount ||= player.current_bet_amount
end
highest_bet_placed() click to toggle source

Dependencies on Round class

# File lib/ruby_holdem/round/move_validator.rb, line 71
def highest_bet_placed
  @highest_bet_placed ||= round.highest_bet_placed
end
min_raise_amount() click to toggle source
# File lib/ruby_holdem/round/move_validator.rb, line 47
def min_raise_amount
  @min_raise_amount ||= highest_bet_placed - current_bet_amount
end
move_type() click to toggle source
# File lib/ruby_holdem/round/move_validator.rb, line 101
def move_type
  move[:move_type]
end
player() click to toggle source
# File lib/ruby_holdem/round/move_validator.rb, line 105
def player
  move[:player]
end
player_can_afford_raise?() click to toggle source

TODO:

# File lib/ruby_holdem/round/move_validator.rb, line 52
def player_can_afford_raise?
  true
end
small_blinds() click to toggle source
# File lib/ruby_holdem/round/move_validator.rb, line 79
def small_blinds
  @small_blinds ||= round.small_blinds
end
turns_played() click to toggle source
# File lib/ruby_holdem/round/move_validator.rb, line 75
def turns_played
  @turns_played ||= round.turns_played
end
validate_call() click to toggle source
# File lib/ruby_holdem/round/move_validator.rb, line 31
def validate_call
  if !player_can_afford_raise?
    raise InsufficientFunds
  end
end
validate_check() click to toggle source
# File lib/ruby_holdem/round/move_validator.rb, line 37
def validate_check
  if min_raise_amount > 0
    raise MinRaiseNotMeet
  end
end
validate_fold() click to toggle source
# File lib/ruby_holdem/round/move_validator.rb, line 43
def validate_fold
  true # NOTE: You can always fold as long as its not a blinds turn
end
validate_raise() click to toggle source
# File lib/ruby_holdem/round/move_validator.rb, line 21
def validate_raise
  if amount < min_raise_amount
    raise MinRaiseNotMeet
  end

  if !player_can_afford_raise?
    raise InsufficientFunds
  end
end