Ejemplo n.º 1
0
    public void TestRotate()
    {
        Blueprint x_line = new Blueprint(3, 3, 3);

        x_line.AddBlock(new Discrete3DCoord(0, 0, 0), 1);
        x_line.AddBlock(new Discrete3DCoord(1, 0, 0), 1);
        x_line.AddBlock(new Discrete3DCoord(2, 0, 0), 1);

        Blueprint y_line = x_line.Rotate(RotationAxis.Z_AXIS, 1);
        Blueprint z_line = x_line.Rotate(RotationAxis.Y_AXIS, 1);

        Assert.AreEqual(1, y_line.GetBlocks()[2, 0, 0]);
        Assert.AreEqual(1, y_line.GetBlocks()[2, 1, 0]);
        Assert.AreEqual(1, y_line.GetBlocks()[2, 2, 0]);

        Assert.AreEqual(1, z_line.GetBlocks()[2, 0, 0]);
        Assert.AreEqual(1, z_line.GetBlocks()[2, 0, 1]);
        Assert.AreEqual(1, z_line.GetBlocks()[2, 0, 2]);

        CollectionAssert.AreEqual(
            x_line.GetBlocks(),
            y_line.Rotate(RotationAxis.Z_AXIS, 3).GetBlocks());

        CollectionAssert.AreEqual(
            x_line.GetBlocks(),
            z_line.Rotate(RotationAxis.Y_AXIS, -1).GetBlocks());
    }
Ejemplo n.º 2
0
    public void TestAddBlock()
    {
        Blueprint a = new Blueprint(3, 3, 3);

        a.AddBlock(new Discrete3DCoord(0, 0, 0), 1);
        Assert.AreEqual(1, a.GetBlocks()[0, 0, 0]);
        a.AddBlock(new Discrete3DCoord(1, 2, 0), 3);
        Assert.AreEqual(1, a.GetBlocks()[1, 2, 0], 3);
    }
Ejemplo n.º 3
0
    // Calculates the amount of volume that has a roof over it.
    int CalcCoveredVolume(Blueprint blueprint)
    {
        int total = 0;

        int[,,] blocks = blueprint.GetBlocks();
        for (int x = 0; x < blueprint.GetDims().x; x++)
        {
            for (int z = 0; z < blueprint.GetDims().z; z++)
            {
                bool has_cover = false;
                for (int y = blueprint.GetDims().y - 1; y >= 0; y--)
                {
                    if (blocks[x, y, z] > 0)
                    {
                        has_cover = true;
                    }
                    else if (has_cover)
                    {
                        total++;
                    }
                }
            }
        }
        return(total);
    }
Ejemplo n.º 4
0
    int CountBlocks(Blueprint blueprint)
    {
        int total = 0;

        foreach (int i in blueprint.GetBlocks())
        {
            total += i;
        }
        return(total);
    }
Ejemplo n.º 5
0
    public void TestGetBlocks()
    {
        Blueprint a = new Blueprint(5, 7, 1);

        int[,,] a_blocks = a.GetBlocks();
        Assert.AreEqual(5, a_blocks.GetLength(0));
        Assert.AreEqual(7, a_blocks.GetLength(1));
        Assert.AreEqual(1, a_blocks.GetLength(2));

        foreach (int i in a_blocks)
        {
            Assert.AreEqual(i, 0);
        }
    }
Ejemplo n.º 6
0
    public void TestDeleteID()
    {
        Blueprint empty = new Blueprint(4, 4, 4);
        Blueprint arch  = new Blueprint(4, 4, 4);

        CollectionAssert.AreEqual(empty.GetBlocks(), arch.GetBlocks());

        arch.AddBlock(new Discrete3DCoord(0, 0, 0), 1);
        arch.AddBlock(new Discrete3DCoord(0, 1, 0), 1);
        arch.AddBlock(new Discrete3DCoord(0, 2, 0), 1);

        arch.AddBlock(new Discrete3DCoord(2, 0, 0), 1);
        arch.AddBlock(new Discrete3DCoord(2, 1, 0), 1);
        arch.AddBlock(new Discrete3DCoord(2, 2, 0), 1);

        arch.AddBlock(new Discrete3DCoord(0, 3, 0), 1);
        arch.AddBlock(new Discrete3DCoord(1, 3, 0), 1);
        arch.AddBlock(new Discrete3DCoord(2, 3, 0), 1);

        CollectionAssert.AreNotEqual(empty.GetBlocks(), arch.GetBlocks());

        arch.DeleteID(1);
        CollectionAssert.AreEqual(empty.GetBlocks(), arch.GetBlocks());
    }
