Beispiel #1
0
        public void AdvanceGenerationDeadCellWithFourLiveNeighborsShouldRemainDead(IGenerationStrategy strategyUnderTest)
        {
            var nextGen = strategyUnderTest.AdvanceGeneration(
                GenerateLivingTestNeighborhood(this.testCell, coreCellLives: false, liveNeighborCount: 4));

            nextGen.Should().NotContain(this.testCell);
        }
Beispiel #2
0
        public void AdvanceGenerationLiveCellWithTwoLiveNeighborsShouldSurvive(IGenerationStrategy strategyUnderTest)
        {
            var nextGen = strategyUnderTest.AdvanceGeneration(
                GenerateLivingTestNeighborhood(this.testCell, coreCellLives: true, liveNeighborCount: 2));

            nextGen.Should().Contain(this.testCell);
        }
Beispiel #3
0
        public void AdvanceGenerationDeadCellWithThreeLiveNeighborsShouldBecomeAlive(IGenerationStrategy strategyUnderTest)
        {
            var nextGen = strategyUnderTest.AdvanceGeneration(
                GenerateLivingTestNeighborhood(this.testCell, coreCellLives: false, liveNeighborCount: 3));

            nextGen.Should().Contain(this.testCell);
        }
Beispiel #4
0
    private void PrepareComboBoxes()
    {
        PrepareEditComboBox(
            cmbSelection,
            btnEditSelection,
            SelectionService.GetSelectionNames,
            SelectionService.GetSelectionTypeByName,
            SelectionService.CreateSelectionByName,
            () => m_selection,
            (i) => m_selection = i);

        PrepareEditComboBox(
            cmbCrossover,
            btnEditCrossover,
            CrossoverService.GetCrossoverNames,
            CrossoverService.GetCrossoverTypeByName,
            CrossoverService.CreateCrossoverByName,
            () => m_crossover,
            (i) => m_crossover = i);

        PrepareEditComboBox(
            cmbMutation,
            btnEditMutation,
            MutationService.GetMutationNames,
            MutationService.GetMutationTypeByName,
            MutationService.CreateMutationByName,
            () => m_mutation,
            (i) => m_mutation = i);

        PrepareEditComboBox(
            cmbTermination,
            btnEditTermination,
            () => {
            return(TerminationService.GetTerminationNames()
                   .Where(t => !t.Equals("And", StringComparison.OrdinalIgnoreCase) && !t.Equals("Or", StringComparison.OrdinalIgnoreCase)).ToList());
        },
            TerminationService.GetTerminationTypeByName,
            TerminationService.CreateTerminationByName,
            () => m_termination,
            (i) => m_termination = i);

        PrepareEditComboBox(
            cmbTermination1,
            btnEditReinsertion,
            ReinsertionService.GetReinsertionNames,
            ReinsertionService.GetReinsertionTypeByName,
            ReinsertionService.CreateReinsertionByName,
            () => m_reinsertion,
            (i) => m_reinsertion = i);

        PrepareEditComboBox(
            cmbGenerationStrategy,
            btnEditGenerationStrategy,
            PopulationService.GetGenerationStrategyNames,
            PopulationService.GetGenerationStrategyTypeByName,
            PopulationService.CreateGenerationStrategyByName,
            () => m_generationStrategy,
            (i) => m_generationStrategy = i);
    }
