public void Evaluate(IEnumerable <object> statements) { BeginScope(); foreach (var statement in statements) { if (statement is Branch) { Branch branch = (Branch)statement; var branchCommand = new BranchCommand(branch.Left, branch.Right); branchCommand.Run(this); } else if (statement is EndBranch) { var endBranchCommand = new EndBranchCommand(); endBranchCommand.Run(this); } /* Todo: This breaks the pattern because we can't roll * up these commands into a list before looping through to run them. */ else if (SkipLines) { var doNothingCommand = new DoNothingCommand(); doNothingCommand.Run(this); } else if (statement is CreateVariable) { var createVariable = (CreateVariable)statement; var createVariableCommand = new CreateVariableCommand(createVariable.Name, createVariable.Value); createVariableCommand.Run(this); } else if (statement is Assignment) { var assignment = (Assignment)statement; var assignmentCommand = new AssignmentCommand(assignment.Name, assignment.Value); assignmentCommand.Run(this); } else if (statement is MethodCall) { var methodCall = (MethodCall)statement; var methodCallCommand = new MethodCallCommand("print", methodCall.Arguments); methodCallCommand.Run(this); } } EndScope(); }
private void RaiseRefreshView(bool refreshCollectionView) { DeleteJobCommand.RaiseCanExecuteChanged(); MergeJobsCommand.RaiseCanExecuteChanged(); MergeAllJobsCommand.RaiseCanExecuteChanged(); DoNothingCommand.RaiseCanExecuteChanged(); if (refreshCollectionView) { JobInfos.Refresh(); } }
private void RunBotAndGetNextMove() { if (_totalDoNothingCommands >= 10) { Logger.LogInfo( "Bot is sending to many do nothing commands, in order to save the game the player will plant a bomb and kill itself soon"); } if (_totalDoNothingCommands >= 20) { Logger.LogInfo( "Bot sent to many do nothing commands, something is most likely going wrong, please fix your bot. Your player will now attempt to kill itself to save the game."); } if (_totalDoNothingCommands == 21) { PublishCommand(new TriggerBombCommand()); return; } ICommand command; try { _botRunner.RunBot(); command = _botRunner.GetBotCommand(); } catch (TimeLimitExceededException ex) { Logger.LogException("Bot time limit exceeded ", ex); command = new DoNothingCommand(); } if (command.GetType() == typeof(DoNothingCommand)) { _totalDoNothingCommands++; } else { _totalDoNothingCommands = 0; } if (_totalDoNothingCommands == 20) { PublishCommand(new PlaceBombCommand()); return; } WriteLogs(); PublishCommand(command); }
private void RunBotAndGetNextMove() { if (_totalDoNothingCommands >= 10) { Logger.LogInfo( "Bot is sending to many do nothing commands, if this continues it the bot will be killed off"); } if (_totalDoNothingCommands >= 20) { BotUnresponsive(); Logger.LogInfo( "Bot sent to many do nothing commands, something is most likely going wrong, please fix your bot. The player's ships will all be marked as destroyed and killed off."); BattleshipPlayer.Killoff(); } if (BattleshipPlayer.FailedFirstPhaseCommands == 5) { Logger.LogInfo("Bot has failed to place ships in the last 5 rounds and will be killed off"); BattleshipPlayer.Killoff(); } ICommand command; try { _botRunner.RunBot(); command = _botRunner.GetBotCommand(); } catch (TimeLimitExceededException ex) { Logger.LogException("Bot time limit exceeded ", ex); command = new DoNothingCommand(); } if (command.GetType() == typeof(DoNothingCommand)) { _totalDoNothingCommands++; } else { _totalDoNothingCommands = 0; } WriteLogs(); RemoveCommandFile(true); BotCommandPublished(command); PublishCommand(command); }
private void LoadHotCornerCommands() { for (var i = 0; i < Controller.IntentStore.HotCornerCommands.Length; i++) { var cmd = Controller.IntentStore.HotCornerCommands[i]; if (cmd == null) { cmd = new DoNothingCommand(); Controller.IntentStore.HotCornerCommands[i] = cmd; } _hotCornerRadioBtns[i].Text = cmd.Description(); } _hotCornerRadioBtns[0].Checked = false; _hotCornerRadioBtns[0].Checked = true; }
private ICommand GetRandomCommand(Worm currentActiveWorm) { ICommand command; var random = new Random(); var validCells = GetValidAdjacentCells(currentActiveWorm); if (!validCells.Any()) { return(new DoNothingCommand()); } var randomCell = validCells[random.Next(0, validCells.Length)]; var randomCellPosition = new MapPosition() { X = randomCell.X, Y = randomCell.Y }; switch (randomCell.Type) { case CellType.AIR: command = new MoveCommand() { MapPosition = randomCellPosition }; break; case CellType.DIRT: command = new DigCommand() { MapPosition = randomCellPosition }; break; default: command = new DoNothingCommand(); break; } return(command); }
private void Awake() { Application.targetFrameRate = 30; jumpCommand = new JumpCommand(); moveLeftCommand = new MoveLeftCommand(); moveRightCommand = new MoveRightCommand(); notMoveCommand = new NotMoveCommand(); doNothingCommand = new DoNothingCommand(); transgressionCommand = new TransgressionCommand(); pauseCommand = new PauseCommand(); interactCommand = new InteractCommand(); commands = new Dictionary <string, Command> { { "Jump", jumpCommand }, { "Teleport", transgressionCommand }, { "Use", interactCommand } }; commandsWithoutPlayer = new Dictionary <string, Command> { { "Exit", pauseCommand } }; }
static DoNothingCommand() { Instance = new DoNothingCommand(); }