1d0tkn0w v2

This program has been disqualified.


AuthorDhairya Jain
Submission date2019-06-02 14:11:04.183339
Rating6042
Matches played143
Win rate60.14

Source code:

import random
beat = {"R": "P", "P": "S", "S": "R"}

def stat_update_helper(stat_ref):
  global human_choice
  global comp_choice
  print human_choice
  if human_choice[-2][1] == stat_ref:
    if beat[comp_choice[-2][0]] == human_choice[-1][0]:
      stats[stat_ref][1] += aggression
    elif comp_choice[-2][0] == human_choice[-1][0]:
      stats[stat_ref][0] += aggression
    else:
      stats[stat_ref][2] += aggression

def stat_update():
  stat_update_helper("win")
  stat_update_helper("draw")
  stat_update_helper("lose")

def weight():
  global r_weight
  global p_weight
  global s_weight
  global human_choice
  if human_choice[-1] == ["R", "win"]:
    r_weight = float(stats["win"][0]) / sum(stats["win"])
    p_weight = float(stats["win"][1]) / sum(stats["win"])
    s_weight = float(stats["win"][2]) / sum(stats["win"])
  elif human_choice[-1] == ["P", "win"]:
    r_weight = float(stats["win"][2]) / sum(stats["win"])
    p_weight = float(stats["win"][0]) / sum(stats["win"])
    s_weight = float(stats["win"][1]) / sum(stats["win"])
  elif human_choice[-1] == ["S", "win"]:
    r_weight = float(stats["win"][1]) / sum(stats["win"])
    p_weight = float(stats["win"][2]) / sum(stats["win"])
    s_weight = float(stats["win"][0]) / sum(stats["win"])
  
  elif human_choice[-1] == ["R", "draw"]:
    r_weight = float(stats["draw"][2]) / sum(stats["draw"])
    p_weight = float(stats["draw"][0]) / sum(stats["draw"])
    s_weight = float(stats["draw"][1]) / sum(stats["draw"])
  elif human_choice[-1] == ["P", "draw"]:
    r_weight = float(stats["draw"][1]) / sum(stats["draw"])
    p_weight = float(stats["draw"][2]) / sum(stats["draw"])
    s_weight = float(stats["draw"][0]) / sum(stats["draw"])
  elif human_choice[-1] == ["S", "draw"]:
    r_weight = float(stats["draw"][0]) / sum(stats["draw"])
    p_weight = float(stats["draw"][1]) / sum(stats["draw"])
    s_weight = float(stats["draw"][2]) / sum(stats["draw"])

  elif human_choice[-1] == ["R", "lose"]:
    r_weight = float(stats["lose"][1]) / sum(stats["lose"])
    p_weight = float(stats["lose"][2]) / sum(stats["lose"])
    s_weight = float(stats["lose"][0]) / sum(stats["lose"])
    #print r_weight, p_weight, s_weight
  elif human_choice[-1] == ["P", "lose"]:
    r_weight = float(stats["lose"][0]) / sum(stats["lose"])
    p_weight = float(stats["lose"][1]) / sum(stats["lose"])
    s_weight = float(stats["lose"][2]) / sum(stats["lose"])
  elif human_choice[-1] == ["S", "lose"]:
    r_weight = float(stats["lose"][2]) / sum(stats["lose"])
    p_weight = float(stats["lose"][0]) / sum(stats["lose"])
    s_weight = float(stats["lose"][1]) / sum(stats["lose"])
def logic(comp, human):
  global human_choice
  global comp_choice
  if comp == human:
    human_choice.append([human, "draw"])
    comp_choice.append([comp, "draw"])
  elif beat[comp] == human:
    human_choice.append([human, "win"])
    comp_choice.append([comp, "lose"])
  elif beat[human] == comp:
    human_choice.append([human, "lose"])
    comp_choice.append([comp, "win"])

if not input:
    stats = {"win": [1, 1, 1], "draw": [1, 1, 1], "lose": [1, 1, 1]}
    r_weight = 0
    p_weight = 0
    s_weight = 0
    aggression = 1
    human_choice = []
    comp_choice = []
    comp_input = random.choice(["R", "P", "S"])
    logic_x = logic(comp_input, random.choice(["R", "P", "S"]))
    logic_x = logic(comp_input, random.choice(["R", "P", "S"]))
    kill = True
else:
  if len(human_choice) == 4 and kill:
    human_choice = human_choice[-2:]
    comp_choice = comp_choice[-2:]
    kill = False
  stat_update()
  weight()
  human_input = input
  comp_input = random.choice(list("R" * int(round(r_weight * 100)) + "P" * int(round(p_weight * 100)) + "S" * int(round(s_weight * 100))))
  logic_x = logic(comp_input, human_input)
output = str(comp_input)