Beispiel #5
0
    private void PrepareComboBoxes()
    {
        PrepareEditComboBox(
            cmbSelection,
            btnEditSelection,
            SelectionService.GetSelectionNames,
            SelectionService.GetSelectionTypeByName,
            SelectionService.CreateSelectionByName,
            () => m_selection,
            (i) => m_selection = i);

        PrepareEditComboBox(
            cmbCrossover,
            btnEditCrossover,
            CrossoverService.GetCrossoverNames,
            CrossoverService.GetCrossoverTypeByName,
            CrossoverService.CreateCrossoverByName,
            () => m_crossover,
            (i) => m_crossover = i);

        PrepareEditComboBox(
            cmbMutation,
            btnEditMutation,
            MutationService.GetMutationNames,
            MutationService.GetMutationTypeByName,
            MutationService.CreateMutationByName,
            () => m_mutation,
            (i) => m_mutation = i);

        PrepareEditComboBox(
            cmbTermination,
            btnEditTermination,
            () =>
        {
            return(TerminationService.GetTerminationNames());
        },
            TerminationService.GetTerminationTypeByName,
            TerminationService.CreateTerminationByName,
            () => m_termination,
            (i) => m_termination = i);

        PrepareEditComboBox(
            cmbReinsertion,
            btnEditReinsertion,
            ReinsertionService.GetReinsertionNames,
            ReinsertionService.GetReinsertionTypeByName,
            ReinsertionService.CreateReinsertionByName,
            () => m_reinsertion,
            (i) => m_reinsertion = i);

        PrepareEditComboBox(
            cmbGenerationStrategy,
            btnEditGenerationStrategy,
            PopulationService.GetGenerationStrategyNames,
            PopulationService.GetGenerationStrategyTypeByName,
            PopulationService.CreateGenerationStrategyByName,
            () => m_generationStrategy,
            (i) => m_generationStrategy = i);
    }
Beispiel #6
0
 public Game(IGenerationStrategy generationStrategy)
 {
     _difficulty               = 3;
     _allowedStepsBack         = MaxStepsBack;
     _gameStatus               = GameStatus.ReadyToStart;
     _bubbleGenerationStrategy = generationStrategy;
     _gameLogic = new GameLogic(new Field(10, 10), _bubbleGenerationStrategy, _difficulty);
     SubscribeGameLogicEvents();
 }
Beispiel #7
0
        public void CreateGenerationStrategyByName_ValidName_GenerationStrategyCreated()
        {
            IGenerationStrategy actual = PopulationService.CreateGenerationStrategyByName("Performance", 1) as PerformanceGenerationStrategy;

            Assert.IsNotNull(actual);

            actual = PopulationService.CreateGenerationStrategyByName("Tracking") as TrackingGenerationStrategy;
            Assert.IsNotNull(actual);
        }
Beispiel #8
0
 public GameLogic(Field field, IGenerationStrategy generationStrategy)
 {
     this._bubbleGenerationStrategy = generationStrategy;
     this.Turn             = 0;
     this.Score            = 0;
     this.Field            = field;
     this.SelectedCell     = null;
     this.Field.EmptyCells = CountEmptyCells();
 }
Beispiel #9
0
        public void AdvanceGenerationBlinkerOscillatorShouldRepeatInTwoGenerations(IGenerationStrategy strategyUnderTest)
        {
            var blinker = new HashSet <Cell> {
                new Cell(0, 1),
                new Cell(1, 1),
                new Cell(2, 1)
            };

            AssertOsscillatorRepeatsInTwoGenerations(blinker, strategyUnderTest);
        }
Beispiel #10
0
 public Game(int fieldheight, int fieldWidth)
 {
     Field       = new Field(fieldheight, fieldWidth);
     _gameStatus = GameStatus.ReadyToStart;
     _bubbleGenerationStrategy = new RandomStrategy();
     _gameLogic = new GameLogic(Field, _bubbleGenerationStrategy);
     _gameLogic.DrawEventHandler         += OnDraw;
     _gameLogic.ScoreChangedEventHandler += OnScoreChange;
     _gameLogic.GameOverEventHandler     += OnGameOver;
     _gameLogic.NextTurnEventHandler     += OnNextTurn;
 }
Beispiel #11
0
 public Game(IGenerationStrategy generationStrategy)
 {
     Field       = new Field(10, 10);
     _gameStatus = GameStatus.ReadyToStart;
     _bubbleGenerationStrategy = generationStrategy;
     _gameLogic = new GameLogic(Field, _bubbleGenerationStrategy);
     _gameLogic.DrawEventHandler         += OnDraw;
     _gameLogic.ScoreChangedEventHandler += OnScoreChange;
     _gameLogic.GameOverEventHandler     += OnGameOver;
     _gameLogic.NextTurnEventHandler     += OnNextTurn;
 }
Beispiel #12
0
 public GameLogic(Field field, IGenerationStrategy generationStrategy, int difficulty)
 {
     this._difficulty = difficulty;
     this.Field       = field;
     this.Field.CountEmptyCells();
     this._bubbleGenerationStrategy = generationStrategy;
     this._findPath       = new FindPath();
     this.Turn            = 0;
     this.Score           = 0;
     this.SelectedCell    = null;
     this._linesDestroyer = new LinesDestroyer(Field);
 }
