def getString(self): if self.c_isEdge: return Face_handler.getCharValue( self.c_face0) + ", " + Face_handler.getCharValue(self.c_face1) else: return Face_handler.getCharValue( self.c_face0) + ", " + Face_handler.getCharValue( self.c_face1) + ", " + Face_handler.getCharValue( self.c_face2)
def rotate(self, p_rotation): l_face = p_rotation.getFace() l_direction = p_rotation.getDirection() if l_face == "TOP": if l_direction == "CW": self.c_currentFront = self.getFace("RIGHT") else: self.c_currentFront = self.getFace("LEFT") else: if l_face == "RIGHT": if l_direction == "CW": l_temp = self.c_currentFront self.c_currentFront = self.getFace("BOTTOM") self.c_currentUp = l_temp else: l_temp = self.getFace("BACK") self.c_currentFront = self.c_currentUp self.c_currentUp = l_temp else: if l_face == "FRONT": if l_direction == "CW": self.c_currentUp = self.getFace("LEFT") else: self.c_currentUp = self.getFace("RIGHT") else: self.rotate( Rotation(Face_handler.getOpposite(l_face), Direction_handler.getOpposite(l_direction)))
def is_redundant(self, p_rotation): l_returnValue = False if len(self.c_array) > 0: l_lastFace = self.c_array[(len(self.c_array) - 1)].getFace() l_lastDirection = self.c_array[len(self.c_array) - 1].getDirection() # rotation is opposite to previous if self.c_array[len(self.c_array) - 1].getReverse().equals(p_rotation): l_returnValue = True # previouswas opposite and previousgreater then current face if (p_rotation.getFace() == Face_handler.getOpposite(l_lastFace) and (l_lastFace > p_rotation.getFace())): l_returnValue = True # two clockwise rotation of same face if ((p_rotation.getFace() == l_lastFace) and (l_lastDirection == "CW") and p_rotation.getDirection() == "CW"): l_returnValue = True #no three counter clockwise rotations if len(self.c_array) > 1: if ((p_rotation.getFace() == l_lastFace) and (l_lastDirection == "CCW") and (p_rotation.getDirection() == "CCW") and (self.c_array[len(self.c_array) - 2].getFace() == l_lastFace) and (l_lastDirection == "CCW") and (self.c_array[len(self.c_array) - 2].getDirection() == "CCW")): l_returnValue = True else: l_returnValue = False return l_returnValue
def getFace(self, p_viewpoint): if p_viewpoint == "TOP": return self.c_currentUp else: if p_viewpoint == "BOTTOM": return Face_handler.getOpposite(self.c_currentUp) else: return self.getHorizonalFacebyVirtual(p_viewpoint)
def getHorizonalFacebyVirtual(self, p_viewpoint): i = 0 while (self.g_face_Order[Face_handler.getIntFaceValue( self.c_currentUp)][i] != self.c_currentFront and i < 4): i += 1 if p_viewpoint == "FRONT": return self.g_face_Order[Face_handler.getIntFaceValue( self.c_currentUp)][i] else: if p_viewpoint == "LEFT": return self.g_face_Order[Face_handler.getIntFaceValue( self.c_currentUp)][(i + 1) % 4] else: if p_viewpoint == "BACK": return self.g_face_Order[Face_handler.getIntFaceValue( self.c_currentUp)][(i + 2) % 4] else: return self.g_face_Order[Face_handler.getIntFaceValue( self.c_currentUp)][(i + 3) % 4]
def printFace(self, face): print("\n" + Face_handler.getCharValue(face) + "\n\n") print( self.get_color(face, "LIF_TOPLEFT") + " " + self.get_color(face, "LIF_TOP") + " " + self.get_color(face, "LIF_TOPRIGHT") + "\n") print( self.get_color(face, "LIF_LEFT") + " " + self.get_color(face, "LIF_RIGHT") + "\n") print( self.get_color(face, "LIF_BOTTOMLEFT") + " " + self.get_color(face, "LIF_BOTTOM") + " " + self.get_color(face, "LIF_BOTTOMRIGHT") + "\n")
def read_from_file(self, p_reader): l_int = 0 l_int = p_reader.read() #Console.Write("%d ",l_int) while (l_int == ' ') or (l_int == 13): l_int = p_reader.read() # Console.Write("%d ",l_int) if ((l_int == 10) or (l_int == -1) or (l_int != '(')): return False else: self.c_face = Face_handler.getFaceInt(int(p_reader.read())) p_reader.read() self.c_direction = Direction_handler.getDirectionInt( int(p_reader.read())) p_reader.read() return True
def test_FaceGetOpposite(self): myFace = "BOTTOM" self.assertEqual("TOP", Face_handler.getOpposite(myFace)) myFace = "FRONT" self.assertEqual("BACK", Face_handler.getOpposite(myFace)) myFace = "RIGHT" self.assertEqual("LEFT", Face_handler.getOpposite(myFace)) myFace = "TOP" self.assertEqual("BOTTOM", Face_handler.getOpposite(myFace)) myFace = "BACK" self.assertEqual("FRONT", Face_handler.getOpposite(myFace)) myFace = "LEFT" self.assertEqual("RIGHT", Face_handler.getOpposite(myFace))
def test_FaceGetIntGetChar(self): myFace = "BOTTOM" self.assertEqual('D', Face_handler.getCharValue(myFace)) myFace = "FRONT" self.assertEqual('F', Face_handler.getCharValue(myFace)) myFace = "RIGHT" self.assertEqual('R', Face_handler.getCharValue(myFace)) myFace = "TOP" self.assertEqual('U', Face_handler.getCharValue(myFace)) myFace = "BACK" self.assertEqual('B', Face_handler.getCharValue(myFace)) myFace = "LEFT" self.assertEqual('L', Face_handler.getCharValue(myFace))
def get_color(self, face, locationInFace): return self.colors[Face_handler.getIntFaceValue(face)][ Location_in_face_handler.GetLocationInFaceInt(locationInFace)]
def set_color(self, face, locationInFace, color): self.colors[Face_handler.getIntFaceValue(face)][ Location_in_face_handler.GetLocationInFaceInt( locationInFace)] = color
def getString(self): return Face_handler.getCharValue( self.c_currentUp) + ", " + Face_handler.getCharValue( self.c_currentFront)
def print(self): print("(" + Face_handler.getCharValue(self.c_face) + "," + Direction_handler.getString(self.c_direction) + ")", end=" ")