Ejemplo n.º 1
0
 public Tile GetTile(SidesOfCube side)
 {
     for (int i = 0; i < numTiles; i++)
     {
         if (tiles[i].sideOfCube == side)
         {
             return(tiles[i]);
         }
     }
     return(tiles[0]);
 }
Ejemplo n.º 2
0
 Tile GetTile(Cubie cubie, SidesOfCube side)
 {
     foreach (Tile tile in cubie.tiles)
     {
         if (tile.sideOfCube == side)
         {
             return(tile);
         }
     }
     return(cubie.tiles[0]);
 }
Ejemplo n.º 3
0
 public int GetTileIndex(SidesOfCube side)
 {
     for (int i = 0; i < numTiles; i++)
     {
         if (tiles[i].sideOfCube == side)
         {
             return(i);
         }
     }
     return(0);
 }
Ejemplo n.º 4
0
 //Move methods
 IEnumerator Move(SidesOfCube side, bool prime)
 {
     cube.RotateSide(side, prime);
     while (cubeDisp.rotating)
     {
         yield return(null);
     }
     if (pauseAfterMove)
     {
         Debug.Break();
     }
 }
Ejemplo n.º 5
0
    IEnumerator RotateSideCo(SidesOfCube side, bool prime)
    {
        rotating = true;
        //find the cubies that are on the side being rotated
        List <GameObject> cubiesToRotate = new List <GameObject>();

        for (int i = 0; i < 6; i++)
        {
            if (centers[i].transform.position == GetDirFromSide(side))
            {
                cubiesToRotate.Add(centers[i]);
                break;
            }
        }
        for (int i = 0; i < 12; i++)
        {
            foreach (Tile tile in edgePointers[i].tiles)
            {
                if (tile.sideOfCube == side)
                {
                    cubiesToRotate.Add(edges[i]);
                    break;
                }
            }
        }
        for (int i = 0; i < 8; i++)
        {
            foreach (Tile tile in cornerPointers[i].tiles)
            {
                if (tile.sideOfCube == side)
                {
                    cubiesToRotate.Add(corners[i]);
                    break;
                }
            }
        }

        //rotate them all around the axis in the correct direction
        Vector3 axis          = GetDirFromSide(side);
        float   rotationTotal = 0;

        while (rotationTotal < 90)
        {
            RotateWorldCubies(cubiesToRotate, ref rotationTotal, axis, prime);
            yield return(null);
        }

        //once the rotation is finished, round their positions and rotations to the nearest integer,
        //just in case they're slightly off
        RoundWorldCubiePositions(cubiesToRotate);
        rotating = false;
    }
Ejemplo n.º 6
0
    public void RotateSide(SidesOfCube side, bool prime)
    {
        //print("Rotating");
        int[] edgeIndexes, cornerIndexes;
        //set the index arrays to correspond to the side that's being rotated
        switch (side)
        {
        case SidesOfCube.up:
            edgeIndexes   = edgeIndexesUp;
            cornerIndexes = cornerIndexesUp;
            break;

        case SidesOfCube.down:
            edgeIndexes   = edgeIndexesDown;
            cornerIndexes = cornerIndexesDown;
            break;

        case SidesOfCube.right:
            edgeIndexes   = edgeIndexesRight;
            cornerIndexes = cornerIndexesRight;
            break;

        case SidesOfCube.left:
            edgeIndexes   = edgeIndexesLeft;
            cornerIndexes = cornerIndexesLeft;
            break;

        case SidesOfCube.front:
            edgeIndexes   = edgeIndexesFront;
            cornerIndexes = cornerIndexesFront;
            break;

        default:     // back side
            edgeIndexes   = edgeIndexesBack;
            cornerIndexes = cornerIndexesBack;
            break;
        }
        //move the pieces
        CyclePieces(null, edgeIndexes, cornerIndexes, prime);
        //rotate pieces
        for (int i = 0; i < 4; i++)
        {
            edgePieces[edgeIndexes[i]].RotateTiles(side, prime);
            cornerPieces[cornerIndexes[i]].RotateTiles(side, prime);
        }

        if (rotationMade != null)
        {
            rotationMade(side, prime);
        }
    }
Ejemplo n.º 7
0
    IEnumerator Align(SidesOfCube current, SidesOfCube target, string move)
    {
        char upperCaseMove = move.ToUpper()[0];

        if (upperCaseMove == 'R' || upperCaseMove == 'L' || upperCaseMove == 'X')
        {
            yield return(StartCoroutine(Align_XAxis(current, target, move)));
        }
        else if (upperCaseMove == 'U' || upperCaseMove == 'D' || upperCaseMove == 'Y')
        {
            yield return(StartCoroutine(Align_YAxis(current, target, move)));
        }
        else if (upperCaseMove == 'F' || upperCaseMove == 'B' || upperCaseMove == 'Z')
        {
            yield return(StartCoroutine(Align_ZAxis(current, target, move)));
        }
    }