Beispiel #13
0
        public void AdvanceGenerationToadOscillatorShouldRepeatInTwoGenerations(IGenerationStrategy strategyUnderTest)
        {
            var toad = new HashSet <Cell> {
                new Cell(1, 1),
                new Cell(1, 2),
                new Cell(1, 3),
                new Cell(2, 0),
                new Cell(2, 1),
                new Cell(2, 2)
            };

            AssertOsscillatorRepeatsInTwoGenerations(toad, strategyUnderTest);
        }
Beispiel #14
0
        public void AdvanceGenerationTubStillLifeShouldRemainUnchanged(IGenerationStrategy strategyUnderTest)
        {
            var tub = new HashSet <Cell> {
                new Cell(0, 1),
                new Cell(1, 0),
                new Cell(1, 2),
                new Cell(2, 1)
            };

            var nextGen = strategyUnderTest.AdvanceGeneration(tub);

            nextGen.Should().BeEquivalentTo(tub);
        }
Beispiel #15
0
        public string Generation(IGenerationStrategy strategy)
        {
            if (strategy == null)
            {
                throw new ArgumentNullException("strategy");
            }
            var instructions = CreateInstructionSet();

            using (var builder = strategy.GenerationProc(_method, instructions))
            {
                return(builder.ToString());
            }
        }
Beispiel #16
0
        public void AdvanceGenerationBlockStillLifeShouldRemainUnchanged(IGenerationStrategy strategyUnderTest)
        {
            var block = new HashSet <Cell> {
                new Cell(0, 0),
                new Cell(0, 1),
                new Cell(1, 0),
                new Cell(1, 1)
            };

            var nextGen = strategyUnderTest.AdvanceGeneration(block);

            nextGen.Should().BeEquivalentTo(block);
        }
Beispiel #17
0
        public GameOfLife()
        {
            InitializeComponent();

            this.scaleFactor           = DefaultCellScale;
            this.cellScaleTextBox.Text = DefaultCellScale.ToString();

            this.generationDelayMs           = DefaultGenerationDelayMs;
            this.generationDelayTextBox.Text = DefaultGenerationDelayMs.ToString();

            this.gameStrategy = new ImmediateEvaluationForAllCellsWithAliveNeighborsGenerationStrategy();
            this.cellParser   = new TupleFormatCellParser();
        }
Beispiel #18
0
        public void AdvanceGenerationBeaconOscillatorShouldRepeatInTwoGenerations(IGenerationStrategy strategyUnderTest)
        {
            var beacon = new HashSet <Cell> {
                new Cell(0, 0),
                new Cell(0, 1),
                new Cell(1, 0),
                new Cell(1, 1),
                new Cell(2, 2),
                new Cell(2, 3),
                new Cell(3, 2),
                new Cell(3, 3)
            };

            AssertOsscillatorRepeatsInTwoGenerations(beacon, strategyUnderTest);
        }
Beispiel #19
0
        public void AdvanceGenerationBeehiveStillLifeShouldRemainUnchanged(IGenerationStrategy strategyUnderTest)
        {
            var beehive = new HashSet <Cell> {
                new Cell(0, 1),
                new Cell(0, 2),
                new Cell(1, 0),
                new Cell(1, 3),
                new Cell(2, 1),
                new Cell(2, 2)
            };

            var nextGen = strategyUnderTest.AdvanceGeneration(beehive);

            nextGen.Should().BeEquivalentTo(beehive);
        }
Beispiel #20
0
        public Game(int fieldheight, int fieldWidth, int difficulty)
        {
            #region Validation
            if ((difficulty > 5) || (difficulty < 3))
            {
                throw new InvalidOperationException("Difficulty must be between 3 and 5");
            }
            #endregion

            _difficulty               = difficulty;
            _allowedStepsBack         = MaxStepsBack;
            _gameStatus               = GameStatus.ReadyToStart;
            _bubbleGenerationStrategy = new RandomStrategy();
            _gameLogic = new GameLogic(new Field(fieldheight, fieldWidth), _bubbleGenerationStrategy, _difficulty);
            SubscribeGameLogicEvents();
        }
