Exemple #1
0
 def test_enumerate(self):
     ml = MoveList(self.valid_move, self.valid_move, self.valid_move)
     i = 1
     for idx, move in ml.enumerate():
         self.assertEqual(idx, i)
         self.assertTrue(isinstance(move, Move))
         i += 1
Exemple #2
0
class AcademyBot(Bot):
    def __init__(self, botCommands):
        super().__init__(botCommands)
        self.frameCounter = 0
        self.FrameLastAction = 0
        self.distance = 0
        self.gameplan = None
        self.Movelist = None
        self.OppMovelist = None
        self.Stance = None
        self.overlay = None
        self.recorder = None
        self.BotMove = None
        self.BotMoveHistory = []

    def Update(self, gameState: TekkenGameState):
        BotBehaviors.Basic(gameState, self.botCommands)
        if self.gameplan == None:
            char_id = gameState.GetBotCharId()
            print("Testing Char ID: " + str(char_id))
            if char_id != None:
                self.gameplan = GetGameplan(char_id)
                self.Movelist = MoveList(char_id)
                self.useMoves = self.Movelist.allMoves
                self.Movelist.getGameplan(1)
                self.OppMovelist = MoveList(gameState.stateLog[-1].opp.char_id)

        if gameState.WasFightReset():
            self.botCommands.ClearCommands()

        if gameState.IsGameHappening():
            self.frameCounter += 1
            self.distance = gameState.GetDist()
            self.BotMove = gameState.GetCurrentBotMoveName()
            self.AppendBotMove(gameState.GetCurrentOppMoveName())
            Stance = self.Movelist.GetStanceFromGameMove(self.BotMove)
            if (Stance != None):
                self.Stance = Stance

    def AppendBotMove(self, Move):
        if (len(self.BotMoveHistory) > 600):
            self.BotMoveHistory.pop()
        if ((not self.BotMoveHistory) or (self.BotMoveHistory[-1] != Move)):
            self.BotMoveHistory.append(Move)

    def HitList(self):
        return (HitOutcome.COUNTER_HIT_STANDING,
                HitOutcome.COUNTER_HIT_CROUCHING,
                HitOutcome.NORMAL_HIT_STANDING,
                HitOutcome.NORMAL_HIT_CROUCHING,
                HitOutcome.NORMAL_HIT_STANDING_LEFT,
                HitOutcome.NORMAL_HIT_CROUCHING_LEFT,
                HitOutcome.NORMAL_HIT_STANDING_BACK,
                HitOutcome.NORMAL_HIT_CROUCHING_BACK,
                HitOutcome.NORMAL_HIT_STANDING_RIGHT,
                HitOutcome.NORMAL_HIT_CROUCHING_RIGHT)
Exemple #3
0
class AcademyBot(Bot):
    def __init__(self, botCommands):
        super().__init__(botCommands)
        self.frameCounter = 0
        self.FrameLastAction = 0
        self.distance = 0
        self.gameplan = None
        self.Movelist = None
        self.Stance = None
        self.overlay = None
        self.recorder = None
        self.BotMove = None

    def Update(self, gameState: TekkenGameState):
        successfulUpdate = gameState.Update()

        #if successfulUpdate:
        #    self.cyclopedia_p1.Update(self.gameState)
        #    self.cyclopedia_p2.Update(self.gameState)

        #print(gameState.GetCurrentBotMoveName())
        #debugging

        if not self.recorder == None:
            self.recorder.Update(gameState)

        BotBehaviors.Basic(gameState, self.botCommands)
        if self.gameplan == None:
            char_id = gameState.GetBotCharId()
            print("Testing Char ID: " + str(char_id))
            if char_id != None:
                self.gameplan = GetGameplan(char_id)
                self.Movelist = MoveList(char_id)
                self.useMoves = self.Movelist.allMoves
                self.Movelist.getGameplan(1)

        if gameState.WasFightReset():
            self.botCommands.ClearCommands()
            self.gameplan = None

        if gameState.IsGameHappening():
            self.frameCounter += 1
            self.distance = gameState.GetDist()
            self.BotMove = gameState.GetCurrentBotMoveName()
            Stance = self.Movelist.GetStanceFromGameMove(self.BotMove)
            if (Stance != None):
                self.Stance = Stance

