示例#1
0
 public void GetCellAtShouldOnlyReturnLivingCellsWhenSet()
 {
     var world = new World();
     world.SetLiveCellAt(new Location(99, 99));
     Assert.IsInstanceOfType(typeof(DeadCell), world.GetCellAt(new Location(1, 1)));
     Assert.IsInstanceOfType(typeof(AliveCell), world.GetCellAt(new Location(99, 99)));
 }
示例#2
0
 public void GivenIHaveAToad()
 {
     World world = new World(9, 9);
     ScenarioContext.Current["world"] = world;
     world.AddCells(new Cell(4, 4), new Cell(5, 4), new Cell(6, 4));
     world.AddCells(new Cell(3, 5), new Cell(4, 5), new Cell(5, 5));
 }
示例#3
0
        public GamePanel(World world, int cellPadding, bool parallel)
        {         
            int cellSize = 2 * cellPadding;
            int width = world.Width * cellSize;
            int height = world.Height * cellSize;
            bmp = new Bitmap(width, height);
            Size = bmp.Size;
            

            Timer timer = new Timer();
            timer.Interval = 1;

            timer.Tick += delegate(Object sender, EventArgs e)
            {
                if (parallel)
                {
                    world.ParallelTransition();
                }
                else
                {
                    world.SequentialTransition();
                }

                world.ImageDraw(Graphics.FromImage(bmp), cellSize);
                Refresh();

                
            };

            timer.Start();
        }
示例#4
0
        public void World_Dimension4x5_return4x5()
        {
            World world = new World(new Dimension(4,5));

            Assert.AreEqual(world.Width, 4);
            Assert.AreEqual(world.Height, 5);
        }
 public void TestWorldSize()
 {
     // object[,] cellArray = new object[12, 12];
     World genesis = new World();
     Assert.AreEqual(12, genesis.Length);
     Assert.AreEqual(12, genesis.Width);
 }
        static void Main(string[] args)
        {
            World myWorld = new World(20);
            //myWorld.RamdomlySeedTheWorld();
            //myWorld.SeedWithBlinkers();
            //myWorld.SeedWithToad();
            myWorld.SeedWithGlider();
            //myWorld.SeedWithFourLevelPyramid();
            myWorld.SeedWithSquare(2, 2, 10);

            myWorld.DisplayWorld();
            Console.WriteLine(" -- SEED--");
            Console.ReadLine();

            for (int i = 0; i < 60; i++)
            {
                myWorld.ApplyTheRulesOfTheGame();
                myWorld.DisplayWorld();
                Console.WriteLine("Generation {0}", i + 1);
                //Console.ReadLine();
                System.Threading.Thread.Sleep(750);
            }

            Console.ReadLine();
        }
示例#7
0
 public void CellWithOneNeighbourDiesAfterATick()
 {
     var world = new World();
     world.SetLiveCellAt(new Location(1, 1));
     world.SetLiveCellAt(new Location(1, 2));
     World nextWorld = world.Tick();
     Assert.IsInstanceOfType(typeof(DeadCell), nextWorld.GetCellAt(new Location(1, 2)));
 }
 public void World_is_initialized_with_dead_cells()
 {
     World world = new World(Height, Width);
     foreach (Coordinate coordinate in world)
     {
         Assert.IsFalse(world.GetCell(coordinate).IsAlive());
     }
 }
 public void Corner_cells_can_be_set()
 {
     World world = new World(Height, Width);
     world.SetCell(world.GetCoordinate(0, 0), Cell.Alive);
     world.SetCell(world.GetCoordinate(0, Width - 1), Cell.Alive);
     world.SetCell(world.GetCoordinate(Height - 1, Width - 1), Cell.Alive);
     world.SetCell(world.GetCoordinate(Height - 1, 0), Cell.Alive);
 }
 public void Evolve_generates_a_new_world_with_the_same_dimensions()
 {
     World world = new World(4, 7);
     World evolved = _worldEvolver.Evolve(world);
     Assert.AreNotSame(world, evolved);
     Assert.AreEqual(world.Height, evolved.Height);
     Assert.AreEqual(world.Width, evolved.Width);
 }
示例#11
0
 public void OneAliveCellShouldDieAfterATick()
 {
     var world = new World();
     world.SetLiveCellAt(new Location(1,1));
     Assert.IsAssignableFrom(typeof(AliveCell), world.GetCellAt(new Location(1, 1)), "before tick");
     World nextWorld = world.Tick();
     Assert.IsInstanceOfType(typeof(DeadCell), nextWorld.GetCellAt(new Location(1, 1)), "after tick");
 }
