Class: Ventiuna::Player
- Inherits:
-
Object
- Object
- Ventiuna::Player
- Defined in:
- lib/ventiuna/player.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#balance ⇒ Object
Returns the value of attribute balance.
-
#bet ⇒ Object
Returns the value of attribute bet.
-
#decisions ⇒ Object
readonly
Returns the value of attribute decisions.
-
#hands ⇒ Object
Returns the value of attribute hands.
-
#loses ⇒ Object
Returns the value of attribute loses.
-
#name ⇒ Object
Returns the value of attribute name.
-
#ties ⇒ Object
Returns the value of attribute ties.
-
#wins ⇒ Object
Returns the value of attribute wins.
Instance Method Summary collapse
- #active_hand ⇒ Object (also: #hand)
- #decision(dealers_card, strategy: "interactive") ⇒ Object
-
#initialize(name, strategy: "Learning", balance: 1000000.0) ⇒ Player
constructor
A new instance of Player.
- #loses_percent ⇒ Object
- #place_bet(min_bet, max_bet) ⇒ Object
- #reset_decisions ⇒ Object
- #reset_hands ⇒ Object (also: #reset_hand)
- #stats ⇒ Object
- #ties_percent ⇒ Object
- #total_rounds ⇒ Object
- #wins_percent ⇒ Object
Constructor Details
#initialize(name, strategy: "Learning", balance: 1000000.0) ⇒ Player
Returns a new instance of Player.
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/ventiuna/player.rb', line 6 def initialize(name, strategy: "Learning", balance: 1000000.0) @name = name @strategy = Ventiuna::Strategy.find_or_create_by_name(strategy) @balance = balance @hands = [Ventiuna::Hand.new] @bet = 0 @wins = 0 @loses = 0 @ties = 0 @decisions = Hash.new([]) end |
Instance Attribute Details
#balance ⇒ Object
Returns the value of attribute balance.
3 4 5 |
# File 'lib/ventiuna/player.rb', line 3 def balance @balance end |
#bet ⇒ Object
Returns the value of attribute bet.
3 4 5 |
# File 'lib/ventiuna/player.rb', line 3 def bet @bet end |
#decisions ⇒ Object (readonly)
Returns the value of attribute decisions.
4 5 6 |
# File 'lib/ventiuna/player.rb', line 4 def decisions @decisions end |
#hands ⇒ Object
Returns the value of attribute hands.
3 4 5 |
# File 'lib/ventiuna/player.rb', line 3 def hands @hands end |
#loses ⇒ Object
Returns the value of attribute loses.
3 4 5 |
# File 'lib/ventiuna/player.rb', line 3 def loses @loses end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/ventiuna/player.rb', line 3 def name @name end |
#ties ⇒ Object
Returns the value of attribute ties.
3 4 5 |
# File 'lib/ventiuna/player.rb', line 3 def ties @ties end |
#wins ⇒ Object
Returns the value of attribute wins.
3 4 5 |
# File 'lib/ventiuna/player.rb', line 3 def wins @wins end |
Instance Method Details
#active_hand ⇒ Object Also known as: hand
46 47 48 |
# File 'lib/ventiuna/player.rb', line 46 def active_hand hands.select{ |h| h.active? }.first end |
#decision(dealers_card, strategy: "interactive") ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/ventiuna/player.rb', line 56 def decision(dealers_card, strategy: "interactive") define_posible_moves(dealers_card) can_split = hands.size == 1 #d = @strategy.decision(dealers_card, hand, can_split) d = nil unless d d = "s" case strategy when "random" d = random_strategy when "interactive" d = interactive end end move = Ventiuna::Move.find_by_strategy_id_and_dealers_card_value_and_hand_and_decision(@strategy.id, dealers_card.value, hand.to_db, d) #puts move.inspect @decisions[hand] = decisions[hand] << move #puts @decisions d end |
#loses_percent ⇒ Object
27 28 29 30 |
# File 'lib/ventiuna/player.rb', line 27 def loses_percent return 0 if total_rounds == 0 (self.loses.to_f/self.total_rounds) * 100 end |
#place_bet(min_bet, max_bet) ⇒ Object
41 42 43 44 |
# File 'lib/ventiuna/player.rb', line 41 def place_bet(min_bet, max_bet) @bet = min_bet @balance -= @bet end |
#reset_decisions ⇒ Object
78 79 80 |
# File 'lib/ventiuna/player.rb', line 78 def reset_decisions @decisions = Hash.new([]) end |
#reset_hands ⇒ Object Also known as: reset_hand
51 52 53 |
# File 'lib/ventiuna/player.rb', line 51 def reset_hands @hands = [Ventiuna::Hand.new] end |
#stats ⇒ Object
18 19 20 |
# File 'lib/ventiuna/player.rb', line 18 def stats "Wins: #{self.wins} (#{self.wins_percent.round}%), Loses: #{self.loses} (#{self.loses_percent.round}%), Ties: #{self.ties} (#{self.ties_percent.round}%)" end |
#ties_percent ⇒ Object
32 33 34 35 |
# File 'lib/ventiuna/player.rb', line 32 def ties_percent return 0 if total_rounds == 0 (self.ties.to_f/self.total_rounds) * 100 end |
#total_rounds ⇒ Object
37 38 39 |
# File 'lib/ventiuna/player.rb', line 37 def total_rounds @wins+@loses+@ties end |
#wins_percent ⇒ Object
22 23 24 25 |
# File 'lib/ventiuna/player.rb', line 22 def wins_percent return 0 if total_rounds == 0 (self.wins.to_f/self.total_rounds) * 100 end |