masterofthebass
Premium Member
After fumbling around with trying to translate Jaap's scrambler into better languages, I gave up and decided to write my own. I think it's much cleaner and much more understandable than Jaap's. Here's the python code if anyone wants to use it:
Code:
def scramblesq1():
top=[1,1,0,1,1,0,1,1,0,1,1,0]
bot=[1,0,1,1,0,1,1,0,1,1,0,1]
topturn=0; botturn=0; start=False
s=""
i=0
while i<40:
while topturn==0 and botturn==0:
turn=randint(0,11)
while(canmove(top,turn)==False):
turn=randint(0,11)
topturn=turn
turn=randint(0,11)
while(canmove(bot,turn)==False):
turn=randint(0,11)
botturn=turn
if topturn==0 and botturn==0 and i==0:
start=True
topturn=1
botturn=1
if start==False:
if topturn!=0:
i+=1
if botturn!=0:
i+=1
top=shift(top, topturn)
bot=shift(bot, botturn)
top,bot=slice(top,bot)
i+=1
s+='(%d,%d) ' % ((topturn, topturn-12)[topturn>6], (botturn, botturn-12)[botturn>6])
start=False
topturn=0
botturn=0
return s
def slice(top, bot):
newtop=[]; newbot=[]
newbot.extend(bot[:6])
newbot.extend(top[:6])
newtop.extend(bot[6:])
newtop.extend(top[6:])
return newtop,newbot
def shift(face, amt):
for x in range(amt):
face.append(face.pop(0))
return face
def canmove(face, amt):
if amt>5:
if face[amt] and face[amt-6]:
return True
else:
if face[amt] and face[6+amt]:
return True
return False