示例#12
0
文件: Program.cs 项目: vonwenm/Jibu
        static void Main()
        {
            // The size of the world
            int columns = 150;
            int rows = 150;

            // Each cell will have width and length = 2 * cellPadding 
            int cellPadding = 2;

            // The number of LifeForms to begin with
            int numLifeForms = 100;

            // Set this to false to run the 
            // game sequentially.
            // If the game is run on a computer
            // with multiple cores, then the
            // speed difference should obvious.
            bool parallel = true;

            LifeForm[] lifeForms = new LifeForm[numLifeForms];
            Random rand = new Random();

            // Generate some life forms that
            // will be placed randomly
            for (int i = 0; i < numLifeForms; i++)
            {
                int x = rand.Next(columns);
                int y = rand.Next(rows);

                if (i < numLifeForms / 3)
                    lifeForms[i] = LifeForm.CreateGlider(x, y);
                else if (i < numLifeForms / 2)
                    lifeForms[i] = LifeForm.CreatePulsar(x, y);
                else
                    lifeForms[i] = LifeForm.CreateLightweightSpaceship(x, y);

            }

            World w = new World(columns, rows);
            w.AddLifeForms(lifeForms);

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new GameOfLife(new GamePanel(w, cellPadding,parallel)));



            // For a text-based version uncomment the loop below.
            /* 
             
            for (int i = 0; i < 10; i++)
            {
                w.ParallelTransition();
                w.ConsoleDraw();
            }
             */

        }
示例#13
0
        public void GameDisplay_setNull_get0x0()
        {
            GameDisplay display = new GameDisplay();
            World world = new World(null);
            display.SetWorld(world);

            Assert.AreEqual(display.Width, 0);
            Assert.AreEqual(display.Height, 0);
        }
示例#14
0
 public void Cell_can_be_retrieved_as_set()
 {
     World world = new World(Height, Width);
     const int row = 2;
     const int column = 2;
     Coordinate coordinate = world.GetCoordinate(row, column);
     world.SetCell(coordinate, Cell.Alive);
     Assert.IsTrue(world.GetCell(coordinate).IsAlive());
 }
示例#15
0
 public void DeadCellWithExactlyThreeLivingNeighboursBecomesALiveCellAfterATick()
 {
     var world = new World();
     world.SetLiveCellAt(new Location(1, 0));   //  -x-
     world.SetLiveCellAt(new Location(0, 1));   //  xo-
     world.SetLiveCellAt(new Location(1, 2));   //  -x-
     World nextWorld = world.Tick();
     Assert.IsInstanceOfType(typeof(AliveCell), nextWorld.GetCellAt(new Location(1, 1)));
 }
示例#16
0
 public void CellWithTwoNeighboursShouldLiveOnAfterNextTick()
 {
     var world = new World();
     world.SetLiveCellAt(new Location(1, 1));
     world.SetLiveCellAt(new Location(1, 2));
     world.SetLiveCellAt(new Location(2, 1));
     World nextWorld = world.Tick();
     Assert.IsInstanceOfType(typeof(AliveCell), nextWorld.GetCellAt(new Location(1, 1)));
 }
示例#17
0
 public void Initialize()
 {
     WorldCoordinateFactoryInterface coordinateFactory = createCoordinateFactoryThatCanGenerateMockCoordinates();
     worldStateMock = new Mock<WorldStateInterface>();
     worldState = worldStateMock.Object;
     testWorld = new World(coordinateFactory, worldState);
     testCell = testCellMock.Object;
     worldCoordinates = testWorld.getAvailableWorldCoordinates();
 }
示例#18
0
        public void AThreeCellWorldInARow_SimulationRunOnce_AThreeCellWorldInAColumnIsTheResult()
        {
            var expected = new HashSet<Cell>() { new Cell(0, 1), new Cell(0, 0), new Cell(0, -1) };

            var world = new World(new[] { new Cell(-1, 0), new Cell(0, 0), new Cell(1, 0) });
            var actual = world.Tick();

            Is.EquivalentTo(expected).Matches(actual);
        }
示例#19
0
        public void GameDisplay_setDimension4x5_get4x5()
        {
            GameDisplay display = new GameDisplay();
            World world = new World(new Dimension(4, 5));
            display.SetWorld(world);

            Assert.AreEqual(display.Width, 4);
            Assert.AreEqual(display.Height, 5);
        }
