public List <Point> Undo() { List <Point> result = new List <Point>(); if (_history.Count > 0) { List <Tuple <Point, PuzzleCellStateTypes> > states = _history[_history.Count - 1]; List <Tuple <Point, PuzzleCellStateTypes> > redoStates = new List <Tuple <Point, PuzzleCellStateTypes> >(); foreach (Tuple <Point, PuzzleCellStateTypes> item in states) { Point pos = item.Item1; PuzzleCellStateTypes state = item.Item2; if (pos.X < 0 || pos.X >= Columns || pos.Y < 0 || pos.Y >= Rows) { continue; } PuzzleCellStateTypes actualState = _playGround[pos.X, pos.Y].State; if (actualState != state) { redoStates.Add(new Tuple <Point, PuzzleCellStateTypes>(pos, actualState)); } } if (redoStates.Count > 0) { _redos.Add(redoStates); } result.AddRange(SetStates(states, false, false)); _history.RemoveAt(_history.Count - 1); } return(result); }
public List <Point> SetState(Point pos, PuzzleCellStateTypes state) { return(SetStates(new List <Tuple <Point, PuzzleCellStateTypes> >() { new Tuple <Point, PuzzleCellStateTypes>(pos, state) })); }
public void Experience(FieldOfVisionTypes fieldOfVisionType, PuzzleBoard partialBoard) { Point centerPos = new Point(); switch (fieldOfVisionType) { case FieldOfVisionTypes.Single: centerPos = new Point(0, 0); break; case FieldOfVisionTypes.ThreeByThree: centerPos = new Point(1, 1); break; case FieldOfVisionTypes.FiveByFive: centerPos = new Point(2, 2); break; } List <ISensoryPattern> sensoryPatterns = new List <ISensoryPattern>(); for (int y = 0; y < partialBoard.Rows; y++) { for (int x = 0; x < partialBoard.Columns; x++) { Point pos = new Point(x, y); DirectionTypes directionType = PuzzleReferee.ConvertToDirectionType(new Point(pos.X - centerPos.X, pos.Y - centerPos.Y)); PuzzleCellStateTypes state = partialBoard.GetState(pos); int value = partialBoard.GetValue(pos); string valueString = value >= 0 ? value.ToString() : " "; if (state != PuzzleCellStateTypes.Undefined) { ISensoryUnit sensoryUnitState = GetOrCreateSensoryUnit(SensoryTypes.FieldState, state.ToString()); ISensoryUnit sensoryUnitValue = GetOrCreateSensoryUnit(SensoryTypes.FieldValue, valueString); List <ISensoryUnit> sensoryUnits = new List <ISensoryUnit>(); sensoryUnits.Add(sensoryUnitState); sensoryUnits.Add(sensoryUnitValue); ISensoryPattern sensoryPattern = new SensoryPattern(directionType, sensoryUnits); if (_kownSensoryPatterns.Contains(sensoryPattern)) { sensoryPattern = _kownSensoryPatterns[_kownSensoryPatterns.IndexOf(sensoryPattern)]; } else { _kownSensoryPatterns.Add(sensoryPattern); _kownSensoryPatterns.Sort(); } sensoryPatterns.Add(sensoryPattern); } } } _lastSensationSnapshot = new SensationSnapshot(DirectionTypes.Center, fieldOfVisionType, sensoryPatterns, IS_SAVEABLE_SNAPSHOT); }
private void SetValueAndState(Point position, Point distancePoint, PuzzleBoard patialBoard) { int width = patialBoard.Columns; int height = patialBoard.Rows; Point centerPos = new Point((width - 1) / 2, (height - 1) / 2); Point nextPosition = new Point(position.X + distancePoint.X, position.Y + distancePoint.Y); Point partialPos = new Point(centerPos.X + distancePoint.X, centerPos.Y + distancePoint.Y); int number = _puzzleBoard.GetValue(nextPosition); PuzzleCellStateTypes state = _puzzleBoard.GetState(nextPosition); patialBoard.SetValue(partialPos, number); patialBoard.SetState(partialPos, state); }
public void TriggerNextState(Point pos) { if (pos.X < 0 || pos.X >= Columns || pos.Y < 0 || pos.Y >= Rows) { return; } PuzzleCellStateTypes state = _playGround[pos.X, pos.Y].State; switch (state) { case PuzzleCellStateTypes.NotMarked: SetState(pos, PuzzleCellStateTypes.Filled); break; case PuzzleCellStateTypes.Filled: SetState(pos, PuzzleCellStateTypes.Empty); break; case PuzzleCellStateTypes.Empty: SetState(pos, PuzzleCellStateTypes.NotMarked); break; } }
private void DoStateAction(PuzzleCellStateTypes markerState) { if (_cbxDirectionTypes.SelectedIndex < 0) { return; } DirectionTypes directionType = (DirectionTypes)_cbxDirectionTypes.SelectedItem; Point direction = PuzzleReferee.ConvertToPoint(directionType); Point markerPosition = new Point(_robotBrain.Position.X + direction.X, _robotBrain.Position.Y + direction.Y); _puzzleBoard.SetState(markerPosition, markerState); if (_cbxAutoRefreshPlayground.Checked) { RefreshPlayGround(); RecreateCells(); } }
public List <Point> SetStates(List <Tuple <Point, PuzzleCellStateTypes> > states, bool useUndo = true, bool clearAllRedos = true) { List <Point> result = new List <Point>(); List <Tuple <Point, PuzzleCellStateTypes> > historyStates = new List <Tuple <Point, PuzzleCellStateTypes> >(); foreach (Tuple <Point, PuzzleCellStateTypes> item in states) { Point pos = item.Item1; PuzzleCellStateTypes state = item.Item2; if (pos.X < 0 || pos.X >= Columns || pos.Y < 0 || pos.Y >= Rows) { continue; } PuzzleCellStateTypes actualState = _playGround[pos.X, pos.Y].State; if (actualState != state) { historyStates.Add(new Tuple <Point, PuzzleCellStateTypes>(pos, actualState)); _playGround[pos.X, pos.Y].State = state; if (actualState == PuzzleCellStateTypes.NotMarked) { _notMarkedCellsCount--; } else if (state == PuzzleCellStateTypes.NotMarked) { _notMarkedCellsCount++; } result.Add(pos); } } if (useUndo && historyStates.Count > 0) { _history.Add(historyStates); } if (clearAllRedos) { _redos.Clear(); } return(result); }