コード例 #1
0
ファイル: CDBTest.cs プロジェクト: tabinfl/Inception
    void blah(TestTile tile, TestTile other)
    {
        int otherIndexSouth            = (int)Math.Round((South(tile) - South(other)) / Spacing(other.LOD));
        int otherIndexNorth            = (int)Math.Round((North(tile) - South(other)) / Spacing(other.LOD));
        int otherIndexWest             = (int)Math.Round((West(tile) - West(other)) / Spacing(other.LOD));
        int otherIndexEast             = (int)Math.Round((East(tile) - West(other)) / Spacing(other.LOD));
        int otherVertexOffset          = (MeshDimension(other.LOD) * otherIndexSouth) + otherIndexWest;
        int otherVertexOffsetNorthWest = (MeshDimension(other.LOD) * otherIndexNorth) + otherIndexWest;
        int otherVertexOffsetSouthEast = (MeshDimension(other.LOD) * otherIndexSouth) + otherIndexEast;
        int tileVertexOffset           = 0;
        int tileVertexOffsetNorthWest  = MeshDimension(tile.LOD) * (MeshDimension(tile.LOD) - 1);
        int tileVertexOffsetSouthEast  = MeshDimension(tile.LOD) - 1;

        int tileToOtherRatio = (int)Math.Pow(2, tile.LOD - other.LOD);
        int otherCount       = Dimension(tile.LOD) / tileToOtherRatio;

        for (int i = 0; i <= otherCount; ++i)
        {
            tile.vertices[tileVertexOffset + (i * tileToOtherRatio)].y = other.vertices[otherVertexOffset + i].y;                                                                          // south
            tile.vertices[tileVertexOffset + (MeshDimension(tile.LOD) * i * tileToOtherRatio)].y = other.vertices[otherVertexOffset + (MeshDimension(other.LOD) * i)].y;                   // west
            tile.vertices[tileVertexOffsetNorthWest + (i * tileToOtherRatio)].y = other.vertices[otherVertexOffsetNorthWest + i].y;                                                        // north
            tile.vertices[tileVertexOffsetSouthEast + (MeshDimension(tile.LOD) * i * tileToOtherRatio)].y = other.vertices[otherVertexOffsetSouthEast + (MeshDimension(other.LOD) * i)].y; // east
        }

        if (tile.LOD <= other.LOD)
        {
            return;
        }
        InterpolateSouthEdge(tile, tileToOtherRatio);
        InterpolateWestEdge(tile, tileToOtherRatio);
        InterpolateNorthEdge(tile, tileToOtherRatio);
        InterpolateEastEdge(tile, tileToOtherRatio);
    }
コード例 #2
0
ファイル: CDBTest.cs プロジェクト: tabinfl/Inception
    void UpdateTileEdges(TestTile tile, TestTile other)
    {
        if (tile.LOD < other.LOD)
        {
            return;
        }
        if (IsSouth(tile, other))
        {
            UpdateTileEdges_South(tile, other);
        }
        if (IsWest(tile, other))
        {
            UpdateTileEdges_West(tile, other);
        }
        if (IsNorth(tile, other))
        {
            UpdateTileEdges_North(tile, other);
        }
        if (IsEast(tile, other))
        {
            UpdateTileEdges_East(tile, other);
        }


        if (tile.LOD <= other.LOD)
        {
            return;
        }
        int step = VertexStep(tile, other);

        InterpolateSouthEdge(tile, step);
        InterpolateWestEdge(tile, step);
        InterpolateNorthEdge(tile, step);
        InterpolateEastEdge(tile, step);
    }
コード例 #3
0
        public void ShouldBeClosedByDefault()
        {
            var tile = new TestTile(TileType.Dirt);

            tile.IsDiscovered
            .Should()
            .BeFalse();
        }
