1d0tkn0w

This program has been disqualified.


AuthorDhairya Jain
Submission date2019-06-02 10:31:18.373413
Rating4707
Matches played125
Win rate48.0

Source code:

import random
beat = {"R": "P", "P": "S", "S": "R"}
# same, winning against comp, losing against comp

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"])
    #print r_weight, p_weight, s_weight
  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"])
    #print r_weight, p_weight, s_weight
  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"])
    #print r_weight, p_weight, s_weight
  
  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"])
    #print r_weight, p_weight, s_weight
  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"])
    #print r_weight, p_weight, s_weight
  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"])
    #print r_weight, p_weight, s_weight

  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"])
    return "draw"
  elif beat[comp] == human:
    human_choice.append([human, "win"])
    comp_choice.append([comp, "lose"])
    return "lose"
  elif beat[human] == comp:
    human_choice.append([human, "lose"])
    comp_choice.append([comp, "win"])
    return "win"

score = {"computer": 0, "human": 0}
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 = 2
    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"]))
else:
  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)