Beispiel #21
0
 public ReflectionGeneratorBase(IReflectedNamingStrategy naming, IGenerationStrategy generation)
 {
     _typeMap = new Dictionary <Type, TypescriptTypeBase>()
     {
         { typeof(void), PrimitiveType.Void },
         { typeof(object), PrimitiveType.Any },
         { typeof(int), PrimitiveType.Number },
         { typeof(decimal), PrimitiveType.Number },
         { typeof(double), PrimitiveType.Number },
         { typeof(float), PrimitiveType.Number },
         { typeof(string), PrimitiveType.String },
         { typeof(bool), PrimitiveType.Boolean },
         { typeof(DateTime), PrimitiveType.Date },
     };
     NamingStrategy     = naming;
     GenerationStrategy = generation;
 }
Beispiel #22
0
        private static void ForPrimitive <T>(object valueByDefault, PropertyInfo property, T model)
        {
            var text = new IGenerationStrategy[]
            {
                new DateGenerationStrategy(),
                new EmailGenerationStrategy(),
                new NumberGenerationStrategy(),
                new GenerationStrategy()
            }.FirstOrDefault(x => x.IsValid(property))
            ?.GetValue(property);

            text = ProcessMacros(valueByDefault?.ToString(), text);

            if (text != null)
            {
                property.SetValue(model, text);
            }
        }
Beispiel #23
0
 public RandomFunctionGenerator(IGenerationStrategy _strategy)
 {
     strategy = _strategy;
 }
Beispiel #24
0
        private static void AssertOsscillatorRepeatsInTwoGenerations(HashSet <Cell> initialState, IGenerationStrategy strategyUnderTest)
        {
            var gen1 = strategyUnderTest.AdvanceGeneration(initialState);

            gen1.Should().NotBeEquivalentTo(initialState);

            var gen2 = strategyUnderTest.AdvanceGeneration(gen1);

            gen2.Should().BeEquivalentTo(initialState);
        }
Beispiel #25
0
 public void AdvanceGenerationFromNoLivingCellsShouldResultInNoLivingCells(IGenerationStrategy strategyUnderTest)
 {
     strategyUnderTest.AdvanceGeneration(new HashSet <Cell>()).Should().BeEmpty();
 }
Beispiel #26
0
        public void AdvanceGenerationFromTwoLiveCellsWithOverlappingNeighborhoodsShouldIncludeAllNeighborsWithoutDuplicates(IGenerationStrategy strategyUnderTest)
        {
            MockGameRules.Setup(x => x.ShouldCellLive(It.IsAny <bool>(), It.IsAny <int>())).Returns(true);

            // Neighbors in column 2 overlap
            var cell1 = new Cell(1, 1);
            var cell2 = new Cell(1, 3);

            var nextGen = strategyUnderTest.AdvanceGeneration(new HashSet <Cell> {
                cell1, cell2
            });

            nextGen.Should().BeEquivalentTo(cell1.FindValidNeighbors().Union(cell2.FindValidNeighbors()));
        }
Beispiel #27
0
        public void AdvanceGenerationFromTwoLiveCellsWithDisparateNeighborhoodsShouldIncludeAllNeighbors(IGenerationStrategy strategyUnderTest)
        {
            MockGameRules.Setup(x => x.ShouldCellLive(It.IsAny <bool>(), It.IsAny <int>())).Returns(true);

            // Not adjacent
            var cell1 = new Cell(10, 20);
            var cell2 = new Cell(50, 70);

            var nextGen = strategyUnderTest.AdvanceGeneration(new HashSet <Cell> {
                cell1, cell2
            });

            nextGen.Should().BeEquivalentTo(new HashSet <Cell>(cell1.FindValidNeighbors().Union(cell2.FindValidNeighbors())));
        }
Beispiel #28
0
 public void AdvanceGenerationFromSingleLivingCellShouldResultInNoLivingCellsWhenNoneShouldLive(IGenerationStrategy strategyUnderTest)
 {
     var nextGen = strategyUnderTest.AdvanceGeneration(new HashSet <Cell> {
         new Cell(0, 0)
     }).Should().BeEmpty();
 }