コード例 #4
0
ファイル: CDBTest.cs プロジェクト: tabinfl/Inception
    ////////////////////////////////////////////////////////////

    TestTile AddTile(int lod, float x, float y)
    {
        var tile = new TestTile()
        {
            LOD       = lod,
            X         = x,
            Y         = y,
            vertices  = new Vector3[MeshDimension(lod) * MeshDimension(lod)],
            triangles = new int[Dimension(lod) * Dimension(lod) * 6],
        };

        tile.gameObject = new GameObject();
        tile.gameObject.transform.SetParent(gameObject.transform);
        tile.gameObject.transform.Translate(20.0f, 0.0f, 120.0f);
        tile.gameObject.name = Name(tile);
        tile.gameObject.AddComponent <MeshRenderer>();
        tile.mesh             = tile.gameObject.AddComponent <MeshFilter>().mesh;
        tile.mesh.indexFormat = UnityEngine.Rendering.IndexFormat.UInt32;

        int   dim     = Dimension(tile.LOD);
        int   meshDim = MeshDimension(tile.LOD);
        float spacing = Spacing(lod);

        for (int row = 0; row < meshDim; ++row)
        {
            for (int col = 0; col < meshDim; ++col)
            {
                float elev = lod * 4.0f;
                //elev += random.Next(2);
                tile.vertices[(row * meshDim) + col] = new Vector3(tile.X + (col * spacing), elev, tile.Y + (row * spacing));
            }
        }
        int triangleIndex = 0;

        for (int row = 0; row < dim; ++row)
        {
            for (int col = 0; col < dim; ++col, triangleIndex += 6)
            {
                int vertexIndex     = (row * meshDim) + col;
                int upperLeftIndex  = vertexIndex;
                int upperRightIndex = upperLeftIndex + 1;
                int lowerLeftIndex  = upperLeftIndex + meshDim;
                int lowerRightIndex = lowerLeftIndex + 1;
                tile.triangles[triangleIndex + 0] = lowerLeftIndex;
                tile.triangles[triangleIndex + 1] = upperRightIndex;
                tile.triangles[triangleIndex + 2] = upperLeftIndex;
                tile.triangles[triangleIndex + 3] = upperRightIndex;
                tile.triangles[triangleIndex + 4] = lowerLeftIndex;
                tile.triangles[triangleIndex + 5] = lowerRightIndex;
            }
        }
        tile.mesh.vertices  = tile.vertices;
        tile.mesh.triangles = tile.triangles;
        tiles.Add(tile);
        return(tile);
    }
コード例 #5
0
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();
        TestTile t = (TestTile)target;

        if (GUILayout.Button("Make Tile"))
        {
            // t.GenerateTile();
        }
    }
コード例 #6
0
    public void TilePlacements()
    {
        Board       b        = new Board(new Vector2Int(6, 6));
        List <Tile> tileList = TestTile.GenerateTiles();

        Assert.IsNotNull(b.PlaceTile(tileList[0], new Vector2Int(0, 0), Direction.UP), "On board placement");
        Assert.IsNull(b.PlaceTile(tileList[0], new Vector2Int(0, 6), Direction.UP), "Off board placement");
        Assert.IsNull(b.PlaceTile(tileList[0], new Vector2Int(-4, 4), Direction.UP), "Off board placement");
        Assert.IsNull(b.PlaceTile(tileList[1], new Vector2Int(0, 0), Direction.UP), "Tile Already in Position");
    }
コード例 #7
0
ファイル: TestHand.cs プロジェクト: DrDoak/EECS397
    public void IsInHand()
    {
        Hand        h        = new Hand();
        List <Tile> tileList = TestTile.GenerateTiles();

        h.AddToHand(tileList [0]);
        h.AddToHand(tileList [2]);
        Assert.False(h.IsInHand(tileList[3]), "Detects if tile is not in hand");
        Assert.True(h.IsInHand(tileList[0]), "Detects if tile is in hand");
        Assert.True(h.IsInHand(tileList[1]), "Detects if identical tile is not in hand");
    }
コード例 #8
0
ファイル: TestHand.cs プロジェクト: DrDoak/EECS397
    public void BasicAddRemove()
    {
        Hand        h        = new Hand();
        List <Tile> tileList = TestTile.GenerateTiles();

        h.AddToHand(tileList [0]);
        h.AddToHand(tileList [1]);
        Assert.AreEqual(2, h.Pieces.Count, "Tiles added normally");
        Assert.IsNull(h.RemoveFromHand(tileList[2]), "Does not attempt to remove tile that is not present");
        Assert.AreEqual(h.RemoveFromHand(tileList[1]), tileList[1], "Correct tile removed");
        Assert.AreEqual(1, h.Pieces.Count, "Tile removed");
    }
