Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions lib/pip_ai/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def initialize(value)
end

def win_ratio
1 if @losses == 0
@wins / @losses
end

Expand All @@ -20,9 +21,9 @@ def lose
@losses += 1
end

def hit?
win_ratio > 0.5
def stand?
win_ratio > 0.25
end
end
end
end
end
47 changes: 47 additions & 0 deletions players/pip_adaptive.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,57 @@
require "yaml"
require 'pip_ai/node'

=begin
Blackjack AI (Adaptive 1)
---------------------

This AI (Adaptive 1) only makes decisions based on it's own cards, ignoring the dealer completely other than to hit or stand.

Method: Each iteration, the AI references a tree of old hands to see whether to hit, stand, or split (split not implemented).

Hand storage tree:

root
/ \
A 2 ....
/ \ ....
A 2

Each node has a hash of children, as well as containing a win number and loss number. Children will automatically be created if the hand has never been played.

Rules:
If the hand has never been played, stand.
If the win ratio (win number/loss number) is high, stand.
Else, hit.

Possible extra strategies: check avg. win ratio of children, if it is higher then hit.
=end

module ScriptWarsBlackjack
module Players
# Pip - By user

class Pip
include PipAI

def initialize()
@storage_path = File.expand_path("../pip_adaptive_1_storage.yml", __FILE__)
@data = {}
save_data(@storage_path)
File.new(@storage_path) unless File.exists?(@storage_path)
load_data(@storage_path)
end

def load_data(yml_file)
@data = YAML.load(File.open(yml_file))
end

def save_data(yml_file)
File.open(yml_file, "w") do |file|
file.write(@data.to_yaml)
end
end

def place_bet(game_state)
# Return your integer bet
0
Expand Down
1 change: 1 addition & 0 deletions players/pip_adaptive_1_storage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--- {}