The Twenty-First Dynasty of Josh/Estate Agent Wrestling Simulator

From BlogNomic Wiki
Revision as of 23:13, 16 September 2023 by Bucky (talk | contribs) (Proposal "Sporting Tweaks"; equivalent behavior could be gotten from the old version by setting josh_minimum=False)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

# Code by Bucky # Implements ruleset revision 24507 with an additional 9999 round limit # Usage example: python AgentWrestling.py "I. O. Yoo" "I. M. Eyeron" TKPTM MGGGL Hyped:R import random from collections import defaultdict moves = ["P","K","G","L","T","M"] move_names = {"P": "Punch", "K": "Kick", "G": "Grapple", "L": "Leap", "T": "Taunt", "M": "Miss"} def fight_die(): return random.choice(moves) def one_round_moves(n=5, over=False, hyped=False): r = "" if over: n -= 1 r = "M" for i in range(n): attempt = fight_die() while attempt == "M" and hyped and "M" in r: attempt = fight_die() print("The hype prevents a miss. "+move_names[attempt]+" instead.") r += attempt return r def generate_finishing_move(): r = "MMMMM" while r.count("M") > 1: r = one_round_moves() return r def bin_moves(move_list): r = defaultdict(int) for m in move_list: if m in moves: r[m] += 1 else: print("Warning: "+m+" is not a valid move") return r def score(name, moves, finishing_move, verbose=True, josh_minimum=False): binned = bin_moves(moves) c = 0 if binned["P"] >= 2: c += 1 if verbose: print(name + " gets 1 contribution for a pair of Punches!") if binned["K"] >= 2: c += 1 if(verbose): print(name + " gets 1 contribution for a pair of Kicks!") if binned["G"] >= 2: c += 1 if verbose: print(name + " gets 1 contribution for a pair of Grapples!") if binned["L"] >= 3 and binned["P"] + binned["K"] + binned["G"] > 0: c += 3 if verbose: print(name + " gets 3 contribution for landing a triple jump attack!") if sorted(moves) == sorted(finishing_move): c += 5 if verbose: print(name + " executes a Finishing Move! "+finishing_move+"! " + name + " gets 5 contribution.") if c >= 1 and binned["T"] > 0: c += 1 if verbose: print(name + " gets 1 contribution for a Taunt afterwards.") if binned["L"] >= 3 and binned["P"] + binned["K"] + binned["G"] == 0: c -= 3 if verbose: print(name + " loses 3 contribution for failing a triple jump attack!") return max(c, 0) def wrestle(left_name, right_name, left_finishing_move, right_finishing_move, meddlings=""): _round_limit = 9999 round_number = 1 left_contribution = right_contribution = 0 win_by_points = False left_over = "Over:L" in meddlings right_over = "Over:R" in meddlings left_hype = "Hyped:L" in meddlings right_hype = "Hyped:R" in meddlings print(left_name + " enters the arena with the finishing move " + left_finishing_move) print(right_name + " enters the arena with the finishing move " + right_finishing_move) while round_number <= _round_limit and not win_by_points: print(" \n Round "+str(round_number)+"!!") left_moves = one_round_moves(over=left_over, hyped=left_hype) print(left_name+" uses the combo "+left_moves) c = score(left_name, left_moves, left_finishing_move) left_contribution += c print(left_name+" gains "+str(c)+" contribution this round for a total of "+str(left_contribution)) right_moves = one_round_moves(over=right_over, hyped=right_hype) print(right_name + " uses the combo " + right_moves) c = score(right_name, right_moves, right_finishing_move) right_contribution += c print(right_name+" gains "+str(c)+" contribution this round for a total of "+str(right_contribution)) if (left_contribution >= 10 or right_contribution >= 10) and left_contribution != right_contribution: win_by_points = True round_number += 1 if win_by_points: return left_name if left_contribution > right_contribution else right_name print("round limit reached; both fighters collapse") return "Nobody" if __name__ == "__main__": import argparse pars = argparse.ArgumentParser(prog="EstateAgentWrestling", description="Conduct a game of Estate Agent Wrestling") pars.add_argument("Left_Agent") pars.add_argument("Right_Agent") pars.add_argument("Left_Agent_Finishing_Move", nargs="?", default=one_round_moves()) pars.add_argument("Right_Agent_Finishing_Move", nargs="?", default=one_round_moves()) pars.add_argument("Meddlings", nargs="*") args = pars.parse_args() left_finish = args.Left_Agent_Finishing_Move if left_finish == "X" or left_finish == "random": left_finish = generate_finishing_move() right_finish = args.Right_Agent_Finishing_Move if right_finish == "X" or right_finish == "random": right_finish = generate_finishing_move() winner = wrestle(args.Left_Agent, args.Right_Agent, left_finish, right_finish, args.Meddlings) print("The winner is "+winner)