Author | Prakhar |
Submission date | 2019-05-07 02:42:50.088787 |
Rating | 2538 |
Matches played | 244 |
Win rate | 25.0 |
Use rpsrunner.py to play unranked matches on your computer.
import random
def back_move(move):
if move == 1:
return 3
elif move == 2:
return 1
else:
return 3
def front_move(move):
if move == 1:
return 2
elif move == 2:
return 3
else:
return 1
def pakkhu_think(chances,human_moves_arr,result_arr,draw_rep_arr,lose_rep_arr,win_rep_arr,rep_arr,repi,win_repi,lose_repi,draw_repi,o,p,q):
n = random.randint(1, 3) - 1
if chances == 0 or chances == 1 or chances == 2 or chances == 3 or chances==4 or chances==5:
return random.randint(1, 3)
else:
if chances==0:
chances+=1
else:
o = strat_1_func()
p = strat_2_func()
q = strat_3_func()
if strat_1 == strat_2 and strat_2 == strat_3:
if n == 0:
last_strat_used = 1
return o
elif n == 1:
last_strat_used = 2
return p
else:
last_strat_used = 3
return q
elif strat_1 == strat_2 and strat_3 < strat_1:
n = random.randint(0, 1)
if n == 0:
last_strat_used = 1
return o
else:
last_strat_used = 2
return p
elif strat_1 == strat_3 and strat_2 < strat_1:
n = random.randint(0, 1)
if n == 0:
last_strat_used = 1
return o
else:
last_strat_used = 3
return q
elif strat_3 == strat_2 and strat_1 < strat_3:
n = random.randint(0, 1)
if n == 0:
last_strat_used = 3
return q
else:
last_strat_used = 2
return p
elif strat_1 > strat_2 and strat_1 > strat_3:
last_strat_used = 1
return o
elif strat_2 > strat_3:
last_strat_used = 2
return p
else:
last_strat_used = 3
return q
def strat_1_func():
if result_arr[chances - 1] == 0:
best_move = find_pattern(draw_rep_arr, draw_repi, 0)
elif result_arr[chances - 1] == -1:
best_move = find_pattern(lose_rep_arr, lose_repi, -1)
else:
best_move = find_pattern(win_rep_arr, win_repi, 1)
return best_move
def strat_3_func():
return find_pattern(rep_arr, repi, 4)
def strat_2_func():
d = human_moves_arr[chances - 1]
a = 0
b = 0
c = 0
for i in range(chances - 2, -1, -1):
if (i + 1) <= chances - 1 and human_moves_arr[i] == d:
if human_moves_arr[i + 1] == 1:
a += 2*(round(i+3)/3)
elif human_moves_arr[i + 1] == 2:
b += i*i
else:
c += i*i
if a >= b and a >= c:
return 2
elif b >= c:
return 3
else:
return 1
def find_pattern(arr, n, q):
c = 0
d = 0
if n >= 2:
a = arr[n - 1]
b = arr[n - 2]
i = n - 3
while (i >= 0):
if arr[i] == b and arr[i + 1] == a:
if i + 3 <= n and arr[i + 3] == 1:
c += i*i
elif i + 3 <= n and arr[i + 3] == 0:
d += i*i
i -= 1
if d >= c:
return front_move(human_moves_arr[chances - 1])
else:
return back_move(human_moves_arr[chances - 1])
else:
if arr[n - 1] == 1:
return front_move(human_moves_arr[chances - 1])
else:
return back_move(human_moves_arr[chances - 1])
if input == "":
last_strat_used = 0
chances = 0
strat_1 = 0
strat_2 = 0
strat_3 = 0
repi = 0
draw_repi = 0
win_repi = 0
lose_repi = 0
o = 0
p = 0
q = 0
human_moves_arr = [0]*1001
result_arr = [0]*1001
rep_arr = [0]*1001
draw_rep_arr = [0]*1001
win_rep_arr = [0]*1001
lose_rep_arr = [0]*1001
else:
chances+=1
if input == "R":
human_moves_arr[chances-1] = 1
if o==2:
strat_1+=2
elif o==3:
strat_1-=3
if p==2:
strat_2+=2
elif p==3:
strat_2-=3
if q==2:
strat_3+=2
elif q==3:
strat_3-=3
if game_move==1:
result_arr[chances-1] = 0
elif game_move==2:
result_arr[chances-1] = 1
else:
result_arr[chances-1] = -1
elif input == "P":
human_moves_arr[chances-1] = 2
if o==3:
strat_1+=2
elif o==1:
strat_1-=3
if p==3:
strat_2+=2
elif p==1:
strat_2-=3
if q==3:
strat_3+=2
elif q==1:
strat_3-=3
if game_move==1:
result_arr[chances-1] = -1
elif game_move==2:
result_arr[chances-1] = 0
else:
result_arr[chances-1] = 1
elif input == "S":
human_moves_arr[chances-1] = 3
if o==1:
strat_1+=2
elif o==2:
strat_1-=3
if p==1:
strat_2+=2
elif p==2:
strat_2-=3
if q==1:
strat_3+=2
elif q==2:
strat_3-=3
if game_move==1:
result_arr[chances-1] = 1
elif game_move==2:
result_arr[chances-1] = -1
else:
result_arr[chances-1] = 0
if chances >= 2:
if result_arr[chances - 1] == 0:
if human_moves_arr[chances - 2] == human_moves_arr[chances - 1]:
draw_rep_arr[draw_repi] = 1
else:
draw_rep_arr[draw_repi] = 0
draw_repi += 1
elif result_arr[chances - 1] == -1:
if human_moves_arr[chances - 2] == human_moves_arr[chances - 1]:
lose_rep_arr[lose_repi] = 1
else:
lose_rep_arr[lose_repi] = 0
lose_repi += 1
else:
if human_moves_arr[chances - 2] == human_moves_arr[chances - 1]:
win_rep_arr[win_repi] = 1
else:
win_rep_arr[win_repi] = 0
win_repi += 1
if human_moves_arr[chances - 1] == human_moves_arr[chances - 2]:
rep_arr[repi] = 1
else:
rep_arr[repi] = 0
repi += 1
game_move = pakkhu_think(chances,human_moves_arr,result_arr,draw_rep_arr,lose_rep_arr,win_rep_arr,rep_arr,repi,win_repi,lose_repi,draw_repi,o,p,q)
if game_move==1:
output = "R"
elif game_move==2:
output = "P"
else:
output = "S"