Esempio n. 1
0
 def silly_inner_generator(self):
     while True:
         direction = random.choice(list(SK.STEPS.keys()))
         if direction == CM.TELEPORT:
             continue
         np = (self.p[0] + SK.STEPS[direction][0], self.p[1] + SK.STEPS[direction][1])
         if cell_is_correct(np):
             yield CM.pack_bot_step(self.run_number, self.time_frame, CM.CAT, direction)
Esempio n. 2
0
    def receive_from_bot(self):
        # ans = input(prompt=sys.stdin) # todo
        ans = next(self.silly_inner_gen)
        ans = json.loads(ans)

        if CM.BOT_STEP in ans.keys():
            assert ans[CM.BOT_STEP][CM.RUN_NUMBER] == self.run_number
            assert ans[CM.BOT_STEP][CM.TIME_FRAME] == self.time_frame
            np = (self.p[0] + SK.STEPS[ans[CM.BOT_STEP][CM.DIRECTION]][0],
                  self.p[1] + SK.STEPS[ans[CM.BOT_STEP][CM.DIRECTION]][1])

            if cell_is_correct(np):
                self.p = np
                return True
        return False
Esempio n. 3
0
    def receive_from_bot(self):
        try:
            # ans = input(prompt=sys.stdin) # todo
            ans = self.silly_gen()
            ans = json.loads(ans)
            assert CM.BOT_STEP in ans
            assert ans[CM.BOT_STEP][CM.RUN_NUMBER] == self.game_run.run_number
            assert ans[CM.BOT_STEP][CM.TIME_FRAME] == self.time_frame

            np = (self.p[0] + SK.STEPS[ans[CM.BOT_STEP][CM.DIRECTION]][0],
                  self.p[1] + SK.STEPS[ans[CM.BOT_STEP][CM.DIRECTION]][1])
            if cell_is_correct(np):
                self.p = np
                return True
            return False
        except TimedOutExc:
            return False