public void GivenCleanExtraProbabilityOf1_Suck_ShouldCleanAdjacentSquare() { // arrange _state.SetAllSquaresDirty(); _state.VacuumPos = new Point2D(1, 1); const double cleanExtraProbability = 1.0; _handler = new ErraticSuckActionHandler(_decoratedHandler, cleanExtraProbability); // act _handler.DoAction(_state, VacuumWorldAction.Suck); // assert var numDirtyNeighbours = _state.AdjacentSquares(_state.VacuumPos).Count(s => _state.SquareIsDirty(s)); Assert.AreEqual(3, numDirtyNeighbours); }
private static IEnumerable <VacuumWorldState> CreateAllStatesWithOneCleanedNeighbour(VacuumWorldState state) { return(state .AdjacentSquares(state.VacuumPos) .Select(square => { var neighbourState = state.Clone(); neighbourState.CleanSquare(square); return neighbourState; })); }
private void CleanRandomDirtyNeighbour(VacuumWorldState state) { var adj = state.AdjacentSquares(state.VacuumPos).Where(state.SquareIsDirty).ToList(); if (adj.Count == 0) { return; } var squareToClean = _random.Choice(adj); state.CleanSquare(squareToClean); }