<s> from Tkinter import * <EOL> from geometry import * <EOL> import heapq <EOL> import copy <EOL> import random <EOL> import solutions <EOL> import math <EOL> from math import sin , cos , pi <EOL> class Struct ( object ) : pass <EOL> def loadObject ( path , index ) : <EOL> with open ( path ) as file : <EOL> try : data = file . read ( ) <EOL> except Exception as e : <EOL> print '<STR_LIT>' , e <EOL> return eval ( data ) [ index ] <EOL> def drawChevron ( canvas , cx , cy , r ) : <EOL> coords = ( cx - <NUM_LIT> * r , cy - <NUM_LIT:0.5> * r , <EOL> cx - <NUM_LIT> * r , cy - <NUM_LIT:0.5> * r , <EOL> cx + <NUM_LIT> * r , cy , <EOL> cx - <NUM_LIT> * r , cy + <NUM_LIT:0.5> * r , <EOL> cx - <NUM_LIT> * r , cy + <NUM_LIT:0.5> * r , <EOL> cx - <NUM_LIT> * r , cy + <NUM_LIT> * r , <EOL> cx + <NUM_LIT> * r , cy , <EOL> cx - <NUM_LIT> * r , cy - <NUM_LIT> * r ) <EOL> canvas . create_polygon ( * coords , fill = '<STR_LIT>' , state = '<STR_LIT>' ) <EOL> def brief ( L ) : <EOL> s = '<STR_LIT>' <EOL> for e in L : <EOL> s += str ( e [ <NUM_LIT:0> ] ) <EOL> return s <EOL> def reversal ( move ) : <EOL> if type ( move ) == tuple : <EOL> move = move [ <NUM_LIT:0> ] <EOL> if type ( move ) == str : <EOL> if "<STR_LIT:'>" in move : <EOL> move = move [ <NUM_LIT:0> ] <EOL> else : <EOL> move = move + "<STR_LIT:'>" <EOL> return move <EOL> def darken ( color ) : <EOL> if color [ <NUM_LIT:0> ] != '<STR_LIT:#>' : <EOL> if color == '<STR_LIT>' : <EOL> color = '<STR_LIT>' <EOL> elif color == '<STR_LIT>' : <EOL> color = '<STR_LIT>' <EOL> elif color == '<STR_LIT>' : <EOL> color = '<STR_LIT>' <EOL> elif color == '<STR_LIT>' : <EOL> color = '<STR_LIT>' <EOL> elif color == '<STR_LIT>' : <EOL> color = '<STR_LIT>' <EOL> elif color == '<STR_LIT>' : <EOL> color = '<STR_LIT>' <EOL> else : return color <EOL> return darken ( color ) <EOL> else : <EOL> red = int ( color [ <NUM_LIT:1> : <NUM_LIT:3> ] , <NUM_LIT:16> ) <EOL> green = int ( color [ <NUM_LIT:3> : <NUM_LIT:5> ] , <NUM_LIT:16> ) <EOL> blue = int ( color [ <NUM_LIT:5> : <NUM_LIT:7> ] , <NUM_LIT:16> ) <EOL> red /= <NUM_LIT:2> <EOL> green /= <NUM_LIT:2> <EOL> blue /= <NUM_LIT:2> <EOL> return '<STR_LIT>' % ( red , green , blue ) <EOL> class CenterPiece ( object ) : <EOL> def __init__ ( self , vec , parent ) : <EOL> self . vec = vec <EOL> self . parent = parent <EOL> def callback ( self , e ) : <EOL> self . parent . addMoves ( [ self . vec ] , self . PLAYING ) <EOL> class Cube ( object ) : <EOL> directions = { I_HAT : '<STR_LIT>' , <EOL> - I_HAT : '<STR_LIT>' , <EOL> J_HAT : '<STR_LIT>' , <EOL> - J_HAT : '<STR_LIT>' , <EOL> K_HAT : '<STR_LIT>' , <EOL> - K_HAT : '<STR_LIT>' } <EOL> helpStrings = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:info>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> faceColors = { } <EOL> @ classmethod <EOL> def setFaceColors ( cls ) : <EOL> cls . faceColors = { } <EOL> for z in xrange ( <NUM_LIT:3> ) : <EOL> for y in xrange ( <NUM_LIT:3> ) : <EOL> for x in xrange ( <NUM_LIT:3> ) : <EOL> pieceId = z * <NUM_LIT:9> + y * <NUM_LIT:3> + x + <NUM_LIT:1> <EOL> cls . faceColors [ pieceId ] = [ ] <EOL> ( X , Y , Z ) = ( x - <NUM_LIT:1> , y - <NUM_LIT:1> , z - <NUM_LIT:1> ) <EOL> pos = Vector ( X , Y , Z ) <EOL> for vec in [ Vector ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> ) , Vector ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> ) , Vector ( <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> ) ] : <EOL> for direction in cls . directions : <EOL> if direction // vec : <EOL> if direction ** pos > <NUM_LIT:0> : <EOL> cls . faceColors [ pieceId ] . append ( cls . directions [ direction ] ) <EOL> def __init__ ( self , canvas , controlPane , app , mode = '<STR_LIT>' ) : <EOL> Cube . setFaceColors ( ) <EOL> self . state = CubeState ( mode ) <EOL> self . faces = { } <EOL> self . size = <NUM_LIT:3> <EOL> self . center = Vector ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> self . app = app <EOL> ( self . PAUSED , self . PLAYING , self . REVERSING , self . STEP , self . BACK ) = ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ) <EOL> self . status = self . PAUSED <EOL> ( self . INGAME , self . SHOWINGINFO , self . SHOWINGSTATS ) = range ( <NUM_LIT:3> ) <EOL> self . helpState = self . SHOWINGINFO <EOL> self . statString = '<STR_LIT>' <EOL> self . helpIndex = '<STR_LIT>' <EOL> self . shuffling = False <EOL> self . delay = <NUM_LIT:100> <EOL> self . direction = ( <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> self . after = <NUM_LIT:0> <EOL> self . debug = False <EOL> self . message = "<STR_LIT>" <EOL> self . sol = '<STR_LIT>' <EOL> self . shuffleLen = <NUM_LIT:200> <EOL> self . moveList = [ ] <EOL> self . moveIndex = - <NUM_LIT:1> <EOL> self . controlPane = controlPane <EOL> self . timeBetweenRotations = <NUM_LIT:0> <EOL> self . timeUntilNextRotation = <NUM_LIT:0> <EOL> self . rotating = False <EOL> self . rotationAxis = False <EOL> self . rotationDirection = False <EOL> self . rotationCount = <NUM_LIT:0> <EOL> self . maxRot = <NUM_LIT:5> <EOL> self . rotationQueue = [ ] <EOL> self . rotatingValues = [ ] <EOL> self . sensitivity = <NUM_LIT> <EOL> self . showingPB = False <EOL> self . pbMin = <NUM_LIT:0> <EOL> self . pbVal = <NUM_LIT:0> <EOL> self . pbMax = <NUM_LIT:0> <EOL> self . paused = False <EOL> self . configureControls ( controlPane ) <EOL> self . configureWindow ( canvas ) <EOL> self . showInWindow ( ) <EOL> @ property <EOL> def maxRot ( self ) : <EOL> return self . maxRotationCount <EOL> @ maxRot . setter <EOL> def maxRot ( self , value ) : <EOL> self . maxRotationCount = value <EOL> self . rotationDTheta = math . pi / ( <NUM_LIT> * self . maxRotationCount ) <EOL> @ maxRot . deleter <EOL> def maxRot ( self ) : <EOL> pass <EOL> def configureControls ( self , pane ) : <EOL> pane . delete ( ALL ) <EOL> width = int ( pane . cget ( '<STR_LIT:width>' ) ) <EOL> height = int ( pane . cget ( '<STR_LIT>' ) ) <EOL> r = <NUM_LIT> <EOL> ( cx , cy ) = ( width / <NUM_LIT:2> , height / <NUM_LIT:2> ) <EOL> pauseButton = pane . create_oval ( cx - r , cy - r , cx + r , cy + r , <EOL> fill = '<STR_LIT>' , activefill = '<STR_LIT>' , <EOL> outline = '<STR_LIT>' , width = <NUM_LIT:1> , activewidth = <NUM_LIT:3> ) <EOL> pane . tag_bind ( pauseButton , '<STR_LIT>' , self . pause ) <EOL> pane . create_rectangle ( cx - ( r * <NUM_LIT> ) , cy - ( r * <NUM_LIT:0.5> ) , <EOL> cx - ( r * <NUM_LIT> ) , cy + ( r * <NUM_LIT:0.5> ) , fill = '<STR_LIT>' , <EOL> state = '<STR_LIT>' ) <EOL> pane . create_rectangle ( cx + ( r * <NUM_LIT> ) , cy - ( r * <NUM_LIT:0.5> ) , <EOL> cx + ( r * <NUM_LIT> ) , cy + ( r * <NUM_LIT:0.5> ) , fill = '<STR_LIT>' , <EOL> state = '<STR_LIT>' ) <EOL> pane . tag_bind ( pauseButton , '<STR_LIT>' , lambda e : self . assignHelp ( '<STR_LIT>' ) ) <EOL> pane . tag_bind ( pauseButton , '<STR_LIT>' , lambda e : self . assignHelp ( '<STR_LIT>' ) ) <EOL> ( cx , cy ) = ( width / <NUM_LIT:2> + r * <NUM_LIT> , height / <NUM_LIT:2> ) <EOL> playButton = pane . create_oval ( cx - r , cy - r , cx + r , cy + r , <EOL> fill = '<STR_LIT>' , activefill = '<STR_LIT>' , <EOL> outline = '<STR_LIT>' , width = <NUM_LIT:1> , activewidth = <NUM_LIT:3> ) <EOL> pane . tag_bind ( playButton , '<STR_LIT>' , self . play ) <EOL> pane . create_polygon ( cx - r * <NUM_LIT> , cy - r * <NUM_LIT:0.5> , <EOL> cx + r * <NUM_LIT> , cy , <EOL> cx - r * <NUM_LIT> , cy + r * <NUM_LIT:0.5> , fill = '<STR_LIT>' , <EOL> state = '<STR_LIT>' ) <EOL> pane . tag_bind ( playButton , '<STR_LIT>' , lambda e : self . assignHelp ( '<STR_LIT>' ) ) <EOL> pane . tag_bind ( playButton , '<STR_LIT>' , lambda e : self . assignHelp ( '<STR_LIT>' ) ) <EOL> ( cx , cy ) = ( width / <NUM_LIT:2> - r * <NUM_LIT> , height / <NUM_LIT:2> ) <EOL> reverseButton = pane . create_oval ( cx - r , cy - r , cx + r , cy + r , <EOL> fill = '<STR_LIT>' , activefill = '<STR_LIT>' , <EOL> outline = '<STR_LIT>' , width = <NUM_LIT:1> , activewidth = <NUM_LIT:3> ) <EOL> pane . tag_bind ( reverseButton , '<STR_LIT>' , self . reverse ) <EOL> pane . create_polygon ( cx + r * <NUM_LIT> , cy - r * <NUM_LIT:0.5> , <EOL> cx - r * <NUM_LIT> , cy , <EOL> cx + r * <NUM_LIT> , cy + r * <NUM_LIT:0.5> , fill = '<STR_LIT>' , <EOL> state = '<STR_LIT>' ) <EOL> pane . tag_bind ( reverseButton , '<STR_LIT>' , lambda e : self . assignHelp ( '<STR_LIT>' ) ) <EOL> pane . tag_bind ( reverseButton , '<STR_LIT>' , lambda e : self . assignHelp ( '<STR_LIT>' ) ) <EOL> ( cx , cy ) = ( width / <NUM_LIT:2> + r * <NUM_LIT> , height / <NUM_LIT:2> ) <EOL> speedUpButton = pane . create_rectangle ( cx - r , cy - r , cx + r , cy + r , <EOL> fill = '<STR_LIT>' , activefill = '<STR_LIT>' , <EOL> outline = '<STR_LIT>' , width = <NUM_LIT:1> , activewidth = <NUM_LIT:3> ) <EOL> pane . tag_bind ( speedUpButton , '<STR_LIT>' , self . speedUp ) <EOL> drawChevron ( pane , cx , cy , r ) <EOL> drawChevron ( pane , cx - <NUM_LIT> * r , cy , r * <NUM_LIT> ) <EOL> drawChevron ( pane , cx + <NUM_LIT> * r , cy , r * <NUM_LIT> ) <EOL> pane . tag_bind ( speedUpButton , '<STR_LIT>' , lambda e : self . assignHelp ( '<STR_LIT>' ) ) <EOL> pane . tag_bind ( speedUpButton , '<STR_LIT>' , lambda e : self . assignHelp ( '<STR_LIT>' ) ) <EOL> ( cx , cy ) = ( width / <NUM_LIT:2> + r * <NUM_LIT> , height / <NUM_LIT:2> ) <EOL> slowDownButton = pane . create_rectangle ( cx - r , cy - r , cx + r , cy + r , <EOL> fill = '<STR_LIT>' , activefill = '<STR_LIT>' , <EOL> outline = '<STR_LIT>' , width = <NUM_LIT:1> , activewidth = <NUM_LIT:3> ) <EOL> pane . tag_bind ( slowDownButton , '<STR_LIT>' , self . slowDown ) <EOL> drawChevron ( pane , cx - <NUM_LIT> * r , cy , r * <NUM_LIT> ) <EOL> drawChevron ( pane , cx , cy , r ) <EOL> pane . tag_bind ( slowDownButton , '<STR_LIT>' , lambda e : self . assignHelp ( '<STR_LIT>' ) ) <EOL> pane . tag_bind ( slowDownButton , '<STR_LIT>' , lambda e : self . assignHelp ( '<STR_LIT>' ) ) <EOL> ( cx , cy ) = ( r * <NUM_LIT> , height / <NUM_LIT:2> ) <EOL> shuffleButton = pane . create_oval ( cx - r , cy - r , cx + r , cy + r , <EOL> fill = '<STR_LIT>' , activefill = '<STR_LIT>' , <EOL> outline = '<STR_LIT>' , width = <NUM_LIT:1> , activewidth = <NUM_LIT:3> ) <EOL> pane . tag_bind ( shuffleButton , '<STR_LIT>' , self . shuffle ) <EOL> coords = ( cx - <NUM_LIT> * r , cy - <NUM_LIT> * r , <EOL> cx - <NUM_LIT> * r , cy - <NUM_LIT> * r , <EOL> cx - <NUM_LIT> * r , cy - <NUM_LIT> * r , <EOL> cx + <NUM_LIT> * r , cy + <NUM_LIT> * r , <EOL> cx + <NUM_LIT> * r , cy + <NUM_LIT> * r , <EOL> cx + <NUM_LIT> * r , cy + <NUM_LIT> * r , <EOL> cx + <NUM_LIT> * r , cy + <NUM_LIT> * r , <EOL> cx + <NUM_LIT> * r , cy - <NUM_LIT:0.0> * r , <EOL> cx + <NUM_LIT> * r , cy + <NUM_LIT> * r , <EOL> cx + <NUM_LIT> * r , cy + <NUM_LIT> * r , <EOL> cx - <NUM_LIT> * r , cy - <NUM_LIT> * r , <EOL> cx - <NUM_LIT> * r , cy - <NUM_LIT> * r ) <EOL> pane . create_polygon ( * coords , outline = '<STR_LIT>' , fill = '<STR_LIT>' , state = '<STR_LIT>' ) <EOL> coords = ( cx - <NUM_LIT> * r , cy + <NUM_LIT> * r , <EOL> cx - <NUM_LIT> * r , cy + <NUM_LIT> * r , <EOL> cx - <NUM_LIT> * r , cy + <NUM_LIT> * r , <EOL> cx + <NUM_LIT> * r , cy - <NUM_LIT> * r , <EOL> cx + <NUM_LIT> * r , cy - <NUM_LIT> * r , <EOL> cx + <NUM_LIT> * r , cy - <NUM_LIT> * r , <EOL> cx + <NUM_LIT> * r , cy - <NUM_LIT> * r , <EOL> cx + <NUM_LIT> * r , cy - <NUM_LIT:0.0> * r , <EOL> cx + <NUM_LIT> * r , cy - <NUM_LIT> * r , <EOL> cx + <NUM_LIT> * r , cy - <NUM_LIT> * r , <EOL> cx - <NUM_LIT> * r , cy + <NUM_LIT> * r , <EOL> cx - <NUM_LIT> * r , cy + <NUM_LIT> * r ) <EOL> pane . create_polygon ( * coords , outline = '<STR_LIT>' , fill = '<STR_LIT>' , state = '<STR_LIT>' ) <EOL> pane . tag_bind ( shuffleButton , '<STR_LIT>' , lambda e : self . assignHelp ( '<STR_LIT>' ) ) <EOL> pane . tag_bind ( shuffleButton , '<STR_LIT>' , lambda e : self . assignHelp ( '<STR_LIT>' ) ) <EOL> ( cx , cy ) = ( r * <NUM_LIT> , height / <NUM_LIT:2> ) <EOL> solveButton = pane . create_oval ( cx - r , cy - r , cx + r , cy + r , <EOL> fill = '<STR_LIT>' , activefill = '<STR_LIT>' , <EOL> outline = '<STR_LIT>' , width = <NUM_LIT:1> , activewidth = <NUM_LIT:3> ) <EOL> pane . tag_bind ( solveButton , '<STR_LIT>' , self . solve ) <EOL> pane . create_text ( cx , cy , text = '<STR_LIT>' , fill = '<STR_LIT>' , state = '<STR_LIT>' ) <EOL> pane . tag_bind ( solveButton , '<STR_LIT>' , lambda e : self . assignHelp ( '<STR_LIT>' ) ) <EOL> pane . tag_bind ( solveButton , '<STR_LIT>' , lambda e : self . assignHelp ( '<STR_LIT>' ) ) <EOL> ( cx , cy ) = ( r * <NUM_LIT> , height / <NUM_LIT:2> ) <EOL> resetButton = pane . create_oval ( cx - r , cy - r , cx + r , cy + r , <EOL> fill = '<STR_LIT>' , activefill = '<STR_LIT>' , <EOL> outline = '<STR_LIT>' , width = <NUM_LIT:1> , activewidth = <NUM_LIT:3> ) <EOL> pane . tag_bind ( resetButton , '<STR_LIT>' , self . reset ) <EOL> pane . create_text ( cx , cy , text = '<STR_LIT>' , fill = '<STR_LIT>' , state = '<STR_LIT>' ) <EOL> pane . tag_bind ( resetButton , '<STR_LIT>' , lambda e : self . assignHelp ( '<STR_LIT>' ) ) <EOL> pane . tag_bind ( resetButton , '<STR_LIT>' , lambda e : self . assignHelp ( '<STR_LIT>' ) ) <EOL> ( cx , cy ) = ( r * <NUM_LIT> , height / <NUM_LIT:2> ) <EOL> fromcamButton = pane . create_oval ( cx - r , cy - r , cx + r , cy + r , <EOL> fill = '<STR_LIT>' , activefill = '<STR_LIT>' , <EOL> outline = '<STR_LIT>' , width = <NUM_LIT:1> , activewidth = <NUM_LIT:3> ) <EOL> pane . tag_bind ( fromcamButton , '<STR_LIT>' , self . fromCamera ) <EOL> pane . create_text ( cx , cy - <NUM_LIT:12> , text = '<STR_LIT>' , fill = '<STR_LIT>' , state = '<STR_LIT>' ) <EOL> pane . create_text ( cx , cy , text = '<STR_LIT>' , fill = '<STR_LIT>' , state = '<STR_LIT>' ) <EOL> pane . tag_bind ( fromcamButton , '<STR_LIT>' , lambda e : self . assignHelp ( '<STR_LIT>' ) ) <EOL> pane . tag_bind ( fromcamButton , '<STR_LIT>' , lambda e : self . assignHelp ( '<STR_LIT>' ) ) <EOL> ( cx , cy ) = ( r * <NUM_LIT> , height / <NUM_LIT:2> ) <EOL> guideButton = pane . create_rectangle ( cx - <NUM_LIT:2> * r , cy - r , cx + <NUM_LIT:2> * r , cy + r , <EOL> fill = '<STR_LIT>' , activefill = '<STR_LIT>' , <EOL> outline = '<STR_LIT>' , width = <NUM_LIT:1> , activewidth = <NUM_LIT:3> ) <EOL> pane . tag_bind ( guideButton , '<STR_LIT>' , self . guideThrough ) <EOL> pane . create_text ( cx , cy - <NUM_LIT:12> , text = '<STR_LIT>' , fill = '<STR_LIT>' , state = '<STR_LIT>' ) <EOL> pane . create_text ( cx , cy , text = '<STR_LIT>' , fill = '<STR_LIT>' , state = '<STR_LIT>' ) <EOL> pane . tag_bind ( guideButton , '<STR_LIT>' , lambda e : self . assignHelp ( '<STR_LIT>' ) ) <EOL> pane . tag_bind ( guideButton , '<STR_LIT>' , lambda e : self . assignHelp ( '<STR_LIT>' ) ) <EOL> ( cx , cy ) = ( r * <NUM_LIT> , height / <NUM_LIT:2> ) <EOL> guideFastButton = pane . create_rectangle ( cx - <NUM_LIT> * r , cy - r , cx + <NUM_LIT> * r , cy + r , <EOL> fill = '<STR_LIT>' , activefill = '<STR_LIT>' , <EOL> outline = '<STR_LIT>' , width = <NUM_LIT:1> , activewidth = <NUM_LIT:3> ) <EOL> pane . tag_bind ( guideFastButton , '<STR_LIT>' , self . guideFastThrough ) <EOL> pane . create_text ( cx , cy - <NUM_LIT:12> , text = '<STR_LIT>' , fill = '<STR_LIT>' , state = '<STR_LIT>' ) <EOL> pane . create_text ( cx , cy , text = '<STR_LIT>' , fill = '<STR_LIT>' , state = '<STR_LIT>' ) <EOL> pane . tag_bind ( guideFastButton , '<STR_LIT>' , lambda e : self . assignHelp ( '<STR_LIT>' ) ) <EOL> pane . tag_bind ( guideFastButton , '<STR_LIT>' , lambda e : self . assignHelp ( '<STR_LIT>' ) ) <EOL> r = <NUM_LIT> <EOL> ( cx , cy ) = ( width / <NUM_LIT:2> - r * <NUM_LIT> , height / <NUM_LIT:2> ) <EOL> backButton = pane . create_oval ( cx - r , cy - r , cx + r , cy + r , <EOL> fill = '<STR_LIT>' , activefill = '<STR_LIT>' , <EOL> outline = '<STR_LIT>' , width = <NUM_LIT:1> , activewidth = <NUM_LIT:3> ) <EOL> pane . tag_bind ( backButton , '<STR_LIT>' , self . back ) <EOL> pane . create_polygon ( cx + r * <NUM_LIT> , cy - r * <NUM_LIT:0.5> , <EOL> cx - r * <NUM_LIT> , cy , <EOL> cx + r * <NUM_LIT> , cy + r * <NUM_LIT:0.5> , fill = '<STR_LIT>' , <EOL> state = '<STR_LIT>' ) <EOL> pane . tag_bind ( backButton , '<STR_LIT>' , lambda e : self . assignHelp ( '<STR_LIT>' ) ) <EOL> pane . tag_bind ( backButton , '<STR_LIT>' , lambda e : self . assignHelp ( '<STR_LIT>' ) ) <EOL> ( cx , cy ) = ( width / <NUM_LIT:2> + r * <NUM_LIT> , height / <NUM_LIT:2> ) <EOL> stepButton = pane . create_oval ( cx - r , cy - r , cx + r , cy + r , <EOL> fill = '<STR_LIT>' , activefill = '<STR_LIT>' , <EOL> outline = '<STR_LIT>' , width = <NUM_LIT:1> , activewidth = <NUM_LIT:3> ) <EOL> pane . tag_bind ( stepButton , '<STR_LIT>' , self . step ) <EOL> pane . create_polygon ( cx - r * <NUM_LIT> , cy - r * <NUM_LIT:0.5> , <EOL> cx + r * <NUM_LIT> , cy , <EOL> cx - r * <NUM_LIT> , cy + r * <NUM_LIT:0.5> , fill = '<STR_LIT>' , <EOL> state = '<STR_LIT>' ) <EOL> pane . tag_bind ( stepButton , '<STR_LIT>' , lambda e : self . assignHelp ( '<STR_LIT>' ) ) <EOL> pane . tag_bind ( stepButton , '<STR_LIT>' , lambda e : self . assignHelp ( '<STR_LIT>' ) ) <EOL> ( cx , cy ) = ( width - r * <NUM_LIT> , height / <NUM_LIT:2> ) <EOL> helpButton = pane . create_rectangle ( cx - <NUM_LIT:2> * r , cy - r , cx + <NUM_LIT:2> * r , cy + r , <EOL> fill = '<STR_LIT>' , activefill = '<STR_LIT>' , <EOL> outline = '<STR_LIT>' , width = <NUM_LIT:1> , activewidth = <NUM_LIT:3> ) <EOL> pane . tag_bind ( helpButton , '<STR_LIT>' , lambda e : self . assignHelpState ( self . SHOWINGINFO ) ) <EOL> pane . create_text ( cx , cy , text = '<STR_LIT>' , fill = '<STR_LIT>' , state = '<STR_LIT>' ) <EOL> pane . tag_bind ( helpButton , '<STR_LIT>' , lambda e : self . assignHelp ( '<STR_LIT:info>' ) ) <EOL> pane . tag_bind ( helpButton , '<STR_LIT>' , lambda e : self . assignHelp ( '<STR_LIT>' ) ) <EOL> ( cx , cy ) = ( width - r * <NUM_LIT> , height / <NUM_LIT:2> ) <EOL> statsButton = pane . create_rectangle ( cx - <NUM_LIT:2> * r , cy - r , cx + <NUM_LIT:2> * r , cy + r , <EOL> fill = '<STR_LIT>' , activefill = '<STR_LIT>' , <EOL> outline = '<STR_LIT>' , width = <NUM_LIT:1> , activewidth = <NUM_LIT:3> ) <EOL> pane . tag_bind ( statsButton , '<STR_LIT>' , self . showStats ) <EOL> pane . create_text ( cx , cy , text = '<STR_LIT>' , fill = '<STR_LIT>' , state = '<STR_LIT>' ) <EOL> pane . tag_bind ( statsButton , '<STR_LIT>' , lambda e : self . assignHelp ( '<STR_LIT>' ) ) <EOL> pane . tag_bind ( statsButton , '<STR_LIT>' , lambda e : self . assignHelp ( '<STR_LIT>' ) ) <EOL> def configureWindow ( self , canvas ) : <EOL> if canvas == None : <EOL> self . root = Tk ( ) <EOL> ( self . width , self . height ) = ( <NUM_LIT> , <NUM_LIT> ) <EOL> self . canvas = Canvas ( self . root , width = self . width , height = self . height , background = '<STR_LIT>' ) <EOL> self . needsLoop = True <EOL> else : <EOL> self . root = canvas . _root ( ) <EOL> self . canvas = canvas <EOL> ( self . width , self . height ) = ( int ( canvas . cget ( '<STR_LIT:width>' ) ) , int ( canvas . cget ( '<STR_LIT>' ) ) ) <EOL> self . needsLoop = False <EOL> self . dim = { '<STR_LIT:width>' : self . width , '<STR_LIT>' : self . height } <EOL> def speedUp ( self , e ) : <EOL> self . maxRot = max ( <NUM_LIT:1> , self . maxRot - <NUM_LIT:1> ) <EOL> def slowDown ( self , e ) : <EOL> self . maxRot += <NUM_LIT:1> <EOL> def timer ( self ) : <EOL> needsRedraw = self . move ( ) or ( not self . status == self . PAUSED ) <EOL> if self . rotating : <EOL> self . rotationCount -= <NUM_LIT:1> <EOL> if self . rotationCount <= <NUM_LIT:0> : <EOL> self . rotating = False <EOL> self . rotatingValues = [ ] <EOL> self . state . rotate ( self . rotationItem ) <EOL> del self . rotationItem <EOL> needsRedraw = True <EOL> if self . timeUntilNextRotation > <NUM_LIT:0> : <EOL> self . timeUntilNextRotation -= <NUM_LIT:1> <EOL> if ( not self . rotating ) and ( self . timeUntilNextRotation <= <NUM_LIT:0> ) : <EOL> if ( self . status == self . PLAYING ) or ( self . status == self . STEP ) : <EOL> if self . moveIndex >= ( len ( self . moveList ) - <NUM_LIT:1> ) : <EOL> self . status = self . PAUSED <EOL> self . updateMessage ( '<STR_LIT>' ) <EOL> self . shuffling = False <EOL> else : <EOL> self . moveIndex += <NUM_LIT:1> <EOL> needsRedraw = self . makeMove ( self . moveList [ self . moveIndex ] , <EOL> animate = not self . shuffling , <EOL> render = not self . shuffling or ( self . moveIndex % <NUM_LIT:20> == <NUM_LIT:0> ) ) <EOL> if ( self . status == self . REVERSING ) or ( self . status == self . BACK ) : <EOL> if self . moveIndex < <NUM_LIT:0> : <EOL> self . status = self . PAUSED <EOL> else : <EOL> needsRedraw = self . makeMove ( reversal ( self . moveList [ self . moveIndex ] ) ) <EOL> self . moveIndex -= <NUM_LIT:1> <EOL> if ( self . status == self . STEP ) or ( self . status == self . BACK ) : <EOL> self . status = self . PAUSED <EOL> self . timeUntilNextRotation = self . timeBetweenRotations <EOL> if needsRedraw : <EOL> try : <EOL> self . redraw ( ) <EOL> except : <EOL> self . updateMessage ( '<STR_LIT>' ) <EOL> self . state . setSolved ( ) <EOL> self . redraw ( ) <EOL> def updateMessage ( self , msg ) : <EOL> self . message = msg <EOL> def updateSol ( self , msg ) : <EOL> self . sol = msg <EOL> def showInWindow ( self ) : <EOL> self . canvas . pack ( ) <EOL> self . camera = Camera ( Vector ( <NUM_LIT:4> , - <NUM_LIT> , - <NUM_LIT:7> ) , Vector ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) , pi / <NUM_LIT:5> , self . dim ) <EOL> self . amt = self . camera . sensitivity * self . camera . pos . dist ( self . camera . origin ) <EOL> self . redraw ( ) <EOL> if self . needsLoop : root . mainloop ( ) <EOL> def cleanup ( self ) : <EOL> for pg in self . faces . values ( ) : <EOL> self . canvas . itemconfig ( pg , state = '<STR_LIT>' ) <EOL> def move ( self ) : <EOL> self . amt = self . camera . sensitivity * self . camera . pos . dist ( self . camera . origin ) <EOL> redraw = False <EOL> if self . direction != ( <NUM_LIT:0> , <NUM_LIT:0> ) : <EOL> self . camera . rotate ( self . direction ) <EOL> redraw = True <EOL> if self . app . resized : <EOL> self . app . dragVal = ( <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> self . app . resized = False <EOL> redraw = True <EOL> elif self . app . dragVal != ( <NUM_LIT:0> , <NUM_LIT:0> ) : <EOL> self . camera . rotate ( ( - self . sensitivity * self . app . dragVal [ <NUM_LIT:0> ] , <EOL> - self . sensitivity * self . app . dragVal [ <NUM_LIT:1> ] ) ) <EOL> redraw = True <EOL> self . app . dragVal = ( self . app . dragVal [ <NUM_LIT:0> ] * <NUM_LIT> , <EOL> self . app . dragVal [ <NUM_LIT:1> ] * <NUM_LIT> ) <EOL> if self . app . dragVal [ <NUM_LIT:0> ] < <NUM_LIT> and self . app . dragVal [ <NUM_LIT:1> ] < <NUM_LIT> : <EOL> self . app . dragVal = ( <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> return redraw <EOL> @ staticmethod <EOL> def corners ( center , direction , * args ) : <EOL> if len ( args ) == <NUM_LIT:0> : <EOL> if direction // Vector ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> ) : <EOL> norm1 = Vector ( <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> else : norm1 = Vector ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> ) <EOL> norm2 = <NUM_LIT:2> * direction * norm1 <EOL> else : ( norm1 , norm2 ) = args <EOL> corners = [ ] <EOL> for coef1 in xrange ( - <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:2> ) : <EOL> for coef2 in xrange ( coef1 , - <NUM_LIT:2> * coef1 , - <NUM_LIT:2> * coef1 ) : <EOL> corner = center + ( <NUM_LIT:0.5> * norm1 * coef1 + <EOL> <NUM_LIT:0.5> * norm2 * coef2 ) <EOL> corners . append ( corner ) <EOL> return corners <EOL> def pieceOffset ( self , x , y , z ) : <EOL> z -= <NUM_LIT:1> <EOL> y -= <NUM_LIT:1> <EOL> x -= <NUM_LIT:1> <EOL> return Vector ( x , y , z ) <EOL> def redraw ( self ) : <EOL> self . canvas . delete ( ALL ) <EOL> self . canvas . create_text ( self . camera . width / <NUM_LIT:2> , <NUM_LIT> , text = self . message , fill = '<STR_LIT>' , font = '<STR_LIT>' ) <EOL> sol = self . sol <EOL> lineWidth = <NUM_LIT:100> <EOL> margin = <NUM_LIT:15> <EOL> y = self . camera . height - margin - <NUM_LIT:20> <EOL> while len ( sol ) > <NUM_LIT:0> : <EOL> self . canvas . create_text ( self . camera . width / <NUM_LIT:2> , <EOL> y , text = sol [ - lineWidth : ] , fill = '<STR_LIT>' , font = '<STR_LIT>' ) <EOL> y -= margin <EOL> sol = sol [ : - lineWidth ] <EOL> if self . showingPB : <EOL> w = ( self . width * ( self . moveIndex - self . pbMin + <NUM_LIT:1> ) / <EOL> ( max ( <NUM_LIT:1> , self . pbMax - self . pbMin ) ) ) <EOL> self . canvas . create_rectangle ( <NUM_LIT:0> , self . height - <NUM_LIT:20> , w , self . height , fill = '<STR_LIT>' ) <EOL> toDraw = [ ] <EOL> for z in xrange ( self . size ) : <EOL> for y in xrange ( self . size ) : <EOL> for x in xrange ( self . size ) : <EOL> try : <EOL> ( pieceID , rotationKey ) = self . state . state [ z ] [ y ] [ x ] <EOL> except : <EOL> pieceID = <NUM_LIT:1> <EOL> rotationKey = <NUM_LIT> <EOL> pieceCenter = self . center + self . pieceOffset ( x , y , z ) <EOL> outDirections = [ d for d in Cube . directions if d ** pieceCenter > <NUM_LIT:0> ] <EOL> sod = [ ] <EOL> for od in outDirections : <EOL> if od // CubeState . keys [ rotationKey / <NUM_LIT:100> ] : <EOL> sod . append ( od ) <EOL> for od in outDirections : <EOL> if od // CubeState . keys [ ( rotationKey / <NUM_LIT:10> ) % <NUM_LIT:10> ] : <EOL> sod . append ( od ) <EOL> for od in outDirections : <EOL> if od // CubeState . keys [ rotationKey % <NUM_LIT:10> ] : <EOL> sod . append ( od ) <EOL> pieceRotation = Vector ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> theta = <NUM_LIT:0.> <EOL> if pieceID in self . rotatingValues : <EOL> oldCenter = pieceCenter <EOL> pieceOffset = pieceCenter - ( pieceCenter > self . rotationAxis ) <EOL> pieceRotation = self . rotationAxis * pieceOffset <EOL> theta = self . rotationDTheta * ( self . maxRot - self . rotationCount ) <EOL> if self . rotationDirection : <EOL> theta *= - <NUM_LIT:1> <EOL> pieceCenter = ( pieceCenter > self . rotationAxis ) <EOL> pieceCenter = pieceCenter + cos ( theta ) * pieceOffset <EOL> pieceCenter = pieceCenter + sin ( theta ) * pieceRotation <EOL> faceColors = Cube . faceColors [ pieceID ] <EOL> for direc , color in zip ( sod , faceColors ) : <EOL> axes = ( ) <EOL> faceCenter = pieceCenter + ( direc / <NUM_LIT:2> ) <EOL> if pieceID in self . rotatingValues : <EOL> if direc // self . rotationAxis : <EOL> faceCenter = pieceCenter + ( direc / <NUM_LIT:2> ) <EOL> if self . rotationAxis // Vector ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> ) : <EOL> axis0temp = Vector ( <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> else : <EOL> axis0temp = Vector ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> ) <EOL> axis1temp = direc * axis0temp <EOL> axis0 = axis0temp * cos ( theta ) + axis1temp * sin ( theta ) <EOL> axis1 = axis0 * direc <EOL> axes = ( axis0 , axis1 ) <EOL> else : <EOL> perp = - <NUM_LIT:1> * ( direc * self . rotationAxis ) <EOL> perp = perp ^ ( direc . mag ) <EOL> faceCenter = pieceCenter + ( sin ( theta ) * ( perp / <NUM_LIT:2> ) + <EOL> cos ( theta ) * ( direc / <NUM_LIT:2> ) ) <EOL> axis0 = self . rotationAxis <EOL> axis1 = ( faceCenter - pieceCenter ) * self . rotationAxis * <NUM_LIT:2> <EOL> axes = ( axis0 , axis1 ) <EOL> visible = ( faceCenter - pieceCenter ) ** ( faceCenter - self . camera . pos ) < <NUM_LIT:0> <EOL> corners = self . corners ( faceCenter , pieceCenter - faceCenter , * axes ) <EOL> corners = [ corner . flatten ( self . camera ) for corner in corners ] <EOL> state = '<STR_LIT>' <EOL> outline = '<STR_LIT>' if visible else '<STR_LIT>' <EOL> if not visible : color = '<STR_LIT>' <EOL> a = <NUM_LIT:0> if visible else <NUM_LIT:1000> <EOL> spec = ( corners , color , state , outline ) <EOL> toDraw . append ( ( ( pieceCenter - self . camera . pos ) . mag + a , spec ) ) <EOL> if self . debug : <EOL> self . canvas . create_text ( faceCenter . flatten ( self . camera ) , text = str ( pieceID ) ) <EOL> """<STR_LIT>""" <EOL> toDraw . sort ( lambda a , b : cmp ( b , a ) ) <EOL> for polygon in toDraw : <EOL> spec = polygon [ <NUM_LIT:1> ] <EOL> ( corners , color , state , outline ) = spec <EOL> self . canvas . create_polygon ( corners , fill = color , width = <NUM_LIT:2> , state = state , outline = outline ) <EOL> self . drawHelp ( ) <EOL> def gatherStats ( self ) : <EOL> self . statString = '<STR_LIT>' <EOL> stats = None <EOL> try : <EOL> with open ( '<STR_LIT>' ) as file : <EOL> stats = eval ( file . read ( ) ) <EOL> except : return <EOL> if stats is not None : <EOL> self . statString = '<STR_LIT>' <EOL> stats = [ s . split ( '<STR_LIT:;>' ) for s in stats ] <EOL> moves = [ stat [ - <NUM_LIT:1> ] for stat in stats ] <EOL> moves = [ mv [ <NUM_LIT:6> : ] for mv in moves ] <EOL> moves = [ int ( mv ) for mv in moves ] <EOL> if len ( moves ) == <NUM_LIT:0> : <EOL> self . statString += "<STR_LIT>" <EOL> return <EOL> self . statString += "<STR_LIT>" % ( len ( moves ) , '<STR_LIT>' if len ( moves ) == <NUM_LIT:1> else '<STR_LIT:s>' ) <EOL> avgMoves = sum ( moves ) / len ( moves ) <EOL> self . statString += "<STR_LIT>" % ( avgMoves ) <EOL> times = [ stat [ - <NUM_LIT:2> ] for stat in stats ] <EOL> times = [ tm [ <NUM_LIT:6> : - <NUM_LIT:4> ] for tm in times ] <EOL> times = [ float ( tm ) for tm in times ] <EOL> avgTime = sum ( times ) / ( max ( <NUM_LIT:1> , len ( times ) ) ) <EOL> self . statString += "<STR_LIT>" % ( avgTime ) <EOL> def resetStats ( self ) : <EOL> try : <EOL> with open ( '<STR_LIT>' , '<STR_LIT>' ) as file : <EOL> file . seek ( <NUM_LIT:0> ) <EOL> file . truncate ( ) <EOL> file . writelines ( [ '<STR_LIT>' ] ) <EOL> except : return <EOL> def showStats ( self , * args ) : <EOL> self . gatherStats ( ) <EOL> self . helpState = self . SHOWINGSTATS <EOL> def drawHelp ( self ) : <EOL> if self . helpState == self . SHOWINGINFO : <EOL> canvas = self . canvas <EOL> canvas . create_rectangle ( <NUM_LIT:100> , <NUM_LIT:100> , self . width - <NUM_LIT:100> , self . height - <NUM_LIT:100> , <EOL> fill = '<STR_LIT>' , outline = '<STR_LIT>' , width = <NUM_LIT:4> ) <EOL> canvas . create_rectangle ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , fill = '<STR_LIT>' , activefill = '<STR_LIT>' ) <EOL> canvas . create_text ( <NUM_LIT> , <NUM_LIT> , text = '<STR_LIT:X>' , fill = '<STR_LIT>' , state = '<STR_LIT>' ) <EOL> canvas . create_rectangle ( self . width / <NUM_LIT:2> - <NUM_LIT:50> , self . height - <NUM_LIT> , <EOL> self . width / <NUM_LIT:2> + <NUM_LIT:50> , self . height - <NUM_LIT> , <EOL> fill = '<STR_LIT>' , activefill = '<STR_LIT>' ) <EOL> canvas . create_text ( self . width / <NUM_LIT:2> , self . height - <NUM_LIT> , text = '<STR_LIT>' , fill = '<STR_LIT>' , state = '<STR_LIT>' ) <EOL> canvas . create_text ( self . width / <NUM_LIT:2> , <NUM_LIT> , text = "<STR_LIT>" , <EOL> font = '<STR_LIT>' ) <EOL> canvas . create_text ( self . width / <NUM_LIT:2> , self . height / <NUM_LIT:2> , text = self . helpStrings [ self . helpIndex ] ) <EOL> elif self . helpState == self . SHOWINGSTATS : <EOL> canvas = self . canvas <EOL> canvas . create_rectangle ( <NUM_LIT:100> , <NUM_LIT:100> , self . width - <NUM_LIT:100> , self . height - <NUM_LIT:100> , <EOL> fill = '<STR_LIT>' , outline = '<STR_LIT>' , width = <NUM_LIT:4> ) <EOL> canvas . create_rectangle ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , fill = '<STR_LIT>' , activefill = '<STR_LIT>' ) <EOL> canvas . create_text ( <NUM_LIT> , <NUM_LIT> , text = '<STR_LIT:X>' , fill = '<STR_LIT>' , state = '<STR_LIT>' ) <EOL> canvas . create_rectangle ( self . width / <NUM_LIT:2> - <NUM_LIT:50> , self . height - <NUM_LIT> , <EOL> self . width / <NUM_LIT:2> + <NUM_LIT:50> , self . height - <NUM_LIT> , <EOL> fill = '<STR_LIT>' , activefill = '<STR_LIT>' ) <EOL> canvas . create_text ( self . width / <NUM_LIT:2> , self . height - <NUM_LIT> , text = '<STR_LIT>' , fill = '<STR_LIT>' , state = '<STR_LIT>' ) <EOL> canvas . create_rectangle ( <NUM_LIT> , self . height - <NUM_LIT> , <NUM_LIT> , self . height - <NUM_LIT> , fill = '<STR_LIT>' , activefill = '<STR_LIT>' ) <EOL> canvas . create_text ( <NUM_LIT> , self . height - <NUM_LIT> , text = "<STR_LIT>" , state = '<STR_LIT>' ) <EOL> canvas . create_text ( self . width / <NUM_LIT:2> , self . height / <NUM_LIT:2> , text = self . statString , font = '<STR_LIT>' ) <EOL> def click ( self , event ) : <EOL> if self . helpState == self . SHOWINGINFO or self . helpState == self . SHOWINGSTATS : <EOL> if <NUM_LIT> < event . x < <NUM_LIT> and <NUM_LIT> < event . y < <NUM_LIT> : <EOL> self . helpState = self . INGAME <EOL> self . redraw ( ) <EOL> elif self . width / <NUM_LIT:2> - <NUM_LIT:50> < event . x < self . width / <NUM_LIT:2> + <NUM_LIT:50> and self . height - <NUM_LIT> < event . y < self . height - <NUM_LIT> : <EOL> self . helpState = self . INGAME <EOL> self . redraw ( ) <EOL> if self . helpState == self . SHOWINGSTATS : <EOL> if <NUM_LIT> < event . x < <NUM_LIT> and self . height - <NUM_LIT> < event . y < self . height - <NUM_LIT> : <EOL> self . resetStats ( ) <EOL> self . showStats ( ) <EOL> self . redraw ( ) <EOL> def assignHelp ( self , key ) : <EOL> self . helpIndex = key <EOL> self . redraw ( ) <EOL> def assignHelpState ( self , state ) : <EOL> self . helpState = state <EOL> self . redraw ( ) <EOL> def setConfig ( self , config ) : <EOL> try : <EOL> self . state = CubeState ( '<STR_LIT>' ) <EOL> if self . debug : <EOL> print self . state <EOL> def faceToAxis ( face ) : <EOL> if self . debug : <EOL> print face <EOL> center = face [ <NUM_LIT:1> ] [ <NUM_LIT:1> ] <EOL> axis = [ vec for vec in Cube . directions if <EOL> Cube . directions [ vec ] . lower ( ) == center . lower ( ) ] [ <NUM_LIT:0> ] <EOL> return axis <EOL> def setAxes ( normal , known , dirString ) : <EOL> dirString = dirString . lower ( ) <EOL> if dirString == '<STR_LIT>' : <EOL> up = known <EOL> elif dirString == '<STR_LIT>' : <EOL> up = known * - <NUM_LIT:1> <EOL> elif dirString == '<STR_LIT:left>' : <EOL> up = ( normal * known ) <EOL> elif dirString == '<STR_LIT:right>' : <EOL> up = ( known * normal ) <EOL> down = up * - <NUM_LIT:1> <EOL> left = ( up * normal ) <EOL> right = left * - <NUM_LIT:1> <EOL> return ( up , down , left , right ) <EOL> timesTouched = [ [ [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ] , [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ] , [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ] ] , [ [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ] , [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ] , [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ] ] , [ [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ] , [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ] , [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ] ] ] <EOL> for faceInfo in config : <EOL> axis = faceToAxis ( faceInfo . currentFace ) <EOL> prevAxis = nextAxis = None <EOL> if faceInfo . prevFace : <EOL> prevAxis = faceToAxis ( faceInfo . prevFace ) <EOL> if faceInfo . nextFace : <EOL> nextAxis = faceToAxis ( faceInfo . nextFace ) <EOL> prevTurn = faceInfo . prevTurn <EOL> nextTurn = faceInfo . nextTurn <EOL> if self . debug : <EOL> print '<STR_LIT>' , axis , Cube . directions [ axis ] <EOL> print '<STR_LIT>' , prevAxis , <EOL> if prevAxis : <EOL> print Cube . directions [ prevAxis ] <EOL> print '<STR_LIT>' , nextAxis , <EOL> if nextAxis : <EOL> print Cube . directions [ nextAxis ] <EOL> print '<STR_LIT>' , prevTurn <EOL> print '<STR_LIT>' , nextTurn <EOL> if prevTurn : <EOL> ( up , down , left , right ) = setAxes ( axis , prevAxis , prevTurn ) <EOL> elif nextTurn : <EOL> ( up , down , left , right ) = setAxes ( axis , nextAxis * - <NUM_LIT:1> , nextTurn ) <EOL> if self . debug : <EOL> print '<STR_LIT>' , up , Cube . directions [ up ] <EOL> print '<STR_LIT>' , down , Cube . directions [ down ] <EOL> print '<STR_LIT>' , left , Cube . directions [ left ] <EOL> print '<STR_LIT>' , right , Cube . directions [ right ] <EOL> for row in xrange ( <NUM_LIT:3> ) : <EOL> for col in xrange ( <NUM_LIT:3> ) : <EOL> pos = axis <EOL> pos = pos + ( down * ( row - <NUM_LIT:1> ) ) <EOL> pos = pos + ( right * ( col - <NUM_LIT:1> ) ) <EOL> ( x , y , z ) = pos . components <EOL> ( x , y , z ) = ( int ( x + <NUM_LIT:1> ) , int ( y + <NUM_LIT:1> ) , int ( z + <NUM_LIT:1> ) ) <EOL> if self . debug : <EOL> print '<STR_LIT>' , x , y , z , <EOL> print '<STR_LIT>' , pos <EOL> timesTouched [ z ] [ y ] [ x ] += <NUM_LIT:1> <EOL> cell = self . state . state [ z ] [ y ] [ x ] <EOL> if type ( cell ) == list : <EOL> cell . append ( ( faceInfo . currentFace [ row ] [ col ] , axis ) ) <EOL> if self . debug : <EOL> print '<STR_LIT>' , self . state <EOL> print '<STR_LIT>' , timesTouched <EOL> reverseZ = - <NUM_LIT:1> if self . camera . view ** Vector ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> ) < <NUM_LIT:0> else <NUM_LIT:1> <EOL> reverseY = - <NUM_LIT:1> if self . camera . view ** Vector ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> ) < <NUM_LIT:0> else <NUM_LIT:1> <EOL> reverseX = - <NUM_LIT:1> if self . camera . view ** Vector ( <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> ) < <NUM_LIT:0> else <NUM_LIT:1> <EOL> zRange = range ( <NUM_LIT:3> ) [ : : reverseZ ] <EOL> yRange = range ( <NUM_LIT:3> ) [ : : reverseY ] <EOL> xRange = range ( <NUM_LIT:3> ) [ : : reverseX ] <EOL> for z in zRange : <EOL> for y in yRange : <EOL> for x in xRange : <EOL> cell = self . state . state [ z ] [ y ] [ x ] <EOL> if type ( cell ) == list : <EOL> pieceId = - <NUM_LIT:1> <EOL> colors = set ( ) <EOL> for i in cell : <EOL> colors . add ( i [ <NUM_LIT:0> ] ) <EOL> for key in Cube . faceColors : <EOL> if set ( Cube . faceColors [ key ] ) == colors : <EOL> pieceId = key <EOL> break <EOL> if pieceId >= <NUM_LIT:0> : <EOL> desiredColorOrder = Cube . faceColors [ pieceId ] <EOL> currentOrder = [ ] <EOL> ori = <NUM_LIT:0> <EOL> notAdded = set ( [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> ] ) <EOL> cell . sort ( lambda a , b : cmp ( desiredColorOrder . index ( a [ <NUM_LIT:0> ] ) , <EOL> desiredColorOrder . index ( b [ <NUM_LIT:0> ] ) ) ) <EOL> for i in cell : <EOL> ori *= <NUM_LIT:10> <EOL> if i [ <NUM_LIT:1> ] // Vector ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> ) : <EOL> ori += <NUM_LIT:2> <EOL> notAdded . discard ( <NUM_LIT:2> ) <EOL> elif i [ <NUM_LIT:1> ] // Vector ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> ) : <EOL> ori += <NUM_LIT:1> <EOL> notAdded . discard ( <NUM_LIT:1> ) <EOL> elif i [ <NUM_LIT:1> ] // Vector ( <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> ) : <EOL> ori += <NUM_LIT:0> <EOL> notAdded . discard ( <NUM_LIT:0> ) <EOL> while len ( notAdded ) > <NUM_LIT:0> : <EOL> ori *= <NUM_LIT:10> <EOL> ori += notAdded . pop ( ) <EOL> orientationKey = ori <EOL> else : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> if pieceId in ( <NUM_LIT:5> , <NUM_LIT:11> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:15> , <NUM_LIT> , <NUM_LIT> ) : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> desired = Cube . faceColors [ CubeState . solvedState [ z ] [ y ] [ x ] [ <NUM_LIT:0> ] ] <EOL> if self . debug : <EOL> print '<STR_LIT>' % ( colors , desired ) <EOL> print '<STR_LIT>' % ( z , y , x , pieceId , orientationKey ) <EOL> self . state . state [ z ] [ y ] [ x ] = ( pieceId , orientationKey ) <EOL> except : <EOL> self . updateMessage ( '<STR_LIT>' ) <EOL> self . state . setSolved ( ) <EOL> self . redraw ( ) <EOL> if self . debug : <EOL> print '<STR_LIT>' , self . state <EOL> self . redraw ( ) <EOL> def addMoves ( self , moves , status = - <NUM_LIT:1> ) : <EOL> self . moveList [ self . moveIndex + <NUM_LIT:1> : ] = [ ] <EOL> self . moveList . extend ( moves ) <EOL> if status != - <NUM_LIT:1> : <EOL> self . status = status <EOL> def rotate ( self , axis ) : <EOL> self . showingPB = False <EOL> self . addMoves ( [ axis ] , self . PLAYING ) <EOL> def makeMove ( self , move , render = True , animate = True ) : <EOL> if type ( move ) == tuple : <EOL> self . updateMessage ( move [ <NUM_LIT:1> ] ) <EOL> axis = move [ <NUM_LIT:0> ] <EOL> else : <EOL> axis = move <EOL> self . rotationItem = self . state . rotationInfo ( axis ) <EOL> if animate : <EOL> self . rotating = True <EOL> self . rotationAxis = self . rotationItem . rotationAxis <EOL> self . rotatingValues = self . rotationItem . rotatingValues <EOL> self . rotationDirection = self . rotationItem . rotationDirection <EOL> self . rotationCount = self . maxRot <EOL> else : <EOL> self . rotating = False <EOL> self . state . rotate ( self . rotationItem ) <EOL> while ( self . moveIndex + <NUM_LIT:1> ) % <NUM_LIT:20> != <NUM_LIT:0> : <EOL> if self . moveIndex == len ( self . moveList ) - <NUM_LIT:1> : <EOL> self . updateMessage ( '<STR_LIT>' ) <EOL> break <EOL> self . moveIndex += <NUM_LIT:1> <EOL> move = self . moveList [ self . moveIndex ] <EOL> if type ( move ) == tuple : <EOL> self . updateMessage ( move [ <NUM_LIT:1> ] ) <EOL> axis = move [ <NUM_LIT:0> ] <EOL> else : <EOL> axis = move <EOL> self . rotationItem = self . state . rotationInfo ( axis ) <EOL> self . state . rotate ( self . rotationItem ) <EOL> return render <EOL> def pause ( self , e ) : <EOL> self . status = self . PAUSED <EOL> def play ( self , e ) : <EOL> self . status = self . PLAYING <EOL> def step ( self , e ) : <EOL> self . timeUntilNextRotation <EOL> self . status = self . STEP <EOL> def back ( self , e ) : <EOL> self . timeUntilNextRotation = <NUM_LIT:0> <EOL> self . status = self . BACK <EOL> def reverse ( self , e ) : <EOL> self . status = self . REVERSING <EOL> def fromCamera ( self , e ) : <EOL> if not self . app . inCam : <EOL> self . app . fromCamera ( ) <EOL> def reset ( self , e ) : <EOL> self . moveList = [ ] <EOL> self . moveIndex = <NUM_LIT:0> <EOL> self . shuffling = False <EOL> self . showingPB = False <EOL> self . state . setSolved ( ) <EOL> self . redraw ( ) <EOL> def solve ( self , * args ) : <EOL> try : <EOL> solution = self . getSolution ( ) <EOL> except Exception as e : <EOL> import traceback , sys <EOL> txt = '<STR_LIT>' <EOL> print '<STR_LIT>' , e <EOL> traceback . print_exc ( file = sys . stdout ) <EOL> self . updateMessage ( txt ) <EOL> self . redraw ( ) <EOL> else : <EOL> if not self . showingPB : <EOL> self . addMoves ( solution , self . PLAYING ) <EOL> self . showingPB = True <EOL> self . pbMin = len ( self . moveList ) - len ( solution ) <EOL> self . pbMax = len ( self . moveList ) <EOL> self . updateSol ( '<STR_LIT>' + brief ( solution ) ) <EOL> self . maxRot = <NUM_LIT:5> <EOL> self . timeBetweenRotations = <NUM_LIT:0> <EOL> self . timeUntilNextRotation = <NUM_LIT:0> <EOL> def guideThrough ( self , * args ) : <EOL> if not self . showingPB : <EOL> self . solve ( ) <EOL> self . maxRot = <NUM_LIT:20> <EOL> self . timeBetweenRotations = <NUM_LIT> <EOL> self . timeUntilNextRotation = <NUM_LIT:15> <EOL> def guideFastThrough ( self , * args ) : <EOL> if not self . showingPB : <EOL> self . solve ( ) <EOL> self . maxRot = <NUM_LIT> <EOL> self . timeBetweenRotations = <NUM_LIT> <EOL> self . timeUntilNextRotation = <NUM_LIT:5> <EOL> def shuffle ( self , * args ) : <EOL> self . showingPB = False <EOL> n = self . shuffleLen <EOL> delay = <NUM_LIT:5> <EOL> moves = [ "<STR_LIT>" , "<STR_LIT:L>" , "<STR_LIT:D>" , "<STR_LIT:R>" , "<STR_LIT:F>" , "<STR_LIT:B>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" <EOL> ] <EOL> moveList = [ ( random . choice ( moves ) , "<STR_LIT>" % ( i + <NUM_LIT:1> , n ) ) for i in xrange ( n ) ] <EOL> self . addMoves ( moveList , self . PLAYING ) <EOL> self . shuffling = True <EOL> self . status = self . PLAYING <EOL> def getSolution ( self , method = '<STR_LIT>' ) : <EOL> if method == '<STR_LIT>' : <EOL> solution = solutions . beginner3Layer ( self . state . copy ( ) ) <EOL> return solution <EOL> class CubeState ( object ) : <EOL> """<STR_LIT>""" <EOL> solvedState = [ [ [ ( <NUM_LIT:1> , <NUM_LIT> ) , ( <NUM_LIT:2> , <NUM_LIT> ) , ( <NUM_LIT:3> , <NUM_LIT> ) ] , <EOL> [ ( <NUM_LIT:4> , <NUM_LIT> ) , ( <NUM_LIT:5> , <NUM_LIT> ) , ( <NUM_LIT:6> , <NUM_LIT> ) ] , <EOL> [ ( <NUM_LIT:7> , <NUM_LIT> ) , ( <NUM_LIT:8> , <NUM_LIT> ) , ( <NUM_LIT:9> , <NUM_LIT> ) ] ] , <EOL> [ [ ( <NUM_LIT:10> , <NUM_LIT> ) , ( <NUM_LIT:11> , <NUM_LIT> ) , ( <NUM_LIT:12> , <NUM_LIT> ) ] , <EOL> [ ( <NUM_LIT> , <NUM_LIT> ) , ( <NUM_LIT> , <NUM_LIT> ) , ( <NUM_LIT:15> , <NUM_LIT> ) ] , <EOL> [ ( <NUM_LIT:16> , <NUM_LIT> ) , ( <NUM_LIT> , <NUM_LIT> ) , ( <NUM_LIT> , <NUM_LIT> ) ] ] , <EOL> [ [ ( <NUM_LIT> , <NUM_LIT> ) , ( <NUM_LIT:20> , <NUM_LIT> ) , ( <NUM_LIT> , <NUM_LIT> ) ] , <EOL> [ ( <NUM_LIT> , <NUM_LIT> ) , ( <NUM_LIT> , <NUM_LIT> ) , ( <NUM_LIT> , <NUM_LIT> ) ] , <EOL> [ ( <NUM_LIT> , <NUM_LIT> ) , ( <NUM_LIT> , <NUM_LIT> ) , ( <NUM_LIT> , <NUM_LIT> ) ] ] ] <EOL> barebones = [ [ [ [ ] , [ ] , [ ] ] , <EOL> [ [ ] , ( <NUM_LIT:5> , <NUM_LIT> ) , [ ] ] , <EOL> [ [ ] , [ ] , [ ] ] ] , <EOL> [ [ [ ] , ( <NUM_LIT:11> , <NUM_LIT> ) , [ ] ] , <EOL> [ ( <NUM_LIT> , <NUM_LIT> ) , ( <NUM_LIT> , <NUM_LIT> ) , ( <NUM_LIT:15> , <NUM_LIT> ) ] , <EOL> [ [ ] , ( <NUM_LIT> , <NUM_LIT> ) , [ ] ] ] , <EOL> [ [ [ ] , [ ] , [ ] ] , <EOL> [ [ ] , ( <NUM_LIT> , <NUM_LIT> ) , [ ] ] , <EOL> [ [ ] , [ ] , [ ] ] ] ] <EOL> keys = { <NUM_LIT:2> : Vector ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> ) , <EOL> <NUM_LIT:1> : Vector ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> ) , <EOL> <NUM_LIT:0> : Vector ( <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> ) } <EOL> perpendiculars = { Vector ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> ) : [ <NUM_LIT:0> , <NUM_LIT:1> ] , <EOL> Vector ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> ) : [ <NUM_LIT:0> , <NUM_LIT:2> ] , <EOL> Vector ( <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> ) : [ <NUM_LIT:1> , <NUM_LIT:2> ] } <EOL> movementCodes = solutions . MOVE_CODES <EOL> movementKeys = { <EOL> "<STR_LIT>" : Vector ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> ) , <EOL> "<STR_LIT:D>" : Vector ( <NUM_LIT:0> , <NUM_LIT:0> , - <NUM_LIT:1> ) , <EOL> "<STR_LIT:L>" : Vector ( - <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> ) , <EOL> "<STR_LIT:R>" : Vector ( <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> ) , <EOL> "<STR_LIT:F>" : Vector ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> ) , <EOL> "<STR_LIT:B>" : Vector ( <NUM_LIT:0> , - <NUM_LIT:1> , <NUM_LIT:0> ) <EOL> } <EOL> def __init__ ( self , state = '<STR_LIT>' ) : <EOL> self . state = state <EOL> self . size = <NUM_LIT:3> <EOL> if self . state == '<STR_LIT>' : <EOL> self . setSolved ( ) <EOL> elif self . state == '<STR_LIT>' : <EOL> self . setBare ( ) <EOL> def __str__ ( self ) : <EOL> s = '<STR_LIT>' <EOL> for z in xrange ( self . size ) : <EOL> for y in xrange ( self . size ) : <EOL> for x in xrange ( self . size ) : <EOL> item = str ( self . state [ z ] [ y ] [ x ] ) <EOL> s += item <EOL> s += '<STR_LIT:\n>' <EOL> s += '<STR_LIT:\n>' <EOL> return s <EOL> def condense ( self ) : <EOL> s = '<STR_LIT>' <EOL> for z in xrange ( self . size ) : <EOL> for y in xrange ( self . size ) : <EOL> for x in xrange ( self . size ) : <EOL> item = self . state [ z ] [ y ] [ x ] <EOL> item2 = str ( item [ <NUM_LIT:0> ] ) + "<STR_LIT:'>" + str ( item [ <NUM_LIT:1> ] ) <EOL> s += item2 <EOL> s += '<STR_LIT:U+002C>' <EOL> s += '<STR_LIT:U+002C>' <EOL> s += '<STR_LIT:U+002C>' <EOL> return s <EOL> @ classmethod <EOL> def getPerps ( cls , p ) : <EOL> for key in cls . perpendiculars : <EOL> if key // p : return cls . perpendiculars [ key ] <EOL> @ staticmethod <EOL> def kthDigit ( num , k ) : <EOL> num /= ( <NUM_LIT:10> ** k ) <EOL> return num % <NUM_LIT:10> <EOL> @ staticmethod <EOL> def swapDigits ( num , i , j ) : <EOL> ithDigit = CubeState . kthDigit ( num , i ) <EOL> num -= ithDigit * int ( <NUM_LIT:10> ** i ) <EOL> jthDigit = CubeState . kthDigit ( num , j ) <EOL> num -= jthDigit * int ( <NUM_LIT:10> ** j ) <EOL> num += ithDigit * int ( <NUM_LIT:10> ** j ) <EOL> num += jthDigit * int ( <NUM_LIT:10> ** i ) <EOL> return num <EOL> def rotationInfo ( self , axis ) : <EOL> isNeg = False <EOL> if type ( axis ) == str and "<STR_LIT:'>" in axis : <EOL> isNeg = True <EOL> axis = axis [ <NUM_LIT:0> ] <EOL> if type ( axis ) == str : <EOL> axis = CubeState . movementKeys [ axis ] <EOL> rotationIndcs = [ ] <EOL> for x in xrange ( self . size ) : <EOL> for y in xrange ( self . size ) : <EOL> for z in xrange ( self . size ) : <EOL> pos = Vector ( x - <NUM_LIT:1> , y - <NUM_LIT:1> , z - <NUM_LIT:1> ) <EOL> if pos ** axis > <NUM_LIT:0> and pos == axis : <EOL> rotationIndcs . append ( ( x , y , z ) ) <EOL> oldValues = { } <EOL> for i in rotationIndcs : <EOL> oldValues [ i ] = self . state [ i [ <NUM_LIT:2> ] ] [ i [ <NUM_LIT:1> ] ] [ i [ <NUM_LIT:0> ] ] <EOL> rot = Struct ( ) <EOL> rot . rotationAxis = axis <EOL> rot . rotatingValues = [ val [ <NUM_LIT:0> ] for val in oldValues . values ( ) ] <EOL> rot . rotationDirection = isNeg <EOL> rot . oldValues = oldValues <EOL> rot . rotationIndcs = rotationIndcs <EOL> return rot <EOL> def rotate ( self , r ) : <EOL> axis = r . rotationAxis <EOL> isNeg = r . rotationDirection <EOL> rotationIndcs = r . rotationIndcs <EOL> oldValues = r . oldValues <EOL> for idx in rotationIndcs : <EOL> pos = Vector ( idx [ <NUM_LIT:0> ] - <NUM_LIT:1> , idx [ <NUM_LIT:1> ] - <NUM_LIT:1> , idx [ <NUM_LIT:2> ] - <NUM_LIT:1> ) <EOL> posn = pos - ( pos > axis ) <EOL> newn = axis * posn <EOL> if isNeg : <EOL> newn = newn * - <NUM_LIT:1.> <EOL> new = newn + ( pos > axis ) <EOL> ( oldId , oldKey ) = oldValues [ idx ] <EOL> perps = CubeState . getPerps ( axis ) <EOL> toSwap = [ ] <EOL> for perp in perps : <EOL> for i in xrange ( self . size ) : <EOL> if CubeState . kthDigit ( oldKey , i ) == perp : <EOL> toSwap . append ( i ) <EOL> newKey = CubeState . swapDigits ( oldKey , * toSwap ) <EOL> newValue = ( oldId , newKey ) <EOL> newi = ( int ( new . x + <NUM_LIT:1> ) , int ( new . y + <NUM_LIT:1> ) , int ( new . z + <NUM_LIT:1> ) ) <EOL> self . state [ newi [ <NUM_LIT:2> ] ] [ newi [ <NUM_LIT:1> ] ] [ newi [ <NUM_LIT:0> ] ] = newValue <EOL> def copy ( self ) : <EOL> return CubeState ( copy . deepcopy ( self . state ) ) <EOL> def setBare ( self ) : <EOL> self . state = copy . deepcopy ( CubeState . barebones ) <EOL> def setSolved ( self ) : <EOL> self . state = copy . deepcopy ( CubeState . solvedState ) </s>