#        if self.botCommands.IsAvailable():

        return successfulUpdate
    def load_movelist(self):
        #try:
        self.movelist = MoveList(self.chars[self.CharChoice.get()])
        #self.MoveId['menu'].delete(0, 'end')
        #moves = self.movelist.GetAllMoveIdsAndNames()
        #for move in moves:
        #self.MoveId['menu'].add_command(label=move, command=_setit(var, move))

        #self.movelist = MoveList(self.CharIDBox.get("1.0", 'end-1c'))
        self.CharNameBox.configure(state="normal")
        self.CharNameBox.delete("1.0", END)
        self.CharNameBox.insert("1.0",
                                self.movelist.CharXml.getroot().attrib['name'])
        self.CharNameBox.configure(state="disabled")
    def testMoveList(self):
        print("Switching to Test Movelist")
        self.launcher = TekkenBotLauncher(BotTestCommand, False)
        self.overlay = GUI_TestOverlay(self, self.launcher, (1000, 35),
                                       (450, 170))
        self.launcher.botBrain.overlay = self.overlay

        #        character=self.launcher.gameState.stateLog[-1].bot.character_name
        character = "Akuma"
        charId = self.GetCharacterId(character)
        movelist = MoveList(charId)
        moves = movelist.GetAllMoveIds()
        moveCommands = []
        for id in moves:
            print(id)
            move = movelist.getMoveById(id)
            moveCommands.append(movelist.getMoveCommand(move))

        self.launcher.botBrain.Command = moveCommands
        self.launcher.botBrain.Delay = 60
Exemple #6
0
 def test_is_move_available(self):
     ml = MoveList(self.valid_move, self.valid_move, self.valid_move)
     self.assertTrue(ml.is_move_available(1))
     self.assertTrue(ml.is_move_available(2))
     self.assertTrue(ml.is_move_available(3))
     self.assertFalse(ml.is_move_available(0))
     self.assertFalse(ml.is_move_available(-1))
     self.assertFalse(ml.is_move_available(4))
Exemple #7
0
    def Update(self, gameState: TekkenGameState):
        BotBehaviors.Basic(gameState, self.botCommands)
        if self.gameplan == None:
            char_id = gameState.GetBotCharId()
            print("Testing Char ID: " + str(char_id))
            if char_id != None:
                self.gameplan = GetGameplan(char_id)
                self.Movelist = MoveList(char_id)
                self.useMoves = self.Movelist.allMoves
                self.Movelist.getGameplan(1)
                self.OppMovelist = MoveList(gameState.stateLog[-1].opp.char_id)

        if gameState.WasFightReset():
            self.botCommands.ClearCommands()

        if gameState.IsGameHappening():
            self.frameCounter += 1
            self.distance = gameState.GetDist()
            self.BotMove = gameState.GetCurrentBotMoveName()
            self.AppendBotMove(gameState.GetCurrentOppMoveName())
            Stance = self.Movelist.GetStanceFromGameMove(self.BotMove)
            if (Stance != None):
                self.Stance = Stance
Exemple #8
0
    def read_pokemon(self):     
        ''' reads a pokemon from stdin '''
        name = stdin.readline()
        try:
            lvl = stdin.readline()
        except ValueError:
            raise ValueError("Level must be an integer")
        try:
            hp = stdin.readline()
        except ValueError:
            raise ValueError("Health powe must be an integer")
        try:
            atk = stdin.readline()
        except ValueError:
            raise ValueError("Attack must be an integer")
        try:
            defe = int(stdin.readline())
        except ValueError:
            raise ValueError("Defence must be an integer")
        try:
            spd = int(stdin.readline())
        except ValueError:
            raise ValueError("Speed must be an integer")
        try:
            spc = int(stdin.readline())
        except ValueError:
            raise ValueError("Special must be an integer")
        try:
            tp = int(stdin.readline())
            typ1 = Type(tp)
            tp = int(stdin.readline())
            typ2 = Type(tp)
        except ValueError:
            raise ValueError("Pokemon Type must be an integer")
        typ_list = [typ1, typ2]
        try:
            natks = int(stdin.readline())
        except ValueError:
            raise ValueError("nat must be an integer")

        stats = Stats(hp, atk, defe, spd, spc)
        moves = MoveList(max_moves = natks + 1)
        for i in range(natks):
            move_name = stdin.readline()
            try:
                tp = int(stdin.readline())
                move_type = Type(tp)
            except ValueError:
                raise ValueError("A move type must be an integer")
            try:
                move_acu = int(stdin.readline())
            except ValueError:
                raise ValueError("A move accuracy must be an integer")
            try:
                move_pwr = int(stdin.readline())
            except ValueError:
                raise ValueError("A move power must be an integer")
            try:
                move_pp = int(stdin.readline())
            except ValueError:
                raise ValueError("A move pp must be an integer")
            moves.add_move(Move(move_name, move_type, move_acu, move_pwr, move_pp))

        return Pokemon(typ_list, stats, moves, name, lvl)
