public void AdvanceGenerationDeadCellWithFourLiveNeighborsShouldRemainDead(IGenerationStrategy strategyUnderTest) { var nextGen = strategyUnderTest.AdvanceGeneration( GenerateLivingTestNeighborhood(this.testCell, coreCellLives: false, liveNeighborCount: 4)); nextGen.Should().NotContain(this.testCell); }
public void AdvanceGenerationLiveCellWithTwoLiveNeighborsShouldSurvive(IGenerationStrategy strategyUnderTest) { var nextGen = strategyUnderTest.AdvanceGeneration( GenerateLivingTestNeighborhood(this.testCell, coreCellLives: true, liveNeighborCount: 2)); nextGen.Should().Contain(this.testCell); }
public void AdvanceGenerationDeadCellWithThreeLiveNeighborsShouldBecomeAlive(IGenerationStrategy strategyUnderTest) { var nextGen = strategyUnderTest.AdvanceGeneration( GenerateLivingTestNeighborhood(this.testCell, coreCellLives: false, liveNeighborCount: 3)); nextGen.Should().Contain(this.testCell); }
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); }
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); }
public Game(IGenerationStrategy generationStrategy) { _difficulty = 3; _allowedStepsBack = MaxStepsBack; _gameStatus = GameStatus.ReadyToStart; _bubbleGenerationStrategy = generationStrategy; _gameLogic = new GameLogic(new Field(10, 10), _bubbleGenerationStrategy, _difficulty); SubscribeGameLogicEvents(); }
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); }
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(); }
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); }
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; }
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; }
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); }
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); }
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); }
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()); } }
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); }
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(); }
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); }
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); }
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(); }
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; }
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); } }
public RandomFunctionGenerator(IGenerationStrategy _strategy) { strategy = _strategy; }
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); }
public void AdvanceGenerationFromNoLivingCellsShouldResultInNoLivingCells(IGenerationStrategy strategyUnderTest) { strategyUnderTest.AdvanceGeneration(new HashSet <Cell>()).Should().BeEmpty(); }
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())); }
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()))); }
public void AdvanceGenerationFromSingleLivingCellShouldResultInNoLivingCellsWhenNoneShouldLive(IGenerationStrategy strategyUnderTest) { var nextGen = strategyUnderTest.AdvanceGeneration(new HashSet <Cell> { new Cell(0, 0) }).Should().BeEmpty(); }