-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplaybot.py
211 lines (189 loc) · 6.2 KB
/
playbot.py
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
import random
from math import ceil
def botp(player,pos,first_moves,second_moves):
bank = 100
win = True
first_wins = []
for a, b in zip(first_moves, second_moves):
if a == b:
if win:
first_wins.append(a)
else:
first_wins.append(0)
win = not win
elif a > b:
first_wins.append(a)
else:
first_wins.append(0)
fw = win
win = False
second_wins = []
for a, b in zip(second_moves, first_moves):
if a == b:
if win:
second_wins.append(a)
else:
second_wins.append(0)
win = not win
elif a > b:
second_wins.append(a)
else:
second_wins.append(0)
sw = win
win = fw if player == 1 else sw
tw = 0 if win else 1
# money = []
# money.append(bank - sum(x) for x in first_wins)
# money.append(bank - sum(x) for x in second_wins)
# my_money = money[player - 1]
# their_money = money[player % 2]
if player == 1:
my_money = bank - sum(first_wins)
their_money = bank - sum(second_wins)
else:
their_money = bank - sum(first_wins)
my_money = bank - sum(second_wins)
if my_money == 0:
return 0
# print(my_money)
f = min(my_money, their_money)
maxp = 9 if player == 1 else 1
maxp0 = 10 if player == 1 else 0
if maxp + pos == 10:
return max(1, my_money)
elif maxp == pos:
return max(1, min(my_money, their_money + tw))
pf = 0.9
dist = abs(maxp0 - pos)
fact = [(1 / (i ** pf)) for i in range(1, dist + 1)]
coeff = sum(fact)
mu = f / (coeff * (dist ** pf))
mu += tw
if len(first_moves) == 0:
if player == 1:
return 13
else:
return 14
if len(first_moves) == 1:
if win:
return 12
else:
return 13
return max(1, min(my_money, int(round(mu))))
#THE SIMULATOR CODE
player1=100
player2=100
first_moves=[]
second_moves=[]
pos=5
draw123=0
play1=1
play2=2
print("You want to go first or second?")
pid = int(input())
if pid == 1:
while pos!=0 or pos!=10:
# bid1=calculate_bid_player1(play1,pos,first_moves,second_moves)
# bid2=calculate_bid_player2(play2,pos,first_moves,second_moves)
print("Enter your bid?")
bid1 = int(input())
bid2=botp(2,pos,first_moves,second_moves)
if bid1 > player1:
print("PLAYER 1 has made a wrong bet")
print("PLAYER 2 BOT WINS")
break
if bid2 > player2:
print("PLAYER 2 BOT has made a wrong bet")
print("PLAYER 1 WINS")
break
first_moves.append(int(bid1))
second_moves.append(int(bid2))
i=len(first_moves)-1
if first_moves[i]>second_moves[i]:
player1-=first_moves[i]
pos-=1
elif first_moves[i]<second_moves[i]:
player2-=second_moves[i]
pos+=1
else:
if draw123%2==0:
player1-=first_moves[i]
pos-=1
else:
player2-=second_moves[i]
pos+=1
draw123+=1
print("Player1 Bid : ",first_moves[i],"\tPlayer1 Balance : ",player1)
print("Player2 BOT Bid : ",second_moves[i],"\tPlayer2 BOT Balance : ",player2)
print("Position : ",pos)
print("")
if pos==0:
print("PLAYER 1 WINS")
break
if pos==10:
print("PLAYER 2 BOT WINS")
break
if (player2>0 and second_moves[i]<=0) or second_moves[i]<0 or (second_moves[i]>player2+second_moves[i]):
print("PLAYER 2 BOT has made a wrong bet")
print("PLAYER 1 WINS")
break
if (player1>0 and first_moves[i]<=0) or first_moves[i]<0 or (first_moves[i]>player1+first_moves[i]):
print("PLAYER 1 has made a wrong bet")
print("PLAYER 2 BOT WINS")
break
if player1==0 and player2==0:
print("Draw")
break
elif pid == 2:
while pos!=0 or pos!=10:
# bid1=calculate_bid_player1(play1,pos,first_moves,second_moves)
# bid2=calculate_bid_player2(play2,pos,first_moves,second_moves)
print("Enter your bid?")
bid2= int(input())
bid1 = botp(1,pos,first_moves,second_moves)
if bid1 > player1:
print("PLAYER 1 BOT has made a wrong bet")
print("PLAYER 2 WINS")
break
if bid2 > player2:
print("PLAYER 2 has made a wrong bet")
print("PLAYER 1 BOT WINS")
break
first_moves.append(int(bid1))
second_moves.append(int(bid2))
i=len(first_moves)-1
if first_moves[i]>second_moves[i]:
player1-=first_moves[i]
pos-=1
elif first_moves[i]<second_moves[i]:
player2-=second_moves[i]
pos+=1
else:
if draw123%2==0:
player1-=first_moves[i]
pos-=1
else:
player2-=second_moves[i]
pos+=1
draw123+=1
print("Player1 BOT Bid : ",first_moves[i],"\tPlayer1 BOT Balance : ",player1)
print("Player2 Bid : ",second_moves[i],"\tPlayer2 Balance : ",player2)
print("Position : ",pos)
print("")
if pos==0:
print("PLAYER 1 BOT WINS")
break
if pos==10:
print("PLAYER 2 WINS")
break
if (player2>0 and second_moves[i]<=0) or second_moves[i]<0 or (second_moves[i]>player2+second_moves[i]):
print("PLAYER 2 has made a wrong bet")
print("PLAYER 1 BOT WINS")
break
if (player1>0 and first_moves[i]<=0) or first_moves[i]<0 or (first_moves[i]>player1+first_moves[i]):
print("PLAYER 1 BOT has made a wrong bet")
print("PLAYER 2 WINS")
break
if player1==0 and player2==0:
print("Draw")
break