class GUI_TekkenAcademy(Tk):
    def __init__(self):
        Tk.__init__(self)
        self.wm_title("Tekken Academy")
        self.geometry(str(720) + 'x' + str(720))

        Style().theme_use('alt')
        self.menu = Menu(self)
        self.configure(menu=self.menu)

        self.tekken_bot_menu = Menu(self.menu)
        self.tekken_bot_menu.add_command(label="Punish Practice Bot",
                                         command=self.switchToPractice)
        self.tekken_bot_menu.add_command(label="Punish Test Bot",
                                         command=self.switchToPunishTestBot)
        #        self.tekken_bot_menu.add_command(label="Back Dash Cancel", command=self.switchToBDCBot)
        #        self.tekken_bot_menu.add_command(label="Test Bot", command=self.switchToTest)
        self.tekken_bot_menu.add_command(label="Stop Bots",
                                         command=self.stopBot)
        #        self.tekken_bot_menu.add_command(label="Test Movelist", command=self.testMoveList)
        #        self.tekken_bot_menu.add_command(label="Clear History", command=self.clearHistory)
        #        self.tekken_bot_menu.add_command(label="Record", command=self.record)
        self.tekken_bot_menu.add_command(label="GUI Record",
                                         command=self.gui_record)
        #        self.tekken_bot_menu.add_command(label="Print Record", command=self.printrecord)
        self.menu.add_cascade(label="Tekken Academy",
                              menu=self.tekken_bot_menu)

        #self.launcher = TekkenBotLauncher(BotPunishTest , False)
        self.launcher = None
        self.overlay = None
        self.recorder = None
        #self.overlay.update_location()

        #Overlay text redirection
        self.text = Text(self, wrap="word")
        self.stdout = sys.stdout
        self.var_print_frame_data_to_file = BooleanVar(value=False)
        sys.stdout = TextRedirector(self.text, sys.stdout,
                                    self.write_to_overlay,
                                    self.var_print_frame_data_to_file,
                                    "stdout")
        self.stderr = sys.stderr
        sys.stderr = TextRedirector(self.text, sys.stderr, self.write_to_error,
                                    "stderr")
        self.text.tag_configure("stderr", foreground="#b22222")

        self.text.grid(row=2, column=0, columnspan=2, sticky=N + S + E + W)
        self.grid_rowconfigure(2, weight=1)
        self.grid_columnconfigure(0, weight=1)

        try:
            with open("TekkenData/tekken_acadamy_readme.txt") as fr:
                lines = fr.readlines()
            for line in lines:
                print(line)
        except:
            print("Error reading readme file.")
        #self.overlay.hide()
        self.protocol("WM_DELETE_WINDOW", self.on_closing)

    def update_launcher(self):
        try:
            self.update()
        finally:
            self.stopBot

        self.after(5, self.update_launcher)

    def update(self):
        successful_update = False
        if (self.launcher != None):
            if (self.launcher.gameState.IsForegroundPID()
                    and self.overlay != None):
                self.overlay.show()
            successful_update = self.launcher.Update()
        if (self.overlay != None):
            self.overlay.update_location()
        if (self.recorder != None and successful_update):
            self.recorder.update_state()

    def record(self):
        self.launcher = TekkenBotLauncher(BotTest, True)
        self.recorder = CommandRecorder(self.launcher)

    def gui_record(self):
        self.launcher = TekkenBotLauncher(GUI_CommandRecorder, True)
        self.launcher.botBrain.gameState = self.launcher.gameState

    def printrecord(self):
        #self.recorder.print_f()
        self.recorder.parse('Recorded')

    def switchToPractice(self):
        print("Switching to Practice")
        self.launcher = TekkenBotLauncher(BotPunishPractice, False)
        self.overlay = GUI_TestOverlay(self, self.launcher, (1000, 35),
                                       (450, 170))
        self.launcher.botBrain.overlay = self.overlay
        self.overlay.WriteToOverlay("Switching to Practice")

    def switchToPunishTestBot(self):
        print("Switching to Punish Test Bot")
        self.launcher = TekkenBotLauncher(BotPunishTest, False)
        self.overlay = GUI_TestOverlay(self, self.launcher, (1000, 35),
                                       (450, 170))
        self.launcher.botBrain.overlay = self.overlay

    def switchToBDCBot(self):
        print("Switching to BDC Practice Bot")
        self.launcher = TekkenBotLauncher(BotBackDashCancelPractice, True)
        self.overlay = GUI_TestOverlay(self, self.launcher, (1000, 35),
                                       (450, 170))
        self.launcher.botBrain.overlay = self.overlay
        self.overlay.WriteToOverlay(
            "Switching to Back Dash Cancelling Practice")

    def switchToTest(self):
        print("Switching to Test Bot")
        self.launcher = TekkenBotLauncher(BotTest, False)
        self.overlay = GUI_TestOverlay(self, self.launcher, (1000, 35),
                                       (450, 170))
        self.launcher.botBrain.overlay = self.overlay

    def testMoveList(self):
        print("Switching to Test Movelist")
        self.launcher = TekkenBotLauncher(BotTestCommand, False)
        self.overlay = GUI_TestOverlay(self, self.launcher, (1000, 35),
                                       (450, 170))
        self.launcher.botBrain.overlay = self.overlay

        #        character=self.launcher.gameState.stateLog[-1].bot.character_name
        character = "Akuma"
        charId = self.GetCharacterId(character)
        movelist = MoveList(charId)
        moves = movelist.GetAllMoveIds()
        moveCommands = []
        for id in moves:
            print(id)
            move = movelist.getMoveById(id)
            moveCommands.append(movelist.getMoveCommand(move))

        self.launcher.botBrain.Command = moveCommands
        self.launcher.botBrain.Delay = 60

    def stopBot(self):
        print("Stopping Bots")
        self.launcher = None

    def updateMovelists(self):
        dir = "TekkenData\Movelists"
        for filename in os.listdir(dir):
            if filename.endswith(".xml"):
                data_file = ET.parse(os.path.join(dir, filename))
                char_root = data_file.getroot()
                try:
                    url = 'http://www.seattletekken.com/modules/academy/src/characters/'
                    char = data_file.getroot().attrib['name']
                    r = requests.get(url + char + '/movelist/movelist.xml')
                except:
                    raise Exception("Can't load xml from website for " + char)

                if r.ok:
                    new_file = ET.fromstring(r.text)
                    if new_file.attrib['version'] > data_file.getroot(
                    ).attrib['version']:
                        try:
                            os.rename(
                                os.path.join(dir, filename),
                                os.path.join(
                                    dir, "xml backups", char + "-" +
                                    data_file.getroot().attrib['version'] +
                                    ".xml"))
                            print("Retrieved updated movelist for " + char)
                        except:
                            raise Exception("Can't backup file")

                        xmlFile = xml.dom.minidom.parseString(
                            ET.tostring(new_file))
                        f = open(os.path.join(dir, filename), "w")
                        f.write(xmlFile.toprettyxml(newl=''))
                        f.close()

                    else:
                        print("Movelist for " + char +
                              " already at current version.")

    def editMovelists(self):
        self.launcher = TekkenBotLauncher(BotTestCommand, False)
        self.overlay = GUI_TestOverlay(self, self.launcher, (1000, 35),
                                       (450, 170))
        self.launcher.botBrain.overlay = self.overlay

        win = Toplevel()
        #        canvas = Canvas(win, bd=0, width=720, height=720)
        #        canvas.grid(row=0, column=0, sticky=N+S+E+W)

        #        frame = Frame(canvas, relief=SUNKEN, width=720, height=720)
        #        frame.grid_rowconfigure(0, weight=1)
        #        frame.grid_columnconfigure(0, weight=1)
        #        frame.grid_propagate(0)

        #frame.pack()
        #        frame.grid(row=0, column=1, sticky=N+W)

        i = 0
        self.CharIDLabel = Label(win, text="Character ID")
        self.CharIDLabel.grid(row=i, column=0)
        self.CharChoice = StringVar(win)
        self.chars = self.GetCharacterNamesWithIds()
        self.CharChoice.set('Alisa')
        self.CharID = OptionMenu(win, self.CharChoice, *self.chars)
        self.CharID.grid(row=i, column=1, sticky=W)
        #        self.CharIDBox = Text(win, height=1, width=10)
        #        self.CharIDBox.grid(row=i, column=1, sticky=W)
        self.CharNameBox = Text(win, height=1, width=30)
        self.CharNameBox.grid(row=i, column=2, sticky=W)
        self.CharNameBox.configure(state="disabled")
        self.LoadMovelistBtn = Button(win,
                                      text="Load Movelist",
                                      command=self.load_movelist)
        self.LoadMovelistBtn.grid(row=i, column=3)
        i = i + 1

        self.MoveIDLabel = Label(win, text="Move")
        self.MoveIDLabel.grid(row=i, column=0)

        #        self.MoveIdVar = StringVar(win)
        #        self.MoveId = OptionMenu(win, self.MoveIdVar, ['Please select character'])
        #        self.MoveId.grid(row=i, column=1, sticky=W)
        self.MoveIDBox = Text(win, height=1, width=10)
        self.MoveIDBox.grid(row=i, column=1, sticky=W)
        self.MoveNameBox = Text(win, height=1, width=30)
        self.MoveNameBox.grid(row=i, column=2, sticky=W)
        self.MoveNameBox.configure(state="disabled")
        self.LoadMoveBtn = Button(win,
                                  text="Load Move",
                                  command=self.load_move)
        self.LoadMoveBtn.grid(row=i, column=3)
        i = i + 1

        self.CommandLabel = Label(win, text="Command")
        self.CommandLabel.grid(row=i, column=0)
        self.CommandBox = Text(win, height=1, width=50)
        self.CommandBox.grid(row=i, column=1, columnspan=2, sticky=W)
        self.CommandBox.insert(END, '+1')
        i = i + 1

        self.DelayLabel = Label(win, text="Delay")
        self.DelayLabel.grid(row=i, column=0)
        self.DelayBox = Text(win, height=1, width=50)
        self.DelayBox.grid(row=i, column=1, columnspan=2, sticky=W)
        self.DelayBox.insert(END, '60')
        i = i + 1

        self.TestButton = Button(win, text="Test", command=self.test_command)
        self.TestButton.grid(row=i, column=0)
        self.StopButton = Button(win, text="Stop", command=self.stopBot)
        self.StopButton.grid(row=i, column=1)
        self.ShortcutsButton = Button(win,
                                      text="Command Shortcuts",
                                      command=self.show_shortcuts)
        self.ShortcutsButton.grid(row=i, column=2)
        self.SaveButton = Button(win,
                                 text="Save MoveList",
                                 command=self.save_move)
        self.SaveButton.grid(row=i, column=3)
        i = i + 1

    def CommandChanged(self):
        print("Command Changed")

    def save_move(self):
        #print("Not currently saving")
        self.movelist.Save()

    def load_move(self):
        try:
            self.CommandBox.delete("1.0", END)
            self.EditMove = self.movelist.getMoveById(
                self.MoveIDBox.get("1.0", 'end-1c'))
            self.CommandBox.insert(
                END, self.movelist.getMoveCommand(self.EditMove, 1))
            self.MoveNameBox.configure(state="normal")
            self.MoveNameBox.delete("1.0", END)
            self.MoveNameBox.insert("1.0",
                                    self.movelist.getMoveName(self.EditMove))
            self.MoveNameBox.configure(state="disabled")
        except:
            print("Cannot load move")

    def load_movelist(self):
        #try:
        self.movelist = MoveList(self.chars[self.CharChoice.get()])
        #self.MoveId['menu'].delete(0, 'end')
        #moves = self.movelist.GetAllMoveIdsAndNames()
        #for move in moves:
        #self.MoveId['menu'].add_command(label=move, command=_setit(var, move))

        #self.movelist = MoveList(self.CharIDBox.get("1.0", 'end-1c'))
        self.CharNameBox.configure(state="normal")
        self.CharNameBox.delete("1.0", END)
        self.CharNameBox.insert("1.0",
                                self.movelist.CharXml.getroot().attrib['name'])
        self.CharNameBox.configure(state="disabled")

    #except:
    #print("Cannot load movelist")

    def show_shortcuts(self):
        short = Toplevel()
        SCText = Text(short)
        SCText.pack()
        SCText.insert(
            END,
            "Commands are spearated by commas, If you put a number with no +, it will wait that many frames\n"
        )
        SCText.insert(
            END, "EX: f+1, 5, +2\tWill hit f+1, wait 5 frames then hit 2\n")
        SCText.insert(END, "+1, +2, +3, +4:\tTap the button\n")
        SCText.insert(END, "*:\tHold the following button\n")
        SCText.insert(END, "dp:\tf,d,df\n")
        SCText.insert(END, "qcb:\td,db,b\n")
        SCText.insert(END, "qcf:\td,df,f\n")
        SCText.insert(END, "pewgf:\tf,N,df\n")
        SCText.insert(END, "ewgf:\tf,N,d,df\n")
        SCText.insert(END, "iWS:\tInstant While Standing\n")
        SCText.insert(END, "WS:\tWhile Standing\n")
        SCText.insert(END, "UF:\tJump Forward\n")
        SCText.insert(
            END, "ff[x]:\tFF + button where x is the delay after hitting ff\n")
        SCText.insert(END, "SSU:\tSide Step Up\n")
        SCText.insert(END, "wr:\tInstant While Running\n")
        SCText.insert(END, "rel:\tRelease All\n")
        SCText.insert(END, "-U:\tRelease Up\n")
        SCText.insert(END, "-D:\tRelease Down\n")
        SCText.insert(END, "-B:\tRelease Back\n")
        SCText.insert(END, "-F:\tRelease Forward\n")
        SCText.insert(END, "u:\tTap up\n")
        SCText.insert(END, "U:\tHold up\n")
        SCText.insert(END, "d:\tTap down\n")
        SCText.insert(END, "D:\tHold down\n")
        SCText.insert(END, "f:\tTap Forward\n")
        SCText.insert(END, "F:\tHold Forward\n")
        SCText.insert(END, "b:\tTap Back\n")
        SCText.insert(END, "B:\tHold Back\n")

    def test_command(self):
        print("Switching to Test Command")
        if self.launcher == None:
            self.launcher = TekkenBotLauncher(BotTestCommand, False)
        self.launcher.botBrain.overlay = self.overlay
        self.launcher.botBrain.Command = self.CommandBox.get("1.0", 'end-1c')
        self.launcher.botBrain.Delay = int(self.DelayBox.get("1.0", 'end-1c'))
        if self.CommandBox.edit_modified():
            print("Modified")
            self.movelist.updateMoveCommand(
                self.EditMove, self.CommandBox.get("1.0", 'end-1c'))
            self.CommandBox.edit_modified(False)

    def write_to_overlay(self, string):
        if self.overlay == None:
            self.stdout.write(string)

    def clearHistory(self):
        self.text.config(state=NORMAL)
        self.text.delete('1.0', END)
        self.text.configure(state="disabled")
        self.text.see('end')

    def write_to_error(self, string):
        self.stderr.write(string)

    def on_closing(self):
        sys.stdout = self.stdout
        sys.stderr = self.stderr
        self.destroy()

    def GetCharacterId(self, char):
        ids = self.GetCharacterNamesWithIds()
        return ids[char.capitalize()]

    def GetCharacterNamesWithIds(self):
        return {
            'None': -99,
            'Akuma': 32,
            'Alisa': 19,
            'Asuka': 12,
            'Bob': 31,
            'Bryan': 7,
            'Claudio': 20,
            'Devil Jin': 13,
            'Dragunov': 16,
            'Eddy': 35,
            'Eliza': 36,
            'Feng': 14,
            'Geese': 43,
            'Gigas': 25,
            'Heihachi': 8,
            'Hwoarang': 4,
            'Jack7': 11,
            'Jin': 6,
            'Josie': 24,
            'Katarina': 21,
            'Kazumi': 26,
            'Kazuya': 9,
            'King': 2,
            'Kuma': 33,
            'Lars': 18,
            'Law': 1,
            'Lee': 30,
            'Leo': 17,
            'Lili': 15,
            'Lucky Chloe': 22,
            'Master Raven': 29,
            'Miguel': 37,
            'Nina': 28,
            'Noctis': 44,
            'Paul': 0,
            'Shaheen': 23,
            'Steve': 10,
            'Xiaoyu': 5,
            'Yoshimitsu': 3
        }