コード例 #9
0
    public void SymmetryScoresTest()
    {
        PlayerMachine pm        = new PlayerMachine("pete");
        List <Tile>   testTiles = TestTile.GenerateTiles();

        Assert.AreEqual(4, pm.UniqueRotationTiles(testTiles [0]), "No rotational symmetry detected");
        Assert.AreEqual(4, pm.UniqueRotationTiles(testTiles [1]), "No rotational symmetry detected");
        Assert.AreEqual(4, pm.UniqueRotationTiles(testTiles [2]), "No rotational symmetry detected");
        Assert.AreEqual(4, pm.UniqueRotationTiles(testTiles [3]), "No rotational symmetry detected");
        Assert.AreEqual(1, pm.UniqueRotationTiles(testTiles [4]), "Two of three other paths are symmetrical to first path");
        Assert.AreEqual(1, pm.UniqueRotationTiles(testTiles [5]), "All paths are symmetrical to each other");
        Assert.AreEqual(2, pm.UniqueRotationTiles(testTiles [6]), "All paths are symmetrical to each other");
    }
コード例 #10
0
    public void MovePlayer()
    {
        Board       b        = new Board(new Vector2Int(6, 6));
        List <Tile> tileList = TestTile.GenerateTiles();
        SPlayer     sp       = new SPlayer();

        b.AddNewPlayer(sp, new PlayerLocation(new Vector2Int(0, 4), 7));

        b.MovePlayer(sp, tileList[0]);

        Assert.AreEqual(new Vector2Int(0, 4), sp.Location.Coordinate, "Moved player to correct coordinate");
        Assert.AreEqual(7, sp.Location.PositionOnTile, "Moved player to correct position");
    }
コード例 #11
0
    public List <TileBase> GetTiles(TestTile del)
    {
        var ret = new List <TileBase>();

        foreach (TileBase tile in tiles)
        {
            if (del(tile))
            {
                ret.Add(tile);
            }
        }
        return(ret);
    }
コード例 #12
0
    public void ChooseAsymmetricTest()
    {
        Board         b  = new Board(new Vector2Int(6, 6));
        PlayerMachine pm = new PlayerMachine("pete");

        pm.AIType = PlayerAIType.ASYMMETRIC;
        List <Tile> testTiles = TestTile.GenerateTiles();
        Hand        h         = new Hand();

        h.AddToHand(testTiles [0]);
        h.AddToHand(testTiles [4]);
        h.AddToHand(testTiles [5]);
        Assert.AreEqual(testTiles[0], pm.PlayTurn(b, h.Pieces, b.CurrentDeck.Pieces.Count));
    }
コード例 #13
0
ファイル: CDBTest.cs プロジェクト: tabinfl/Inception
 void InterpolateEdge(TestTile tile, int segmentWidth, int vertexArrayOffset, int vertexArrayStep)
 {
     for (int i = 0; i + segmentWidth < MeshDimension(tile.LOD); i += segmentWidth)
     {
         int   startIndex = vertexArrayOffset + (i * vertexArrayStep);
         int   endIndex   = startIndex + (segmentWidth * vertexArrayStep);
         float a          = tile.vertices[startIndex].y;
         float b          = tile.vertices[endIndex].y;
         float slope      = (b - a) / segmentWidth;
         for (int j = 1; j < segmentWidth; ++j)
         {
             tile.vertices[startIndex + (j * vertexArrayStep)].y = a + (slope * j);
         }
     }
 }
コード例 #14
0
    public void ChooseSymmetricTest()
    {
        Administrator a = new Administrator();
        Board         b = new Board(new Vector2Int(6, 6));

        a.SetBoard(b);
        PlayerMachine pm = new PlayerMachine("pete");

        a.AddNewPlayer(pm);
        pm.AIType = PlayerAIType.SYMMETRIC;
        List <Tile> testTiles = TestTile.GenerateTiles();
        Hand        h         = new Hand();

        h.AddToHand(testTiles [0]);
        h.AddToHand(testTiles [4]);
        h.AddToHand(testTiles [5]);
        //4 or 5 both work.
        Assert.AreEqual(testTiles[5], pm.PlayTurn(b, h.Pieces, b.CurrentDeck.Pieces.Count));
    }
コード例 #15
0
    public void GetAdjacentPlayers()
    {
        Board       b        = new Board(new Vector2Int(6, 6));
        List <Tile> tileList = TestTile.GenerateTiles();

        SPlayer sp = new SPlayer();

        b.AddNewPlayer(sp, new PlayerLocation(new Vector2Int(0, 4), 7));

        SPlayer sp2 = new SPlayer();

        b.AddNewPlayer(sp2, new PlayerLocation(new Vector2Int(0, 4), 6));

        b.PlaceTile(tileList[2], new Vector2Int(1, 4), Direction.UP);
        b.PlaceTile(tileList[1], new Vector2Int(0, 4), Direction.UP);

        Assert.AreEqual(0, b.GetAdjacentPlayers(tileList[2]).Count, "Did not incorrectly grab a player");
        Assert.AreEqual(2, b.GetAdjacentPlayers(tileList[1]).Count, "Found adjacent player");
    }
コード例 #16
0
        static void PathfindTest()
        {
            var map = new Map <TestTile>(1, 100, 20);

            PopulateMap(map);
            Console.WriteLine(map);

            var search = new MapAStar <TestTile>();

            search.PathFind(map.Get(0), t => TestTile.IsPassable(t.type), new Point <int>(2, 0), new Point <int>(98, 19));

            RenderPath(map.Get(0), search);

            var solutionRender = new Layer <TestTile>(map.width, map.height);

            RenderSearchExtent(solutionRender, search);

            var layer = new Layer <TestTile>(100, 20);

            // create a bunch of walls
            layer.Fill((x, y, oldTile) =>
            {
                return(new TestTile('.'));
            });
            for (int c = 0; c < layer.size.x; c += 2)
            {
                for (int r = 1; r < layer.size.y; ++r)
                {
                    layer.Set(c, r, new TestTile('x'));
                }
                c += 2;
                for (int r = 0; r < layer.size.y - 1; ++r)
                {
                    layer.Set(c, r, new TestTile('x'));
                }
            }
            Console.WriteLine(layer);

            search = new MapAStar <TestTile>();
            search.PathFind(layer, (TestTile t) => TestTile.IsPassable(t.type), new Point <int>(0, 0), new Point <int>(99, 19));
            RenderPath(layer, search);
        }
コード例 #17
0
    public List <TileBase> GetClutteredTiles()
    {
        TestTile del = delegate(TileBase tile)
        {
            if (!tile.isConstructed)
            {
                return(false);
            }
            foreach (Resource res in tile.clutteredResources)
            {
                if (!res.isClaimed)
                {
                    return(true);
                }
            }
            return(false);
        };

        return(GetTiles(del));
    }
コード例 #18
0
ファイル: CDBTest.cs プロジェクト: tabinfl/Inception
    void UpdateTileEdges_East(TestTile tile, TestTile other)
    {
        float offsetDistanceX = East(tile) - West(other);
        float offsetDistanceY = South(tile) - South(other);
        int   offsetIndexX    = Mathf.RoundToInt(offsetDistanceX / Spacing(other.LOD));
        int   offsetIndexY    = Mathf.RoundToInt(offsetDistanceY / Spacing(other.LOD));
        int   offsetIndex     = (offsetIndexY * MeshDimension(other.LOD)) + offsetIndexX;

        int tileVertexOffset  = MeshDimension(tile.LOD) - 1;
        int tileVertexStep    = MeshDimension(tile.LOD);
        int otherVertexOffset = offsetIndex;
        int otherVertexStep   = MeshDimension(other.LOD);
        int tileStep          = (int)Mathf.Pow(2, tile.LOD - other.LOD);

        int otherCount = Dimension(tile.LOD) / tileStep;

        for (int i = 0; i <= otherCount; ++i)
        {
            int tileVertexIndex  = tileVertexOffset + (tileVertexStep * i * tileStep);
            int otherVertexIndex = otherVertexOffset + (otherVertexStep * i);
            tile.vertices[tileVertexIndex].y = other.vertices[otherVertexIndex].y;
        }
    }
