def shuffle_boxs(boxs,num_moves):
global BLANK,ALLMOVES
moves_gen = []
ALLMOVES = [UP,DOWN,LEFT,RIGHT]
HMOVES = [LEFT,RIGHT]
VMOVES = [UP,DOWN]
last_move = None
for i in range(num_moves):
if i % 2 ==0:
move = VMOVES[random.randint(0,1)]
while is_valid_move(move) != True:
move = VMOVES[random.randint(0,1)]
else:
move = HMOVES[random.randint(0,1)]
while is_valid_move(move) != True:
move = HMOVES[random.randint(0,1)]
if move == LEFT :
(boxx,boxy) = (BLANK[0]+1,BLANK[1])
elif move == RIGHT :
(boxx,boxy) = (BLANK[0]-1,BLANK[1])
elif move == UP :
(boxx,boxy) = (BLANK[0],BLANK[1]+1)
elif move == DOWN :
(boxx,boxy) = (BLANK[0],BLANK[1]-1)
boxs[BLANK[0]][BLANK[1]].num = boxs[boxx][boxy].num
boxs[BLANK[0]][BLANK[1]].is_blank = False
boxs[boxx][boxy].move_to(move)
ALLMOVES.append(move)
last_move = move
global BLANK,ALLMOVES
moves_gen = []
ALLMOVES = [UP,DOWN,LEFT,RIGHT]
HMOVES = [LEFT,RIGHT]
VMOVES = [UP,DOWN]
last_move = None
for i in range(num_moves):
if i % 2 ==0:
move = VMOVES[random.randint(0,1)]
while is_valid_move(move) != True:
move = VMOVES[random.randint(0,1)]
else:
move = HMOVES[random.randint(0,1)]
while is_valid_move(move) != True:
move = HMOVES[random.randint(0,1)]
if move == LEFT :
(boxx,boxy) = (BLANK[0]+1,BLANK[1])
elif move == RIGHT :
(boxx,boxy) = (BLANK[0]-1,BLANK[1])
elif move == UP :
(boxx,boxy) = (BLANK[0],BLANK[1]+1)
elif move == DOWN :
(boxx,boxy) = (BLANK[0],BLANK[1]-1)
boxs[BLANK[0]][BLANK[1]].num = boxs[boxx][boxy].num
boxs[BLANK[0]][BLANK[1]].is_blank = False
boxs[boxx][boxy].move_to(move)
ALLMOVES.append(move)
last_move = move