1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
| from pwn import * from Game import Game, randint, NOTHING, WALL, BOMB, CAT, PERSON import pickle
n = 60 Map = pickle.loads(open('./map2', 'rb').read()) directions = ['u', 'd', 'l', 'r']
def move(x, y, d): if d == 'u': y -= 1 elif d == 'd': y += 1 elif d == 'l': x -= 1 elif d == 'r': x += 1 return x, y
def get_next(sx, sy, dx, dy): vis = [[0 for _ in range(60)] for _ in range(60)] first = [[0 for _ in range(60)] for _ in range(60)] queue = [] queue.append((dx, dy, 2)) vis[dx][dy] = 2 for d in directions: nx, ny = move(sx, sy, d) if Map[nx][ny] == NOTHING: queue.append((nx, ny, 1)) first[nx][ny] = d vis[nx][ny] = 1 while len(queue) != 0: x, y, fd = queue[0] queue.pop(0) for d in directions: nx, ny = move(x, y, d) if Map[nx][ny] == NOTHING: if fd == 2: if vis[nx][ny] == 0: vis[nx][ny] = 2 queue.append((nx, ny, fd)) elif vis[nx][ny] == 1: return first[nx][ny] else: if vis[nx][ny] == 0: vis[nx][ny] = 1 first[nx][ny] = first[x][y] queue.append((nx, ny, fd)) elif vis[nx][ny] == 2: return first[x][y]
def start(): global game, p p = remote('59.110.63.160', 40001) game = Game()
def solve(): global game, p while True: for _ in range(3): direction = get_next(game.x, game.y, game.cx, game.cy) p.sendline(direction) if game.move(direction, PERSON) == 2: p.interactive() for _ in range(2): choice = randint(0, 3) direction = directions[choice] randcount = 0 while game.move(direction, CAT) == False: choice = randint(0, 3) direction = directions[choice] randcount += 1 if randcount == 10: break
if __name__ == '__main__': start() solve()
|