def __init__(self, round=0): import math import random import extra self.math = math self.random = random self.extra = extra self.showdownRound = 90 # after this round, your personal program takes over self.round = max(round, 90) # the current round self.myMoves = [] # all the moves you've made, first to last self.opponentMoves = [ ] # all the moves your opponent has made, first to last my_source_raw = extra.__getattribute__(''.join( ['ge', 't_', 'my', '_s', 'ou', 'rce']))(self) opponent_source_raw = extra.__getattribute__(''.join( ['ge', 't_', 'op', 'po', 'ne', 'nt', '_s', 'ou', 'rce']))(self) my_source = "\n".join([ " ".join(line.split('\t')).rstrip() for line in my_source_raw.splitlines() ]) opponent_source = "\n".join([ " ".join(line.split('\t')).rstrip() for line in opponent_source_raw.splitlines() ]) if not 'def payload(self) :' in opponent_source: self.is_opponent_clone = False else: my_common_code, my_payload = my_source.rsplit( 'def payload(self) :', 1) opponent_common_code, opponent_payload = opponent_source.rsplit( 'def payload(self) :', 1) if my_common_code != opponent_common_code: self.is_opponent_clone = False else: self.is_opponent_clone = True for line in opponent_payload.split("\n"): # checks that no common method or property is overwritten after the payload # allows the innocuous command "foo = 'bar'" by member's demand if line.lstrip() != "" and line != "foo = 'bar'" and line[ 0:8] != " ": self.is_opponent_clone = False break if self.is_opponent_clone: payload_length_difference = len(my_payload) - len( opponent_payload) if my_payload != opponent_payload: # compares payloads without reading them # fair way to decide who starts with 3 between two clones # for 100% protection against ties, personalize your payload with a comment self.high_first = (my_payload < opponent_payload) == ( (payload_length_difference + round) % 2 == 1)
def get_op(self): if self.gotOpponent: return self.opponent self.gotOpponent = True # only try once try: import ast import extra opponent_source = extra.__getattribute__(''.join(['ge','t_','op','po','ne','nt','_s','ou','rce']))(self) enemy_tree = ast.parse(opponent_source) enemy_classes = [ s for s in enemy_tree.body if isinstance(s, ast.ClassDef) ] assert len(enemy_classes) == 1 enemy_true_name = enemy_classes[0].name enemy_tree.body.append( ast.parse( f"_e_b[0] = {enemy_true_name}(round={self.round})" ).body[0] ) exec( compile(enemy_tree, '<string>', mode='exec'), self.opGlob, self.opGlob ) self.opponent = self.opGlob['_e_b'][0] return self.opponent except Exception as e: import logging logging.error(e)