示例#20
0
        public void ASingleCellWorld_SimulationRunOnce_AnEmptyWorldIsTheResult()
        {
            var expected = new HashSet<Cell>();

            var world = new World(new[] { new Cell(0, 0), });
            var actual = world.Tick();

            Assert.AreEqual(expected, actual);
        }
示例#21
0
 public void GivenIHaveAnEmptyCellWith3AdjacentCells(int numberOfAdjacentCells)
 {
     World world = new World(9, 9);
     ScenarioContext.Current["world"] = world;
     switch (numberOfAdjacentCells)
     {
         case 3:
             world.AddCells(new Cell(4, 4), new Cell(4, 6), new Cell(3, 5));
             break;
     }
 }
示例#22
0
 public void ToString_returns_a_grid_representing_the_world()
 {
     World world = new World(3, 3);
     Assert.AreEqual("- - -\r\n- - -\r\n- - -", world.ToString());
     world.SetCell(world.GetCoordinate(0, 0), Cell.Alive);
     world.SetCell(world.GetCoordinate(2, 0), Cell.Alive);
     world.SetCell(world.GetCoordinate(1, 1), Cell.Alive);
     world.SetCell(world.GetCoordinate(0, 2), Cell.Alive);
     world.SetCell(world.GetCoordinate(2, 2), Cell.Alive);
     Assert.AreEqual("O - O\r\n- O -\r\nO - O", world.ToString());
 }
 public void Evolve_calls_ICellEvolver_for_each_cell()
 {
     World world = new World(3, 3);
     int[] callbackCount = new[] {0};
     _cellEvolverMock
         .Setup(x => x.Evolve(It.IsAny<Cell>(), It.IsAny<Cell[]>()))
         .Returns(Cell.Alive)
         .Callback(() => callbackCount[0]++)
         .Verifiable();
     _worldEvolver.Evolve(world);
     Assert.AreEqual(9, callbackCount[0]);
 }
示例#24
0
 public void NextTurn1()
 {
     Cell[] cells = {
         new Cell(0, 0),
         new Cell(1, 1),
         new Cell(0, 2)
     };
     World nextMove = new World(cells).NextMove();
     Assert.IsTrue(nextMove.Cells.Length == 2);
     Assert.IsTrue(nextMove.Cells.Any(t => t.X == 0 && t.Y == 1));
     Assert.IsTrue(nextMove.Cells.Any(t => t.X == 1 && t.Y == 1));
 }
 public void Blinker_test()
 {
     WorldEvolver worldEvolver = new WorldEvolver(new B3S23CellEvolver());
     const string blinkerInit = "- - -\r\nO O O\r\n- - -";
     World world = new World(blinkerInit);
     Console.Out.WriteLine(world);
     Console.Out.WriteLine("");
     world = worldEvolver.Evolve(world);
     Console.Out.WriteLine(world);
     Console.Out.WriteLine("");
     world = worldEvolver.Evolve(world);
     Console.Out.WriteLine(world);
 }
        public void WorldAssureYouCanPlaceCell()
        {
            /* arrange */
            World test_world = new World();
            /* end arrange */

            /* act */
            /* end act */

            /* assert */

            /* end assert */
        }
示例#27
0
        public void World_no_neighbor_around_1x1_then_dead()
        {
            World world = new World(new Dimension(3, 3));
            LiveCell[] cells = new LiveCell[1] {
                new LiveCell(1, 1)
            };
            world.SetLiveCells(cells);

            world.Advance();

            cells = world.GetLiveCells();
            Assert.AreEqual(0,cells.Length);
        }
        public void WorldAssureWorldCanInstance()
        {
            /* arrange */
            World test_world = new World();
            /* end arrange */

            /* act */
            var actual = test_world.BuildWorldSize();
            /* end act */

            /* assert */
            Assert.AreEqual(actual, 10);
            /* end assert */
        }
示例#29
0
        public void World_3_neighbors_around_dead_0x0_then_live()
        {
            World world = new World(new Dimension(3, 3));
            LiveCell[] cells = new LiveCell[3] {
                new LiveCell(0, 1),
                new LiveCell(1, 0),
                new LiveCell(1, 1)
            };
            world.SetLiveCells(cells);

            world.Advance();

            Assert.AreEqual(true, HasCell(world, 0, 0));
        }
示例#30
0
        private void GameView_Load(object sender, EventArgs e)
        {
            int startW = 90;
            int startH = 60;

            var world1 = new World(startW, startH);
            world1.Random();

            var world2 = new World(startW, startH);

            processor = new Processor(world1, world2);
            ticker.Start();
            Refresh();
        }