whileTrue: if cntSuccess==0: maze=r.recvuntil('answer:\n').split('\n')[:-1] else: maze=r.recvuntil('answer:\n').split('\n')[3:-1] cntSuccess+=1 print("------") for rows in maze: print(''.join(rows)) print("------") maze=[list(n) for n in maze] row=len(maze) col=len(maze[0]) path=[] flag="" book=[[(0,0,0) for _ inrange(col)] for _ inrange(row)] head=0 tail=1
cnt=0 for i inrange(len(maze)): if'S'in maze[i]: start=(i,maze[i].index('S')) cnt+=1 if'E'in maze[i]: end=(i,maze[i].index('E')) cnt+=1 if cnt==2: break
path.append(start) book[start[0]][start[1]]=path[head]+('*',) maze[start[0]][start[1]]='#' isSuccess=0 while head<tail: for i inrange(4): x,y=path[head][0]+dirs[i][0],path[head][1]+dirs[i][1] if x notinrange(row) or y notinrange(col) or maze[x][y]=='#': continue maze[x][y]='#' book[x][y]=path[head]+(flag_char[i],) path.append((x,y)) tail+=1 if x==end[0] and y==end[1]: isSuccess=1 break if isSuccess==1: break head+=1 cur=book[end[0]][end[1]] while cur[2]!='*': flag+=cur[2] cur=book[cur[0]][cur[1]] flag=flag[::-1] r.sendline(str(len(flag)+1)) print(flag) if cntSuccess==4: break # print('time: ',round(time.clock()-t,2),'s') r.interactive()
defxorTuple(t1,t2,size): ret=() for i inrange(size): ret+=(t1[i]^t2[i],) return ret
for x inrange(11): width=119 height=83 res=[[(0,0,0) for _ inrange(height)] for _ inrange(width)] for pos inrange(11+x,451,11): # 后40组 im=Image.open('frames/frame_'+str(pos).rjust(3,'0')+'.png') img=im.convert('RGB') for i inrange(width): for j inrange(height): res[i][j]=xorTuple(res[i][j],img.getpixel((i,j)),3) resImg=Image.new("RGB",(width,height)) for i inrange(len(res)): for j inrange(len(res[0])): if res[i][j]!=(0,0,0): resImg.putpixel([i,j],res[i][j]) else: resImg.putpixel([i,j],(255,255,255)) resImg.save("res_"+str(x).rjust(3,'0')+".png")
width=83 height=83 ans=[[(0,0,0) for _ inrange(height*3)] for _ inrange(width*3)] for pi inrange(3): for pj inrange(3): im=Image.open('res_'+str(ans_list[pi][pj]-1).rjust(3,'0')+'.png') img=im.convert('RGB') for i inrange(width): for j inrange(height): ans[pi*83+i][pj*83+j]=img.getpixel((i,j))
ansImg=Image.new("RGB",(width*3,height*3)) for i inrange(len(ans)): for j inrange(len(ans[0])): ansImg.putpixel([i,j],ans[i][j]) ansImg.save("ans.png")