Exemple #10
0
 def test_get_move(self):
     ml = MoveList(self.valid_move, self.valid_move, self.valid_move)
     self.assertTrue(isinstance(ml.get_move(1), Move))
Exemple #11
0
 def test_add_move(self):
     for maxi in range(20):
         ml = MoveList(max_moves=maxi)
         for _ in range(maxi):
             ml.add_move(self.valid_move)
         self.assertRaises(OverflowError, ml.add_move, self.valid_move)
Exemple #12
0
import movelist
import NotationParser
from NotationParser import ParseMoveList
from movelist import MoveList

gp = MoveList(28)

m = gp.GetPunishers(10, True)
print(m)

#moves = gp.getGameplan(1)

#for move in gp.gameplan:
#    try:
#        command = ParseMoveList(gp.getMoveCommand(move))
#    except:
#        print(move[0].text)
Exemple #13
0
    def Update(self, gameState: TekkenGameState):
        successfulUpdate = gameState.Update()
        if gameState.IsGameHappening():
            self.frameCounter += 1
            self.distance = gameState.GetDist()

        if not self.recorder == None:
            self.recorder.Update(gameState)

        BotBehaviors.Basic(gameState, self.botCommands)

        if gameState.WasFightReset():
            self.botCommands.ClearCommands()
            self.gameplan = None

        if self.gameplan == None:
            char_id = gameState.GetBotCharId()
            if char_id != None:
                self.gameplan = GetGameplan(char_id)
                #self.punishableMoves = self.gameplan.GetPunishableMoves()
                #self.allMoves = getMoves(char_id)
                #self.useMoves = getPunishableMoves(self.allMoves)
                self.allMoves = MoveList(char_id)
                self.useMoves = self.allMoves.allMoves
                self.allMoves.getGameplan(1)
                self.allMoves.shuffleGameplan()

        if self.botCommands.IsAvailable():
            #if gameState.DidBotStartGettingPunishedXFramesAgo(30):
            #gameState.IsOppAbleToAct()
            if gameState.stateLog[-1].bot.IsPunish(
            ) or gameState.stateLog[-1].bot.IsBeingJuggled():
                #if gameState.GetFramesSinceBotTookDamage() < 30:
                if self.lastMove:
                    print("Punished")
                    self.NumCorrectPunished = self.NumCorrectPunished + 1
                    self.allMoves.removeMoveFromGameplan(self.lastMove)
                self.lastMove = None
                if not self.allMoves.gameplan:
                    self.exit = True
                    print("Percentage of punishes: " +
                          str((float(self.NumCorrectPunished) /
                               float(self.CountOfAttempts)) * 100) + "%")
                    print("Total Punished: " + str(self.NumCorrectPunished))
                    print("Total Attempts: " + str(self.CountOfAttempts))

            BotBehaviors.BlockAllAttacks(gameState, self.botCommands)
            #Check to see if the bot is standing
            if gameState.stateLog[-1].bot.simple_state != (
                    SimpleMoveStates.STANDING):
                self.FrameLastAction = self.frameCounter
                #print(gameState.stateLog[-1].bot.simple_state)
            else:
                if self.distance > 1500:
                    self.botCommands.AddCommand(
                        self.botCommands.ForwarddashSmall())
                elif self.DetermineIfAction():
                    #print(self.distance)
                    #self.botCommands.AddCommand(random.choice(self.punishableMoves))
                    #print(random.choice(self.punishableMoves))
                    if len(self.queue) == 0:
                        self.lastMove = self.allMoves.getNextGameplanMove()
                        #move = self.allMoves.getMoveById(18)
                        #self.queue.append(move)
                        #self.queue.append(move)
                    else:
                        self.lastMove = self.queue.pop(0)
                    #move = self.allMoves[-1]
                    #command = move.getMoveCommand
                    command = self.allMoves.getMoveCommand(self.lastMove, 0)
                    print("Move: " + self.allMoves.getMoveName(self.lastMove) +
                          "\nID: " + self.allMoves.getMoveId(self.lastMove) +
                          "\n")
                    #print(ParseMoveList(command))
                    if command is not None:
                        self.botCommands.AddCommand(ParseMoveList(command))
                        self.CountOfAttempts = self.CountOfAttempts + 1
