private void RobotBrain_ActionWanted(object sender, ActionWantedEventArgs e) { DirectionTypes actionDirection = e.Action.Direction; ActionTypes actionType = e.Action.Type; if (_puzzleReferee.CheckAction(_robotBrain.Position, actionDirection, actionType)) { Point direction = PuzzleReferee.ConvertToPoint(actionDirection); Point actionPosition = new Point(_robotBrain.Position.X + direction.X, _robotBrain.Position.Y + direction.Y); int stateChangeCount = 0; switch (actionType) { case ActionTypes.Move: _robotBrain.Position = actionPosition; break; case ActionTypes.MarkAsEmpty: stateChangeCount = _puzzleBoard.SetState(actionPosition, PuzzleCellStateTypes.Empty).Count; break; case ActionTypes.MarkAsFilled: stateChangeCount = _puzzleBoard.SetState(actionPosition, PuzzleCellStateTypes.Filled).Count; break; case ActionTypes.RemoveMarker: stateChangeCount = _puzzleBoard.SetState(actionPosition, PuzzleCellStateTypes.NotMarked).Count; break; } if (_puzzleBoard.IsWrong()) { _robotBrain.ActionFeedback -= 1000; } else if (_puzzleBoard.IsComplete()) { _robotBrain.ActionFeedback += 100; } else if (stateChangeCount > 0) { _robotBrain.ActionFeedback += stateChangeCount; } } if (!_simulationRunsInBackground && _cbxAutoRefreshPlayground.Checked) { RefreshPlayGround(); RecreateCells(); } }