Ejemplo n.º 8
0
 public void RotateTiles(SidesOfCube axis, bool prime)
 {
     if (axis == SidesOfCube.up)
     {
         foreach (Tile tile in tiles)
         {
             RotateCubieUD(tile, prime);
         }
     }
     if (axis == SidesOfCube.down)
     {
         foreach (Tile tile in tiles)
         {
             RotateCubieUD(tile, !prime);
         }
     }
     else if (axis == SidesOfCube.right)
     {
         foreach (Tile tile in tiles)
         {
             RotateCubieRL(tile, prime);
         }
     }
     else if (axis == SidesOfCube.left)
     {
         foreach (Tile tile in tiles)
         {
             RotateCubieRL(tile, !prime);
         }
     }
     else if (axis == SidesOfCube.front)
     {
         foreach (Tile tile in tiles)
         {
             RotateCubieFB(tile, prime);
         }
     }
     else if (axis == SidesOfCube.back)
     {
         foreach (Tile tile in tiles)
         {
             RotateCubieFB(tile, !prime);
         }
     }
 }
Ejemplo n.º 9
0
    string ConvertMove(SidesOfCube side)
    {
        switch (side)
        {
        case SidesOfCube.right:
            return("R");

        case SidesOfCube.left:
            return("L");

        case SidesOfCube.up:
            return("U");

        case SidesOfCube.down:
            return("D");

        case SidesOfCube.front:
            return("F");

        default:
            return("B");
        }
    }
Ejemplo n.º 10
0
    //Align methods
    IEnumerator DoAlignment(SidesOfCube current, SidesOfCube target, string move, Func <SidesOfCube, SidesOfCube, int> func)
    {
        //if the value is negative, that means the moves should be prime
        int numMoves = func(current, target);

        if (Mathf.Abs(numMoves) == 1 && (move.ToUpper() == "L" || move.ToUpper() == "D" || move.ToUpper() == "B"))
        {
            numMoves *= -1;//since L D and B rotate in the opposite direction as x y and z, the moves need to be reversed
        }
        if (numMoves < 0)
        {
            yield return(StartCoroutine(Move(move, true)));
        }
        else
        {
            while (numMoves > 0)
            {
                yield return(StartCoroutine(Move(move, false)));

                numMoves--;
            }
        }
    }
Ejemplo n.º 11
0
    Vector3 GetDirFromSide(SidesOfCube side)
    {
        switch (side)
        {
        case SidesOfCube.up:
            return(Vector3.up);

        case SidesOfCube.down:
            return(Vector3.down);

        case SidesOfCube.right:
            return(Vector3.left);

        case SidesOfCube.left:
            return(Vector3.right);

        case SidesOfCube.front:
            return(Vector3.forward);

        default:
            return(Vector3.back);
        }
    }
Ejemplo n.º 12
0
 void RotateSide(SidesOfCube side, bool prime)
 {
     StartCoroutine(RotateSideCo(side, prime));
 }
Ejemplo n.º 13
0
    int getFastestAlignMoves_ZAxis(SidesOfCube current, SidesOfCube target)
    {
        if (current == target)
        {
            return(0);
        }

        int cur, tar;

        if (current == SidesOfCube.up)
        {
            cur = 0;
        }
        else if (current == SidesOfCube.right)
        {
            cur = 1;
        }
        else if (current == SidesOfCube.down)
        {
            cur = 2;
        }
        else
        {
            cur = 3;
        }
        if (target == SidesOfCube.up)
        {
            tar = 0;
        }
        else if (target == SidesOfCube.right)
        {
            tar = 1;
        }
        else if (target == SidesOfCube.down)
        {
            tar = 2;
        }
        else
        {
            tar = 3;
        }

        if (cur % 2 == tar % 2)
        {
            return(2);
        }

        if (tar == 0 && cur == 3)
        {
            return(1);
        }
        if (tar == 3 && cur == 0)
        {
            return(-1);
        }
        if (tar < cur)
        {
            return(-1);
        }
        return(1);
    }
Ejemplo n.º 14
0
 IEnumerator Align_ZAxis(SidesOfCube current, SidesOfCube target, string move)
 {
     yield return(StartCoroutine(DoAlignment(current, target, move, getFastestAlignMoves_ZAxis)));
 }
Ejemplo n.º 15
0
    int getFastestAlignMoves_YAxis(SidesOfCube current, SidesOfCube target)
    {
        if (current == target)
        {
            return(0);
        }

        int cur, tar;

        if (current == SidesOfCube.front)
        {
            cur = 0;
        }
        else if (current == SidesOfCube.left)
        {
            cur = 1;
        }
        else if (current == SidesOfCube.back)
        {
            cur = 2;
        }
        else
        {
            cur = 3;
        }
        if (target == SidesOfCube.front)
        {
            tar = 0;
        }
        else if (target == SidesOfCube.left)
        {
            tar = 1;
        }
        else if (target == SidesOfCube.back)
        {
            tar = 2;
        }
        else
        {
            tar = 3;
        }


        if (cur % 2 == tar % 2)
        {
            return(2);
        }

        if (tar == 0 && cur == 3)
        {
            return(1);
        }
        if (tar == 3 && cur == 0)
        {
            return(-1);
        }
        if (tar < cur)
        {
            return(-1);
        }
        return(1);
    }
Ejemplo n.º 16
0
    //todo: implement Cubie.GetTile() and Cubie.GetTileIndex() everywhere it belongs.
    IEnumerator Cross()
    {
        solving = true;
        //start with white side

        //move white center to the down side
        Tile tile = cube.whiteSide.center.tiles[0];

        if (tile.sideOfCube == SidesOfCube.front)
        {
            while (tile.sideOfCube != SidesOfCube.down)
            {
                yield return(StartCoroutine(Move(MidLayersOfCube.Middle, true)));
            }
        }
        else if (tile.sideOfCube == SidesOfCube.back)
        {
            while (tile.sideOfCube != SidesOfCube.down)
            {
                yield return(StartCoroutine(Move(MidLayersOfCube.Middle, false)));
            }
        }
        else if (tile.sideOfCube == SidesOfCube.right)
        {
            while (tile.sideOfCube != SidesOfCube.down)
            {
                yield return(StartCoroutine(Move(MidLayersOfCube.Standing, false)));
            }
        }
        else
        {
            while (tile.sideOfCube != SidesOfCube.down)
            {
                yield return(StartCoroutine(Move(MidLayersOfCube.Standing, true)));
            }
        }

        //find white edges
        Tile[] whiteTiles = new Tile[4];
        Tile[] otherTiles = new Tile[4];
        for (int i = 0; i < 4; i++)
        {
            if (cube.whiteSide.edges[i].tiles[0].color == Colors.white)
            {
                whiteTiles[i] = cube.whiteSide.edges[i].tiles[0];
                otherTiles[i] = cube.whiteSide.edges[i].tiles[1];
            }
            else
            {
                whiteTiles[i] = cube.whiteSide.edges[i].tiles[1];
                otherTiles[i] = cube.whiteSide.edges[i].tiles[0];
            }
        }

        //line up the other side of each edge piece with its color's center piece
        for (int i = 0; i < 4; i++)
        {
            //check if the cubie is already in its proper place...
            SidesOfCube centerSide   = cube.GetCenterFromColor(otherTiles[i].color).tiles[0].sideOfCube;
            bool        cubieInPlace = (otherTiles[i].sideOfCube == centerSide);
            if (cubieInPlace)
            {
                yield return(StartCoroutine(Align(whiteTiles[i].sideOfCube, SidesOfCube.down, ConvertMove(otherTiles[i].sideOfCube))));

                continue;
            }

            //move the edge piece to the top layer and orient it properly
            if (otherTiles[i].sideOfCube == SidesOfCube.up)
            {
                //put the cubie and its corresponding non-white side in front
                yield return(StartCoroutine(Align(whiteTiles[i].sideOfCube, SidesOfCube.front, "U")));

                yield return(StartCoroutine(Align(centerSide, SidesOfCube.front, "d")));

                //flip the cubie
                yield return(StartCoroutine(Algorithm("F D R' D'")));
            }
            else if (otherTiles[i].sideOfCube == SidesOfCube.down)
            {
                //put the corresponding center in front
                yield return(StartCoroutine(Align(centerSide, SidesOfCube.front, "u")));

                SidesOfCube originalFirstSide = cube.GetCenterFromColor(otherTiles[0].color).tiles[0].sideOfCube;

                if (whiteTiles[i].sideOfCube == SidesOfCube.left)
                {
                    //move current edge out of down side
                    yield return(StartCoroutine(Move(SidesOfCube.left, true)));
                }
                else
                {
                    //align down side for current edge
                    yield return(StartCoroutine(Align(whiteTiles[i].sideOfCube, SidesOfCube.right, "D")));

                    //move current edge out of down side
                    yield return(StartCoroutine(Move(SidesOfCube.right, false)));
                }

                if (i > 0)//realign the down side as it was before if there were any other edges already solved
                {
                    yield return(StartCoroutine(Align(otherTiles[0].sideOfCube, originalFirstSide, "D")));
                }

                //move current edge into place
                yield return(StartCoroutine(Align(whiteTiles[i].sideOfCube, SidesOfCube.down, "F")));
            }
            else
            {
                SidesOfCube originalWhiteTileSide = whiteTiles[i].sideOfCube;
                string      move = ConvertMove(otherTiles[i].sideOfCube);

                //rotate otherTiles[i].side until white is up
                yield return(StartCoroutine(Align(originalWhiteTileSide, SidesOfCube.up, move)));

                //move top layer out of the way (align with its proper center)
                yield return(StartCoroutine(Align(otherTiles[i].sideOfCube, centerSide, "U")));

                //undo front side movement, in case another white edge piece was already aligned there
                yield return(StartCoroutine(Align(SidesOfCube.up, originalWhiteTileSide, move)));

                //move edge into place
                yield return(StartCoroutine(Align(whiteTiles[i].sideOfCube, SidesOfCube.down, ConvertMove(centerSide))));
            }
        }
        currentStep = StartCoroutine(FirstTwoLayers());
    }
Ejemplo n.º 17
0
 public Tile(Colors col, SidesOfCube side)
 {
     color      = col;
     sideOfCube = side;
 }