public void Step() { switch (GetStateAt(CurrentPosition)) { case State.Clean: AffectedNodes.Add(CurrentPosition, State.Weakened); CurrentDirection = (CurrentDirection - 1); if (CurrentDirection < 0) { CurrentDirection = 3; } break; case State.Weakened: TotalInfections++; AffectedNodes[CurrentPosition] = State.Infected; break; case State.Infected: AffectedNodes[CurrentPosition] = State.Flagged; CurrentDirection = (CurrentDirection + 1) % 4; break; case State.Flagged: AffectedNodes.Remove(CurrentPosition); CurrentDirection = (CurrentDirection + 2) % 4; break; default: throw new Exception("Unknown state"); } CurrentPosition = GetNextPosition(); }
private State GetStateAt(Point position) { if (AffectedNodes.ContainsKey(position)) { return(AffectedNodes[position]); } else { return(State.Clean); } }