public bool SendVisualizationMovement(RotateCubeMovement movement)
        {
            if (inVisualization)
            {
                byte[] buffer = new byte[1];
                buffer[0] = ArduinoProtocol.CreateMovement(movement);

                try
                {
                    serialPort.ReadExisting();
                    serialPort.Write(buffer, 0, 1);
                    serialPort.ReadByte();
                    return true;
                }
                catch (Exception e)
                {
                    System.Console.Write("Could not send 'Init Execution' command.");
                    return false;
                }
            }
            return false;
        }
        /// <summary>
        /// Adds the rotation movement.
        /// </summary>
        /// <param name="positionFace">Position of the face to be turned</param>
        /// <param name="movements">List of movements to be concatenated of the new movement</param>
        private void BringFaceToSomeClaw(CubeFaceType positionFace, CubeFaceType nextPositionFace, List<Movement> movements)
        {
            // se face não está diretamente ligada a uma das garras, leva a face para a garra
            if (!positionFace.Equals(Claw_L) && !positionFace.Equals(Claw_F))
            {
                RotateCubeMovement mov = new RotateCubeMovement();

                switch (positionFace)
                {
                    case CubeFaceType.U:
                        if (nextPositionFace.Equals(CubeFaceType.F))
                        {
                            mov.Axis = CoordinateAxis.X;
                            mov.Type = TurnType.HalfTurnLeft;
                        }
                        else
                        {
                            mov.Axis = CoordinateAxis.Y;
                            mov.Type = TurnType.HalfTurnRight;
                        }
                        break;
                    case CubeFaceType.B:
                        mov.Axis = CoordinateAxis.Y;
                        mov.Type = TurnType.FullTurn;
                        break;
                    case CubeFaceType.R:
                        mov.Axis = CoordinateAxis.X;
                        mov.Type = TurnType.FullTurn;
                        break;
                    case CubeFaceType.D:
                        if (nextPositionFace.Equals(CubeFaceType.F))
                        {
                            mov.Axis = CoordinateAxis.X;
                            mov.Type = TurnType.HalfTurnRight;
                        }
                        else
                        {
                            mov.Axis = CoordinateAxis.Y;
                            mov.Type = TurnType.HalfTurnLeft;
                        }
                        break;
                }
                // turns the representation of the cube (very important)
                Cube.TurnCube(mov);
                // adds the new movement to the list of movements
                movements.Add(mov);
            }
        }
        private static bool PositioningFace(ArduinoChannel channel, int numberFace)
        {
            RotateCubeMovement rotMov = new RotateCubeMovement();

            switch (numberFace)
            {
                case 1:
                    // não faz nada, é a primeira face
                    break;
                case 2:
                    rotMov.Axis = CoordinateAxis.Y;
                    rotMov.Type = TurnType.HalfTurnRight;
                    channel.SendVisualizationMovement(rotMov);
                    break;
                case 3:
                    rotMov.Axis = CoordinateAxis.Y;
                    rotMov.Type = TurnType.HalfTurnRight;
                    channel.SendVisualizationMovement(rotMov);
                    break;
                case 4:
                    rotMov.Axis = CoordinateAxis.Y;
                    rotMov.Type = TurnType.HalfTurnRight;
                    channel.SendVisualizationMovement(rotMov);
                    break;
                case 5:
                    rotMov.Axis = CoordinateAxis.X;
                    rotMov.Type = TurnType.HalfTurnRight;
                    channel.SendVisualizationMovement(rotMov);

                    rotMov = new RotateCubeMovement();
                    rotMov.Axis = CoordinateAxis.Y;
                    rotMov.Type = TurnType.HalfTurnRight;
                    channel.SendVisualizationMovement(rotMov);
                    break;
                case 6:
                    rotMov.Axis = CoordinateAxis.Y;
                    rotMov.Type = TurnType.FullTurn;
                    channel.SendVisualizationMovement(rotMov);
                    break;
                default:
                    return false;
            }
            return true;
        }
Esempio n. 4
0
 public void TurnCube(RotateCubeMovement movement)
 {
     if (CubeMap.Count == 6)
     {
         if (movement.Axis.Equals(CoordinateAxis.X))
         {
             RotateCubeByXAxis(movement.Type);
         }
         else if (movement.Axis.Equals(CoordinateAxis.Y))
         {
             RotateCubeByYAxis(movement.Type);
         }
         else if (movement.Axis.Equals(CoordinateAxis.Z))
         {
             RotateCubeByZAxis(movement.Type);
         }
     }
 }