2023-11-02 09:11:00 +08:00

65 lines
1.5 KiB
Python

# https://zh.wikipedia.org/zh-hans/%E8%A7%A3%E8%BF%B7%E5%AE%AE%E6%BC%94%E7%AE%97%E6%B3%95
from pwn import *
import random
import time
context.log_level = 'debug'
map = [[0 for _ in range(19)] for _ in range(19)]
start = [9,9]
position = start
for i in range(19):
map[0][i] = 9
map[18][i] = 9
map[i][0] = 9
map[i][18] = 9
r = remote("172.20.14.117",46828)
r.recvline()
r.recvline()
# 11*11的迷宫
def gen_moves(map:list, position:list)->str:
moves = ''
if map[position[0]-1][position[1]] == 0:
moves += "w"
if map[position[0]+1][position[1]] == 0:
moves += "s"
if map[position[0]][position[1]-1] == 0:
moves += "a"
if map[position[0]][position[1]+1] == 0:
moves += "d"
return moves
while(1):
moves = gen_moves(map, position)
move = random.choice(moves).encode()
r.sendline(move)
status = r.recvline().decode()
# 撞墙
if 'wall' in status:
if move == b'w':
map[position[0]-1][position[1]] = 9
if move == b's':
map[position[0]+1][position[1]] = 9
if move == b'a':
map[position[0]][position[1]-1] = 9
if move == b'd':
map[position[0]][position[1]+1] = 9
else:
if move == b'w':
position[0] -= 1
if move == b's':
position[0] += 1
if move == b'a':
position[1] -= 1
if move == b'd':
position[1] += 1