-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient_bot.rb
154 lines (137 loc) · 4.95 KB
/
client_bot.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
require 'net/http'
require 'json'
#############################################################
print "Name: "
name = gets.chomp
print "ID: "
game_id = gets.chomp
begin
hostname = "localhost"; port = "3000"
# url = URI.parse("http://enovapoker.herokuapp.com/")
url = URI.parse("http://localhost:3000/")
response = Net::HTTP.post_form(url, {:name => name, :game_id => game_id})
resp = JSON.parse(response.body)
if resp.has_key?("player_key")
puts "Your player key: #{resp["player_key"]}"
player_key = resp["player_key"]
else
puts resp["message"]
end
rescue
puts "Did not connect"
end
#############################################################
#
# print "Name: "
# name = gets.chomp
# print "ID: "
# game_id = gets.chomp
# print "Player Key: "
# player_key = gets.chomp
#
#############################################################
play = true
state = nil
betting_summary = nil
replacement_summary = nil
last_summary = nil
while play
# uri = URI('http://enovapoker.herokuapp.com/game_state')
uri = URI('http://localhost:3000/game_state')
uri.query = URI.encode_www_form({:name => name, :game_id => game_id, :player_key => player_key})
res = Net::HTTP.get_response(uri)
answer = JSON.parse(res.body)
if answer["play"] && answer["replacement"]
state = nil
puts "----------------------------------------------"
puts "Replacement Round"
puts
if answer["replacement_summary"] != [] then puts answer["replacement_summary"]; puts; end
puts "Your hand: #{answer["hand"]}"
puts "Type which cards you want to replace."
puts "0 for no replacement. Type 13 to replace 1st and 3rd card."
puts ">> 0"
play = 0
# url = URI('http://enovapoker.herokuapp.com/player')
url = URI('http://localhost:3000/player')
response = Net::HTTP.post_form(url, {:name => name, :game_id => game_id, :player_key => player_key, :player_action => "replacement", :parameters => play})
puts
puts "----------------------------------------------"
elsif answer["play"]
state = nil
if last_summary != answer["round_summary"] && answer["round_summary"] != [[], []] && answer["round_summary"] != []
puts answer["betting_summary"]
puts " "
puts "Hand Ended"
puts answer["round_summary"]
puts "==========================================="
puts "New Hand"
puts " "
last_summary = answer["round_summary"]
end
puts "----------------------------------------------"
puts "Betting Round"
puts
if answer["betting_summary"] != [] then puts answer["betting_summary"]; puts; end
puts "Your hand: #{answer["hand"]}"
puts "There are #{answer["pot"]} chips in the pot."
puts "The minimum amount to play is #{answer["min_bet"]}."
puts "You have bet #{answer["bet"]} chips and you have #{answer["stack"]} chips in your stack."
if answer["bet"] != answer["min_bet"]
puts "Maximum Raise: #{answer["max_raise"]}"
puts "Will you call, raise, or fold?"
#number = Random.new.rand(0..3)
#if number == 0 then play = "fold" else play = "call" end
play = "call"
else
puts "Maximum Bet: #{answer["max_bet"]}"
puts "Will you check, bet, or fold?"
max = answer["max_bet"].to_i
play = "bet #{Random.new.rand(0..max/3)}"
end
# print ">> "
# play = gets.chomp
puts ">> #{play}"
# url = URI('http://enovapoker.herokuapp.com/player')
url = URI('http://localhost:3000/player')
response = Net::HTTP.post_form(url, {:name => name, :game_id => game_id, :player_key => player_key, :player_action => play.split(" ")[0], :parameters => play.split(" ")[1]})
puts
puts "----------------------------------------------"
elsif answer["game_over"] == true
puts answer["round_summary"]
puts
puts answer["winning_summary"]
play = false
else
if answer["current_player"] && answer["replacement"]
current_state = "#{answer["current_player"]} is replacing cards."
elsif answer["current_player"]
current_state = "#{answer["current_player"]} is betting."
elsif answer["waiting"]
current_state = answer["message"]
# if answer["round_summary"] then round_summary = answer["round_summary"] end
else
current_state = answer["message"]
end
#
# if answer["round_summary"] != nil
# round_summary = answer["round_summary"]
# end
if state != current_state # Stop repetition of same phrase
puts current_state
state = current_state
end
if last_summary != answer["round_summary"] && answer["round_summary"] != [[], []] && answer["round_summary"] != []
puts answer["betting_summary"]
puts " "
puts "Hand Ended"
puts answer["round_summary"]
puts "==========================================="
puts "New Hand"
puts " "
last_summary = answer["round_summary"]
state = nil
end
end
sleep 3
end