Ejemplo n.º 1
0
        public void ShouldNotOverrunWest()
        {
            // arrange
            RelationshipsBuilder relationshipsBuilder = new RelationshipsBuilder();
            List <Cell>          cells = new FakeCellsBuilder().SetupCartesianGrid(3, 3);

            // act
            Relationships relationships = relationshipsBuilder.GetCellRelationships(cells, 3, 3);

            // assert
            int indexToCheck = 0;

            relationships.GetNeighbors(cells[indexToCheck]).Should().HaveCount(3);
            relationships.GetNeighbors(cells[indexToCheck]).Any(x => x.IsNeighborOf(cells[1])).Should().BeTrue();
            relationships.GetNeighbors(cells[indexToCheck]).Any(x => x.IsNeighborOf(cells[3])).Should().BeTrue();
        }
Ejemplo n.º 2
0
        public void ShouldReturnRelationshipsForCell()
        {
            Cell cell1 = new LiveCell(Guid.NewGuid());
            Cell cell2 = new LiveCell(Guid.NewGuid());

            Relationships relationships = new Relationships();

            relationships.CreateNewRelationship(cell1, cell2);

            List <Relationship> neighbors = relationships.GetNeighbors(cell1);

            neighbors.Should().HaveCount(1);
        }
Ejemplo n.º 3
0
        public void ShouldPopulateSouthEastNeighbor()
        {
            // arrange
            RelationshipsBuilder relationshipsBuilder = new RelationshipsBuilder();
            List <Cell>          cells = new FakeCellsBuilder().SetupCartesianGrid(3, 3);

            // act
            Relationships relationships = relationshipsBuilder.GetCellRelationships(cells, 3, 3);

            // assert
            int indexToCheck = 4;

            relationships.GetNeighbors(cells[indexToCheck]).Should().HaveCount(8);
            relationships.GetNeighbors(cells[indexToCheck]).Any(x => x.IsNeighborOf(cells[5])).Should().BeTrue();
            relationships.GetNeighbors(cells[indexToCheck]).Any(x => x.IsNeighborOf(cells[3])).Should().BeTrue();
            relationships.GetNeighbors(cells[indexToCheck]).Any(x => x.IsNeighborOf(cells[7])).Should().BeTrue();
            relationships.GetNeighbors(cells[indexToCheck]).Any(x => x.IsNeighborOf(cells[1])).Should().BeTrue();
            relationships.GetNeighbors(cells[indexToCheck]).Any(x => x.IsNeighborOf(cells[2])).Should().BeTrue();
            relationships.GetNeighbors(cells[indexToCheck]).Any(x => x.IsNeighborOf(cells[0])).Should().BeTrue();
            relationships.GetNeighbors(cells[indexToCheck]).Any(x => x.IsNeighborOf(cells[8])).Should().BeTrue();
            relationships.GetNeighbors(cells[indexToCheck]).Any(x => x.IsNeighborOf(cells[6])).Should().BeTrue();
        }
Ejemplo n.º 4
0
        public God(CellsBuilder cellsBuilder, RelationshipsBuilder relationshipsBuilder, IRule rule)
        {
            List <Cell> cells = cellsBuilder.SetupCartesianGrid(3, 3);

            Relationships relationships = relationshipsBuilder.GetCellRelationships(cells, 3, 3);

            List <Cell> nextTurnCells = new List <Cell>();

            foreach (Cell cell in cells)
            {
                relationships.GetNeighbors(cell);
                Cell nextTurnCell = cell.GenerateNextTurnStatus(rule, cells);

                nextTurnCells.Add(nextTurnCell);
                // update relationship?
            }
        }