Exemple #14
0
class BotPunishTest(Bot):
    def __init__(self, botCommands):
        super().__init__(botCommands)
        self.SetFrameTrapCommandFromNotationString("+4")
        self.recorder = None
        self.inputDelay = 0
        self.inputDelayCode = None
        #        self.gameState = TekkenGameState()
        self.frameCounter = 0
        self.FrameLastAction = 0
        self.elapsedTime = time.time()
        self.distance = 0
        self.gameplan = None
        self.punishableMoves = None
        self.allMoves = None
        self.useMoves = None
        self.queue = []
        self.lastMove = None
        self.NumCorrectPunished = 0
        self.CountOfAttempts = 0
        self.exit = False

    def Update(self, gameState: TekkenGameState):
        successfulUpdate = gameState.Update()
        if gameState.IsGameHappening():
            self.frameCounter += 1
            self.distance = gameState.GetDist()

        if not self.recorder == None:
            self.recorder.Update(gameState)

        BotBehaviors.Basic(gameState, self.botCommands)

        if gameState.WasFightReset():
            self.botCommands.ClearCommands()
            self.gameplan = None

        if self.gameplan == None:
            char_id = gameState.GetBotCharId()
            if char_id != None:
                self.gameplan = GetGameplan(char_id)
                #self.punishableMoves = self.gameplan.GetPunishableMoves()
                #self.allMoves = getMoves(char_id)
                #self.useMoves = getPunishableMoves(self.allMoves)
                self.allMoves = MoveList(char_id)
                self.useMoves = self.allMoves.allMoves
                self.allMoves.getGameplan(1)
                self.allMoves.shuffleGameplan()

        if self.botCommands.IsAvailable():
            #if gameState.DidBotStartGettingPunishedXFramesAgo(30):
            #gameState.IsOppAbleToAct()
            if gameState.stateLog[-1].bot.IsPunish(
            ) or gameState.stateLog[-1].bot.IsBeingJuggled():
                #if gameState.GetFramesSinceBotTookDamage() < 30:
                if self.lastMove:
                    print("Punished")
                    self.NumCorrectPunished = self.NumCorrectPunished + 1
                    self.allMoves.removeMoveFromGameplan(self.lastMove)
                self.lastMove = None
                if not self.allMoves.gameplan:
                    self.exit = True
                    print("Percentage of punishes: " +
                          str((float(self.NumCorrectPunished) /
                               float(self.CountOfAttempts)) * 100) + "%")
                    print("Total Punished: " + str(self.NumCorrectPunished))
                    print("Total Attempts: " + str(self.CountOfAttempts))

            BotBehaviors.BlockAllAttacks(gameState, self.botCommands)
            #Check to see if the bot is standing
            if gameState.stateLog[-1].bot.simple_state != (
                    SimpleMoveStates.STANDING):
                self.FrameLastAction = self.frameCounter
                #print(gameState.stateLog[-1].bot.simple_state)
            else:
                if self.distance > 1500:
                    self.botCommands.AddCommand(
                        self.botCommands.ForwarddashSmall())
                elif self.DetermineIfAction():
                    #print(self.distance)
                    #self.botCommands.AddCommand(random.choice(self.punishableMoves))
                    #print(random.choice(self.punishableMoves))
                    if len(self.queue) == 0:
                        self.lastMove = self.allMoves.getNextGameplanMove()
                        #move = self.allMoves.getMoveById(18)
                        #self.queue.append(move)
                        #self.queue.append(move)
                    else:
                        self.lastMove = self.queue.pop(0)
                    #move = self.allMoves[-1]
                    #command = move.getMoveCommand
                    command = self.allMoves.getMoveCommand(self.lastMove, 0)
                    print("Move: " + self.allMoves.getMoveName(self.lastMove) +
                          "\nID: " + self.allMoves.getMoveId(self.lastMove) +
                          "\n")
                    #print(ParseMoveList(command))
                    if command is not None:
                        self.botCommands.AddCommand(ParseMoveList(command))
                        self.CountOfAttempts = self.CountOfAttempts + 1

    def DetermineIfAction(self):
        if self.frameCounter - self.FrameLastAction > (1 * 60):
            self.FrameLastAction = self.frameCounter
            return True
        return False

    def SetFrameTrapCommandFromNotationString(self, notation: str):

        try:
            self.response = ParseMoveList(">, " + notation + ", >>")
            #print(self.response)
        except:
            print("Could not parse move: " + str(notation))

    def Record(self):
        self.recorder = MatchRecorder()

    def Stop(self):
        notation = self.recorder.GetInputAsNotation()
        #commands = self.recorder.GetInputAsCommands()
        #self.botCommands.ClearCommands()
        #self.botCommands.AddCommand(commands)
        self.recorder = None
        return notation