void InitialiseCellArray()
    {
        int id = 0;

        for (int i = 0; i < gridSizeX; i++)
        {
            for (int j = 0; j < gridSizeY; j++)
            {
                //Iniitialise cell array at current position
                waterCellArray[i, j] = new WaterCell(0, new Vector2i(i, j), id++);
                //Create cell at position with -1 volume
                CreateCell(new Vector2i(i, j), 0);
                //Ensure all cells initially are inactive
                waterCellArray[i, j].fActive = false;
                //Add to active cell index, after first run through of this list all inactive cells will drop off, this is just to save manually added active cells to the list
                activeCellIndexListA.Add(new Vector2i(i, j));
            }
        }

        //Have to do this after all cells have been initialised otherwise neighbours wont exist
        for (int i = 0; i < gridSizeX; i++)
        {
            for (int j = 0; j < gridSizeY; j++)
            {
                //Populate neighbours
                waterCellArray[i, j].populateNeighbourReferences();
            }
        }
    }
 void Start()
 {
     thisCell           = WaterController.Current.waterCellArray[position.x, position.y];
     xPositiveNeighbour = thisCell.getNeighbourData(Direction.xPositive);
     xNegativeNeighbour = thisCell.getNeighbourData(Direction.xNegative);
     zPositiveNeighbour = thisCell.getNeighbourData(Direction.zPositive);
     zNegativeNeighbour = thisCell.getNeighbourData(Direction.zNegative);
 }
예제 #3
0
        public void ShouldBeOfWaterType()
        {
            //Arrange
            var waterCell = new WaterCell(1, 1);

            //Assert
            waterCell.CellType.ShouldBeEqual(CellType.Water);
        }
예제 #4
0
        public void ShouldBeTerminal()
        {
            //Arrange
            var waterCell = new WaterCell(1, 1);

            //Assert
            waterCell.Terminal.ShouldBeTrue();
        }
예제 #5
0
        public void ShouldBeDiscoverdByDefault()
        {
            //Arrange
            var waterCell = new WaterCell(1, 1);

            //Assert
            waterCell.Discoverd.ShouldBeTrue();
        }
예제 #6
0
        public Ship(Team team, WaterCell cell, ShipMovement movement = ShipMovement.None)
        {
            Gold      = 0;
            this.team = team;
            Cell      = cell;

            SelectStrategy(movement);
        }
예제 #7
0
        public void CellsEqualByPostition1()
        {
            var cell1 = new WaterCell(1, 1);
            var cell2 = new WaterCell(1, 1);

            // Assert
            (cell1 == cell2).Should().BeTrue();
        }
예제 #8
0
        public void TestFailOnAttackWaterSergeant_ThrowsPieceConflictHandlerException()
        {
            Piece att = new Sergeant(Ownership.FirstPlayer);
            ICell def = new WaterCell();

            TestDelegate code = () => ConflictHandler.Handle(att, def);

            Assert.Throws(typeof(PieceConflictHandlerException), code);
        }
예제 #9
0
        public void CellsEqualByType()
        {
            var cell1 = new WaterCell(1, 1);
            var cell2 = new WaterCell(1, 1);
            var cell3 = new GrassCell(1, 1);

            // Assert
            (cell1 == cell2).Should().BeTrue();
            (cell1 == cell3).Should().BeFalse();
        }
예제 #10
0
        public void WhenThereIsNoPirates()
        {
            var cell = new WaterCell(1, 2);

            ship.Pirates.Clear();

            // act
            ship.MoveTo(cell);

            // Assert
            ship.Cell
            .ShouldBeEqual(new WaterCell(1, 1));
        }
예제 #11
0
        public void AlongTheHorizontalLineIfOnHorizontal()
        {
            var blackShip = new Ship(teamBlack, new WaterCell(1, 5), Ship.ShipMovement.Horizontal);

            blackShip.Pirates.Add(teamBlack.Pirates.Current);

            // act
            var cell = new WaterCell(2, 5);

            blackShip.MoveTo(cell);

            //assert
            blackShip.Cell.ShouldBeEqual(cell);
        }
예제 #12
0
        public bool MoveTo(WaterCell cell)
        {
            if (strategy.MoveAllowedTo(cell))
            {
                Cell = cell;
                foreach (var pirate in Pirates)
                {
                    pirate.Position = Position;
                }

                GrabPirates(cell);
                return(true);
            }
            return(false);
        }
예제 #13
0
        public void WhenPiratesOnShip()
        {
            var destinationCell = new WaterCell(1, 2);

            ship.Pirates.Add(teamBlack.Pirates.GetNext());
            // act
            ship.MoveTo(destinationCell);

            // Assert
            ship.Pirates.Count
            .Should()
            .BeGreaterThan(1);

            ship.Cell
            .ShouldBeEqual(destinationCell);
        }
예제 #14
0
 private void InitBoardSystemCells()
 {
     // Fills the middle two rows with the defaults ICells:
     // two Empty, two Water, two Empty, two Water, two Empty per row
     // Assumes classic board
     for (int index = DefaultBoardSize * 4; index < DefaultBoardSize * 6; index++)
     {
         if ((index % DefaultBoardSize) / 2 % 2 == 0)
         {
             State[index] = new EmptyCell();
         }
         else
         {
             State[index] = new WaterCell();
         }
     }
 }
예제 #15
0
        public void OnlyWhenPirateOnShip()
        {
            ship = new Ship(teamBlack, waterCell);
            ship.Pirates.Add(teamBlack.Pirates.Current);

            var destinationCell = new WaterCell(1, 2);

            // act
            ship.MoveTo(destinationCell);

            // Assert
            ship.Pirates.Count
            .Should()
            .BeGreaterOrEqualTo(1);

            ship.Cell
            .ShouldBeEqual(destinationCell);
        }
예제 #16
0
        public void AlongTheVerticalLineIfOnHorizontal()
        {
            var originalCell = new WaterCell(1, 5);
            var blackShip    = new Ship(teamBlack, originalCell, Ship.ShipMovement.Horizontal);

            blackShip.Pirates.Add(teamBlack.Pirates.Current);

            // act
            var destCell = new WaterCell(1, 6);

            blackShip.MoveTo(destCell);

            //assert
            blackShip.Pirates.Count.Should()
            .BeGreaterOrEqualTo(1);

            blackShip.Cell.ShouldBeEqual(originalCell);
        }
예제 #17
0
        public void OldCellShouldReleaseShip()
        {
            // arrange
            var originalCell = new WaterCell(1, 1);
            var team         = new Team(TeamType.Black, new TestEmptyRules());
            var ship         = new Ship(team, originalCell);

            ship.Pirates.Add(team.Pirates.Current);

            // Act
            var newCell = new WaterCell(1, 2);

            ship.MoveTo(newCell);

            // Assert
            ship.Cell
            .ShouldBeEqual(newCell);
        }
예제 #18
0
    void InitWater()
    {
        //WaterCell[,] water =  new WaterCell[m_ter.terrainData.heightmapWidth,m_ter.terrainData.heightmapHeight];// allocate array
        waterSim   = new WaterCell[m_ter.terrainData.heightmapWidth, m_ter.terrainData.heightmapHeight];// allocate array
        waterlevel = new float[m_ter.terrainData.heightmapWidth, m_ter.terrainData.heightmapHeight];

        for (int x = 0; x < m_ter.terrainData.heightmapWidth; x++)
        {
            for (int y = 0; y < m_ter.terrainData.heightmapHeight; y++)
            {
                waterSim[x, y]           = new WaterCell(); // invoke constructor
                waterSim[x, y].volume    = startingVolume;
                waterSim[x, y].newVolume = startingVolume;
                waterSim[x, y].iteration = 0;
                waterlevel[x, y]         = 0.0f;
            }
        }
    }
예제 #19
0
        public void PirateCanMoveOnlyFromWaterToWater()
        {
            //Arrange
            var field  = new GreenField();
            var pirate = field.CurrentPirate;

            pirate.Position = new Position(0, 0);

            var waterCell = new WaterCell(1, 0);

            field.InsertCell(waterCell);

            //Act
            field.MovePirateTo(pirate, waterCell);

            //Assert
            pirate.Position.ShouldBeEqual(waterCell.Position);
        }
예제 #20
0
        private void GrabPirates(WaterCell cell)
        {
            if (team == null || team.Player == null)
            {
                return;
            }

            var teamTypes = team.Player.GetTeamTypes();

            foreach (var pirate in cell.Pirates)
            {
                if (teamTypes.Contains(pirate.TeamType))
                {
                    Pirates.Add(pirate);
                }
//                    else {
//                        pirate.ApplyCommand(Pirate.Actions.Kill);
//                    }
            }
        }
예제 #21
0
        public void AllPiratesShouldMoveWithShip()
        {
            // arrange
            var originalCell = new WaterCell(1, 1);
            var team         = new Team(TeamType.Black, new TestEmptyRules());
            var ship         = new Ship(team, originalCell);

            ship.Pirates.Add(team.Pirates.Current);
            ship.Pirates.Add(team.Pirates.GetNext());

            // Act
            var newCell = new WaterCell(1, 2);

            ship.MoveTo(newCell);

            // Assert
            foreach (var pirate in ship.Pirates)
            {
                pirate.Position
                .ShouldBeEqual(newCell.Position);
            }
        }
예제 #22
0
 public void TestInit()
 {
     waterCell = new WaterCell(1, 1);
     teamBlack = new Team(TeamType.Black, new TestEmptyRules());
 }
    void UpdateCells()
    {
        //For each cell in cell index list A
        foreach (Vector2i index in activeCellIndexListA)
        {
            //And if cell is active
            //if (waterCellArray[index.x, index.y].fActive)
            {
                //Compare against all neighbours
                foreach (Direction dir in neighboursToCompare)
                {
                    //If neighbour exists and is in range
                    if (index.x < gridSizeX - 1 && index.y < gridSizeY - 1 && index.x > 0 && index.y > 0)
                    {
                        //Get addition vector from direction we are checking
                        Vector2i additionVec2i = new Vector2i(0, 0);
                        switch (dir)
                        {
                        case Direction.xPositive:
                            additionVec2i = new Vector2i(1, 0);
                            break;

                        case Direction.xNegative:
                            additionVec2i = new Vector2i(-1, 0);
                            break;

                        case Direction.zPositive:
                            additionVec2i = new Vector2i(0, 1);
                            break;

                        case Direction.zNegative:
                            additionVec2i = new Vector2i(0, -1);
                            break;
                        }

                        //Check for solids in world height array, if this cell is less than the height of the solid, break out
                        if (waterCellArray[index.x, index.y].volume < worldHeightArray[index.x + additionVec2i.x, index.y + additionVec2i.y])
                        {
                            break;
                        }

                        //If this block is in a solid, volume should be 0
                        if (worldHeightArray[index.x, index.y] > 0)
                        {
                            waterCellArray[index.x, index.y].volume = 0;
                            break;
                        }

                        //Get reference to neighbour cell
                        WaterCell neighbourCell = waterCellArray[index.x + additionVec2i.x, index.y + additionVec2i.y];
                        //If neighbour is not done
                        if (!neighbourCell.fDone)
                        {
                            //If difference between volumes is greater than min amount
                            if (Mathf.Abs(waterCellArray[index.x, index.y].volume - neighbourCell.volume) > minVolume)
                            {
                                //Set previous volume to current volume
                                waterCellArray[index.x, index.y].previousVolume = waterCellArray[index.x, index.y].volume;
                                //Adjust this volume
                                waterCellArray[index.x, index.y].volume -= (waterCellArray[index.x, index.y].volume - neighbourCell.volume) * baseFlowRate;
                                //Adjust neighbour volume using previous volume
                                neighbourCell.volume += (waterCellArray[index.x, index.y].previousVolume - neighbourCell.volume) * baseFlowRate;

                                //If neighbour is not active
                                if (!neighbourCell.fActive)
                                {
                                    neighbourCell.fActive = true;
                                    activeCellIndexListB.Add(neighbourCell.position);
                                }
                                //If this cell is not active
                                if (!waterCellArray[index.x, index.y].fActive)
                                {
                                    waterCellArray[index.x, index.y].fActive = true;
                                    activeCellIndexListB.Add(waterCellArray[index.x, index.y].position);
                                }
                            }
                        }
                    }
                }
                //Set this cell to done
                waterCellArray[index.x, index.y].fDone = true;
            }
        }

        //For cells in list B
        foreach (Vector2i index in activeCellIndexListB)
        {
            //Reset flags
            //waterCellArray[index.x, index.y].fActive = false;
            waterCellArray[index.x, index.y].fDone = false;
        }

        //Flip lists, it is done like this to prevent copying references and do a deep copy instead
        //A assigned to temp list
        tempList.AddRange(activeCellIndexListA);
        //B assigned to A
        activeCellIndexListA.Clear();
        activeCellIndexListA.AddRange(activeCellIndexListB);
        //A (tempList) assigned to B
        activeCellIndexListB.Clear();
        activeCellIndexListB.AddRange(tempList);
        //Clear temp list
        tempList.Clear();
    }