Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python2
- # -*- coding: utf-8 -*-
- import pprint as pp
- # todo rewert to int, or hastag
- W = "W"
- B = "B"
- R = "R"
- O = "O"
- Y = "Y"
- G = "G"
- Top = "Top"
- Bottom = "Bottom"
- Right = "Right"
- Left = "Left"
- Front = "Front"
- Back = "Back"
- #using it for turning cube sides
- # clockwise
- CW = "0"
- # counterclockwise
- CCW = "1"
- class Cube(object):
- """This class provide basic functionality
- of how the cube works"""
- # provides basics of cube
- polarity_color = (W, Y),(B, G),(O, R)
- polarity_sides = (Top,Bottom),(Left,Right),(Front, Back)
- # connections of cube sides
- connection_side = dict()
- connection_side[W] = [R,G,O,B]
- connection_side[B] = [W,R,Y,O]
- connection_side[R] = [W,G,Y,B]
- connection_side[O] = [W,B,Y,G]
- connection_side[Y] = [R,G,O,B]
- connection_side[G] = [W,O,Y,R]
- def __init__(self):
- # creating default marking
- self.state = self._defaultMarking()
- self._check()
- self.turn(Top, CW)
- """Default marking provide polarity of solved cube"""
- def _defaultMarking(self):
- state = dict()
- state[Front] = [[R,R,R],
- [R,R,R],
- [R,R,R]]
- state[Back] = [[O,O,O],
- [O,O,O],
- [O,O,O]]
- state[Top] = [[W,W,W],
- [W,W,W],
- [W,W,W]]
- state[Bottom] = [[Y,Y,Y],
- [Y,Y,Y],
- [Y,Y,Y]]
- state[Left] = [[G,G,G],
- [G,G,G],
- [G,G,G]]
- state[Right] = [[B,B,B],
- [B,B,B],
- [B,B,B]]
- return state
- """Checking state of cube functionality"""
- def _check(self):
- self._checkCenterPolarity()
- """Checking only valid of center"""
- def _checkCenterPolarity(self):
- # default we asume that cube are wrong
- flag = 0
- for sides in self.polarity_sides:
- for colors in self.polarity_color:
- if (self.state[sides[0]][1][1] == colors[0] and self.state[sides[1]][1][1] == colors[1] or
- self.state[sides[1]][1][1] == colors[0] and self.state[sides[0]][1][1] == colors[1]):
- flag += 1
- if flag == 3:
- print "Debug:\tCube centers are valid"
- return True
- else:
- raise ValueError("3 Cube centers are not valid. Check it")
- """Next, big part of methods it's a movement alghotithms
- First of all we need to implement the basics turning of all sides.
- Lets do it! =)"""
- def turn(self, side, cw=CW):
- pass
- """Pretty Printing of Current Values"""
- def __str__(self):
- out = " "+self.state[Top][0][0]+self.state[Top][0][1]+self.state[Top][0][2]+" \n"
- out += " "+self.state[Top][1][0]+self.state[Top][1][1]+self.state[Top][1][2]+" \n"
- out += " "+self.state[Top][2][0]+self.state[Top][2][1]+self.state[Top][2][2]+" \n"
- out += (self.state[Back][0][0]+self.state[Back][0][1]+self.state[Back][0][2]+"|"+
- self.state[Left][0][0]+self.state[Left][0][1]+self.state[Left][0][2]+"|"+
- self.state[Front][0][0]+self.state[Front][0][1]+self.state[Front][0][2]+"|"+
- self.state[Right][0][0]+self.state[Right][0][1]+self.state[Right][0][2]+"\n")
- out += (self.state[Back][1][0]+self.state[Back][1][1]+self.state[Back][1][2]+"|"+
- self.state[Left][1][0]+self.state[Left][1][1]+self.state[Left][1][2]+"|"+
- self.state[Front][1][0]+self.state[Front][1][1]+self.state[Front][1][2]+"|"+
- self.state[Right][1][0]+self.state[Right][1][1]+self.state[Right][1][2]+"\n")
- out += (self.state[Back][2][0]+self.state[Back][2][1]+self.state[Back][2][2]+"|"+
- self.state[Left][2][0]+self.state[Left][2][1]+self.state[Left][2][2]+"|"+
- self.state[Front][2][0]+self.state[Front][2][1]+self.state[Front][2][2]+"|"+
- self.state[Right][2][0]+self.state[Right][2][1]+self.state[Right][2][2]+"\n")
- out += " "+self.state[Bottom][0][0]+self.state[Bottom][0][1]+self.state[Bottom][0][2]+" \n"
- out += " "+self.state[Bottom][1][0]+self.state[Bottom][1][1]+self.state[Bottom][1][2]+" \n"
- out += " "+self.state[Bottom][2][0]+self.state[Bottom][2][1]+self.state[Bottom][2][2]+" \n"
- return out
- # return pp.pformat(self.state)
- """Helping to pretty output"""
- def _helpStr(self, side=None):
- if not side == None:
- out = ""
- for i in self.state[side]:
- for j in i:
- out += j
- out += "\n"
- else:
- out = " \n" * 3
- return out
- if __name__ == "__main__":
- cubic = Cube()
- print cubic
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement