コード例 #1
0
    // if rotBeforeMov == True, we are assuming that the shape is already rotated
    void UpdateValidPos()
    {
        if (rotBeforeMov)
        {
            // Make all valid pos 0
            for (int i1 = 0; i1 < MOV_RES; i1++)
            {
                for (int i2 = 0; i2 < MOV_RES; i2++)
                {
                    for (int i3 = 0; i3 < MOV_RES; i3++)
                    {
                        validPos[0, 0, i1, i2, i3] = 0;
                    }
                }
            }

            FindValidPos(shapes[actObjNum], 0, 0);
            RemoveUnnessPos(0, 0);
        }
        else
        {
            // Make all valid pos 0
            for (int i1 = 0; i1 < packEvol.r1Value.Count; i1++)
            {
                for (int i2 = 0; i2 < packEvol.r2Value.Count; i2++)
                {
                    for (int i3 = 0; i3 < MOV_RES; i3++)
                    {
                        for (int i4 = 0; i4 < MOV_RES; i4++)
                        {
                            for (int i5 = 0; i5 < MOV_RES; i5++)
                            {
                                validPos[i1, i2, i3, i4, i5] = 0;
                            }
                        }
                    }
                }
            }

            Quaternion rotTemp;
            for (int i = 0; i < packEvol.r1Value.Count; i++)
            {
                for (int j = 0; j < packEvol.r2Value.Count; j++)
                {
                    // Rotate the shape accordingly
                    rotTemp = packEvol.R1R2Rotation(i, j);
                    shapes[actObjNum].transform.rotation = rotTemp;
                    FindValidPos(shapes[actObjNum], i, j);
                    RemoveUnnessPos(i, j);
                }
            }
        }
    }
コード例 #2
0
ファイル: GtPack.cs プロジェクト: princeton-vl/PackIt_Extra
    /**
     * An imporved version of GetGtStepAction where we capture all the possible valid action for a particular
     * pack configuration. Note that the actions are only valid in context of the currect pack configuration
     * and not all possible ways of packing the shapes.
     */
    public List <StepAction2> GetGtStepAction2(ref Pack pack, List <StepAction> gtStepAction, bool rotBeforeMov = false)
    {
        GameObject[] shapes = packEvol.VisualizePack(pack, loadFromResources: false, keepRenderer: false);

        List <StepAction2> stepActList2 = new List <StepAction2>();
        int stepNum;

        // add all the movements
        for (int i = 0; i < pack.sources.Length; i++)
        {
            stepNum = i;
            int step;
            if (rotBeforeMov)
            {
                step = 4;
            }
            else
            {
                step = 3;
            }

            List <Vector3Int> action = new List <Vector3Int>()
            {
                GetGtAction(step, stepNum, gtStepAction)
            };

            stepActList2.Add(new StepAction2(step, stepNum, action));
        }

        // add all the possible rotations
        for (int i = 0; i < pack.sources.Length; i++)
        {
            stepNum = i;
            // old gt shape index
            Vector3Int _          = GetGtAction(2, stepNum, gtStepAction);
            int        shapeIndex = _.x;
            GameObject shape      = shapes[shapeIndex];
            shape.transform.position = new Vector3(100, 100f, 100f);

            List <Vector3Int> action = new List <Vector3Int>();
            for (int r1 = 0; r1 < packEvol.r1Value.Count; r1++)
            {
                for (int r2 = 0; r2 < packEvol.r2Value.Count; r2++)
                {
                    Quaternion rotTemp = packEvol.R1R2Rotation(r1, r2);
                    shape.transform.rotation = rotTemp;
                    if (!WillShapeCollide(shape, pack.positions[shapeIndex]))
                    {
                        action.Add(new Vector3Int(r1 * packEvol.r2Value.Count + r2, 0, 0));
                    }
                }
            }

            // put the shape back
            shape.transform.rotation = pack.rotations[shapeIndex];
            shape.transform.position = pack.positions[shapeIndex];

            if (rotBeforeMov)
            {
                stepActList2.Add(new StepAction2(3, stepNum, action));
            }
            else
            {
                stepActList2.Add(new StepAction2(4, stepNum, action));
            }
        }

        // assert all shapes in correct rotation and postition
        for (int i = 0; i < pack.sources.Length; i++)
        {
            Debug.Assert(shapes[i].transform.rotation == pack.rotations[i]);
            Debug.Assert(shapes[i].transform.position == pack.positions[i]);
        }

        // An n x (n+1) matrix
        // The (n+1)th node represents the bottom
        // represents the botton shapes for each shape
        int[,] shapeCon = BottomShapeMatrix(shapes);

        List <int> shapesAlreadyAdded = new List <int>();

        shapesAlreadyAdded.Add(pack.sources.Length);
        for (int i = 0; i < pack.sources.Length; i++)
        {
            List <Vector3Int> possibleShapesToAdd = new List <Vector3Int>();
            foreach (int shapeAlreadyAdded in shapesAlreadyAdded)
            {
                for (int j = 0; j < pack.sources.Length; j++)
                {
                    if (shapeCon[j, shapeAlreadyAdded] == 1)
                    {
                        if (!possibleShapesToAdd.Contains(new Vector3Int(j, 0, 0)) && !shapesAlreadyAdded.Contains(j))
                        {
                            possibleShapesToAdd.Add(new Vector3Int(j, 0, 0));
                        }
                    }
                }
            }

            stepNum = i;
            stepActList2.Add(new StepAction2(2, stepNum, possibleShapesToAdd));

            // add the next shape
            Vector3Int _ = GetGtAction(2, stepNum, gtStepAction);
            // making sure that the next shape added is one of the possibleShapesToAdd
            Debug.Assert(possibleShapesToAdd.Contains(_));
            int        shapeIndex = _.x;
            GameObject shape      = shapes[shapeIndex];
            shape.transform.position = pack.positions[shapeIndex];
            shapesAlreadyAdded.Add(shapeIndex);
        }

        int shapesLength = shapes.Length;

        for (int i = 0; i < shapesLength; i++)
        {
            UnityEngine.Object.DestroyImmediate(shapes[i]);
        }

        return(stepActList2);
    }