/// <summary> /// Return a new cell object, after the player is moved by a direction /// </summary> /// <param name="currentCell">The current cell object, where the player is at</param> /// <param name="direction">The direction that the player want to move (up, down, left, right)</param> /// <returns>Return a new cell</returns> private ICell FindNewCellCoordinates(ICell currentCell, Direction direction) { ICell newCell = (ICell)currentCell.Clone(); switch (direction) { case Direction.Up: newCell.Row -= 1; break; case Direction.Down: newCell.Row += 1; break; case Direction.Left: newCell.Col -= 1; break; case Direction.Right: newCell.Col += 1; break; } return(newCell); }
public ICell PropagateInfection(ICell cell) { if (_germReservoir.TryTake(out IGerm germ)) { return(InfectCell(cell, germ)); } return(cell.Clone()); }
private ICell InfectCell(ICell cell, IGerm germ) { if (_random.NextDouble() <= ChanceToEncounterACell) { PublishCellInfection(); return(germ.InfectCell(cell)); } return(cell.Clone()); }
public void CloneTest() { ICell original = container.Resolve <ICell>(new ParameterOverride("rowIndex", 0), new ParameterOverride("colIndex", 0)); ICell clone = original.Clone(); Assert.AreEqual(original.RowIndex, clone.RowIndex); Assert.AreEqual(original.ColIndex, clone.ColIndex); Assert.AreEqual(original.IsAlive, clone.IsAlive); Assert.AreNotEqual(original, clone); }
/// <summary> /// Поместить новую ячейку в указанную координату /// </summary> /// <param name="c"></param> /// <param name="position"></param> /// <returns></returns> public bool Add(ICell c, Coordinate position) { if (_cells[position.X, position.Y] != null) { return(false); } ICell member = (ICell)c.Clone(); member.Position = position; _cells[position.X, position.Y] = member; return(true); }
public ICell PropagateInfection(ICell cell) { return(cell.Clone()); }
/** * Does the computation */ protected override void SolveRabbitInstance(IGH_DataAccess DA) { List <GH_Point> pointsList = new List <GH_Point>(); DA.GetDataList(1, pointsList); int XDimension = pointsList.Count; IList <Point3d> genericPoints = GH_PointUtils.ConvertToOnPoints(pointsList); //Get the cell prototype------------------------------------------------------------ GH_ObjectWrapper cellPrototypeWrapper = null; DA.GetData <GH_ObjectWrapper>(0, ref cellPrototypeWrapper); ICell cellPrototype = (ICell)cellPrototypeWrapper.Value; //---------------------------------------------------------------------------------- List <GH_ObjectWrapper> stateConfigurations = new List <GH_ObjectWrapper>(); DA.GetDataList(2, stateConfigurations); GH_ObjectWrapper stateConfigWrapper1; OnStateConfig stateConfig = null; foreach (GH_ObjectWrapper stateConfigWrapper in stateConfigurations) { if (stateConfigWrapper != null)// Custom configuration defined { if (stateConfigWrapper.Value.GetType() == typeof(OnStateConfig)) { stateConfig = (OnStateConfig)stateConfigWrapper.Value; //get the user-defined points that define custom Cell State IList <Point3d> userConfigurationGHPoints = stateConfig.GetPoints(); //get the real configuration points, by finding the points that are closer to the user defined configuration points IList <Point3d> realConfigurationPoints = PointUtils.GetClosestPoints(userConfigurationGHPoints, genericPoints); stateConfig.SetPoints(realConfigurationPoints); } } } //---------------------------------------------------------------------------------- //build the grid Grid1d <ICell> space1d = new Grid1d <ICell>(XDimension); CellState ghAliveState = new GH_CellState(new GH_Boolean(true)); CellState ghDeadState = new GH_CellState(new GH_Boolean(false)); //populate the grid for (int i = 0; i < XDimension; i++) { ICell cell = cellPrototype.Clone(); cell.SetId(i);//very important as this identifies the cell if (stateConfig != null) { foreach (Point3d configurationPoint in stateConfig.GetPoints()) { if (pointsList[i].Value.X == configurationPoint.X && pointsList[i].Value.Y == configurationPoint.Y && pointsList[i].Value.Z == configurationPoint.Z) { cell.SetState(stateConfig.GetState()); } } } cell.SetAttachedObject(pointsList[i]); space1d.Add(cell, i); } //build neighborhood for (int i = 0; i < XDimension; i++) { ElementaryCell cell = (ElementaryCell)space1d.GetObjectAt(i); //IList<ICell> neighbors = new List<ICell>(2); if (i > 0) { cell.SetLeftNeighbor((ElementaryCell)space1d.GetObjectAt(i - 1));//neighbors.Add(cells[(i - 1)%XDimension]); } else if (i == 0) { cell.SetLeftNeighbor((ElementaryCell)space1d.GetObjectAt(XDimension - 1));//neighbors.Add(cells[(i - 1)%XDimension]); } if (i < XDimension - 1) { cell.SetRightNeighbor((ElementaryCell)space1d.GetObjectAt(i + 1));//neighbors.Add(cells[(i + 1)%XDimension]); } else if (i == XDimension - 1) { cell.SetRightNeighbor((ElementaryCell)space1d.GetObjectAt(0)); } } CA ca = new CA(space1d); //set the output parameters DA.SetData(0, ca); }
public ICell Clone() { return(wrappedCell.Clone()); }