Ejemplo n.º 7
0
    public void TestApplyDesign()
    {
        Blueprint composite = new Blueprint(4, 5, 4);

        Blueprint long_block = new Blueprint(4, 1, 1);

        long_block.AddBlock(new Discrete3DCoord(0, 0, 0), 1);
        long_block.AddBlock(new Discrete3DCoord(1, 0, 0), 1);
        long_block.AddBlock(new Discrete3DCoord(2, 0, 0), 1);
        long_block.AddBlock(new Discrete3DCoord(3, 0, 0), 1);

        Blueprint tall_block = new Blueprint(2, 3, 1);

        tall_block.AddBlock(new Discrete3DCoord(0, 0, 0), 1);
        tall_block.AddBlock(new Discrete3DCoord(0, 1, 0), 1);
        tall_block.AddBlock(new Discrete3DCoord(0, 2, 0), 1);

        Blueprint really_really_long_block = new Blueprint(10, 1, 1);

        really_really_long_block.AddBlock(new Discrete3DCoord(0, 0, 0), 1);
        really_really_long_block.AddBlock(new Discrete3DCoord(1, 0, 0), 1);
        really_really_long_block.AddBlock(new Discrete3DCoord(2, 0, 0), 1);
        really_really_long_block.AddBlock(new Discrete3DCoord(3, 0, 0), 1);
        really_really_long_block.AddBlock(new Discrete3DCoord(4, 0, 0), 1);
        really_really_long_block.AddBlock(new Discrete3DCoord(5, 0, 0), 1);
        really_really_long_block.AddBlock(new Discrete3DCoord(6, 0, 0), 1);
        really_really_long_block.AddBlock(new Discrete3DCoord(7, 0, 0), 1);
        really_really_long_block.AddBlock(new Discrete3DCoord(8, 0, 0), 1);
        really_really_long_block.AddBlock(new Discrete3DCoord(9, 0, 0), 1);

        composite.ApplyDesign(long_block, 0, 0, 0);

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

        unique_ids.Add(composite.GetBlocks()[0, 0, 0]);
        CollectionAssert.AllItemsAreUnique(unique_ids);
        CollectionAssert.DoesNotContain(unique_ids, 0);

        composite.ApplyDesign(tall_block, 0, 1, 0);
        unique_ids.Add(composite.GetBlocks()[0, 1, 0]);
        CollectionAssert.AllItemsAreUnique(unique_ids);
        CollectionAssert.DoesNotContain(unique_ids, 0);

        composite.ApplyDesign(tall_block, 3, 1, 0);
        unique_ids.Add(composite.GetBlocks()[3, 1, 0]);
        CollectionAssert.AllItemsAreUnique(unique_ids);
        CollectionAssert.DoesNotContain(unique_ids, 0);

        composite.ApplyDesign(really_really_long_block, 0, 3, 0);
        unique_ids.Add(composite.GetBlocks()[0, 3, 0]);
        CollectionAssert.AllItemsAreUnique(unique_ids);
        CollectionAssert.DoesNotContain(unique_ids, 0);

        Assert.AreEqual(composite.GetBlocks()[0, 3, 0], composite.GetBlocks()[3, 3, 0]);
    }
Ejemplo n.º 8
0
    public void TestCopyInto()
    {
        Blueprint a = new Blueprint(3, 3, 3);

        a.AddBlock(new Discrete3DCoord(0, 0, 0), 1);
        a.AddBlock(new Discrete3DCoord(0, 0, 1), 1);
        a.AddBlock(new Discrete3DCoord(0, 0, 2), 1);

        Blueprint mismatched_size = new Blueprint(2, 3, 3);

        Assert.Throws <System.ArgumentException>(() => a.CopyInto(mismatched_size));

        Blueprint copy = new Blueprint(3, 3, 3);

        a.CopyInto(copy);
        CollectionAssert.AreEqual(a.GetBlocks(), copy.GetBlocks());
    }