コード例 #19
0
ファイル: TestScene.cs プロジェクト: HapaxL/pingine
        public override Dictionary <ulong, Entity> InitEntities()
        {
            var entities = new Dictionary <ulong, Entity>();

            movingEntities = new Dictionary <ulong, TestEntity>();

            for (int i = 0; i < 150; i++)
            {
                var cube = new TestEntity();
                entities.Add(cube.Id, cube);
                movingEntities.Add(cube.Id, cube);
            }

            for (int j = 0; j < 45; j++)
            {
                for (int i = 0; i < 80; i++)
                {
                    var tile = new TestTile(i * 16, j * 16, 0, Game.RNG.Next(6));
                    entities.Add(tile.Id, tile);
                }
            }

            return(entities);
        }
コード例 #20
0
ファイル: CDBTest.cs プロジェクト: tabinfl/Inception
 bool IsEast(TestTile tile, TestTile other)
 {
     if (East(tile) > East(other))
     {
         return(false);
     }
     if (East(tile) < West(other))
     {
         return(false);
     }
     if (North(tile) <= South(other))
     {
         return(false);
     }
     if (South(tile) >= North(other))
     {
         return(false);
     }
     if ((tile.LOD == other.LOD) && (East(tile) == East(other)))
     {
         return(false);
     }
     return(true);
 }
コード例 #21
0
ファイル: CDBTest.cs プロジェクト: tabinfl/Inception
 bool IsNorth(TestTile tile, TestTile other)
 {
     if (North(tile) > North(other))
     {
         return(false);
     }
     if (North(tile) < South(other))
     {
         return(false);
     }
     if (East(tile) <= West(other))
     {
         return(false);
     }
     if (West(tile) >= East(other))
     {
         return(false);
     }
     if ((tile.LOD == other.LOD) && (North(tile) == North(other)))
     {
         return(false);
     }
     return(true);
 }
コード例 #22
0
ファイル: CDBTest.cs プロジェクト: tabinfl/Inception
 string Name(TestTile tile) => string.Format("TILE LOD:{0} X:{1:0.00} Y:{2:0.00} D:{3} SZ:{4:0.00}", tile.LOD, tile.X, tile.Y, Dimension(tile.LOD), Size(tile.LOD));
コード例 #23
0
ファイル: CDBTest.cs プロジェクト: tabinfl/Inception
 float South(TestTile tile) => tile.Y;
コード例 #24
0
ファイル: CDBTest.cs プロジェクト: tabinfl/Inception
 void InterpolateNorthEdge(TestTile tile, int segmentWidth) => InterpolateEdge(tile, segmentWidth, MeshDimension(tile.LOD) * (MeshDimension(tile.LOD) - 1), 1);
コード例 #25
0
ファイル: CDBTest.cs プロジェクト: tabinfl/Inception
 void InterpolateEastEdge(TestTile tile, int segmentWidth) => InterpolateEdge(tile, segmentWidth, MeshDimension(tile.LOD) - 1, MeshDimension(tile.LOD));
コード例 #26
0
ファイル: CDBTest.cs プロジェクト: tabinfl/Inception
 void InterpolateSouthEdge(TestTile tile, int segmentWidth) => InterpolateEdge(tile, segmentWidth, 0, 1);
コード例 #27
0
ファイル: CDBTest.cs プロジェクト: tabinfl/Inception
 float West(TestTile tile) => tile.X;
コード例 #28
0
ファイル: CDBTest.cs プロジェクト: tabinfl/Inception
 float North(TestTile tile) => tile.Y + Size(tile.LOD);
コード例 #29
0
ファイル: CDBTest.cs プロジェクト: tabinfl/Inception
 int VertexStep(TestTile tile, TestTile other) => (int)Math.Pow(2, tile.LOD - other.LOD);
コード例 #30
0
ファイル: CDBTest.cs プロジェクト: tabinfl/Inception
 float East(TestTile tile) => tile.X + Size(tile.LOD);