/// <summary> /// Set robot name and team name and send it to server asynchronously. /// </summary> /// <param name="name"> name of this robot</param> /// <param name="teamName">name of team (suggest to use <code>Guid.NewGuid().ToString();</code> for getting name</param> /// <returns></returns> private async Task <InitAnswerCommand> InitAsync(String name, String teamName) { await sendCommandAsync(new InitCommand(name, teamName, GetRobotType())); InitAnswerCommand answerCommand = (InitAnswerCommand)checkCommand(await sns.ReceiveCommandAsync()); ProcessInit(answerCommand); RobotStateCommand robotState = (RobotStateCommand)checkCommand(await sns.ReceiveCommandAsync()); ProcessState(robotState); return(answerCommand); }
protected override void ProcessState(RobotStateCommand state) { base.ProcessState(state); Flag[] flags = FlagCapture.GetFlags(state); carryFlag = false; foreach (var flag in flags) { if (flag.RobotId == this.ID) { carryFlag = true; } } }
protected override void ProcessState(RobotStateCommand state) { base.ProcessState(state); bases = BaseCapture.GetBases(state); foreach (var @base in bases) { if (@base.TeamId != mineLayer.TEAM_ID) { capturedBase = @base; break; } } }
/// <summary> /// Set x,y coordinates, hit points and power. Set score and gold and call <code>sendMerchant</code> if is end of lap /// </summary> /// <seealso cref="SendMerchant"/> /// <param name="state"></param> protected virtual void ProcessState(RobotStateCommand state) { this.X = state.X; this.Y = state.Y; this.HitPoints = state.HIT_POINTS; this.Power = state.POWER; this.TURN = state.TURN; if (state.END_LAP_COMMAND != null) { Gold = state.END_LAP_COMMAND.GOLD; Score = state.END_LAP_COMMAND.SCORE; if (LAP == MAX_LAP) { Console.WriteLine("Match finish."); Environment.Exit(0); } SendMerchant(); LAP++; } }
/// <inheritdoc /> protected override RobotStateCommand addToRobotStateCommand(RobotStateCommand robotStateCommand, BattlefieldRobot r) { return(robotStateCommand); }
/// <inheritdoc /> protected override RobotStateCommand addToRobotStateCommand(RobotStateCommand robotStateCommand, BattlefieldRobot r) { robotStateCommand.MORE[FlagCapture.POSITION_IN_ROBOT_STATE_COMMAND] = flags.ToArray(); return(robotStateCommand); }
public static IObstacle[] GetFromState(RobotStateCommand robotStateCommand) { return(robotStateCommand.MORE[COMMAND_MORE_OBTACLES_POSITION] as IObstacle[]); }
public void AddToRobotStateCommand(RobotStateCommand robotStateCommand) { robotStateCommand.MORE[COMMAND_MORE_OBTACLES_POSITION] = OBTACLES; }
static ObstaclesAroundRobot() { COMMAND_MORE_OBTACLES_POSITION = RobotStateCommand.RegisterSubCommandFactory(SUB_COMMAND_FACTORY); }
static BaseCapture() { POSITION_IN_ROBOT_STATE_COMMAND = RobotStateCommand.RegisterSubCommandFactory(SUB_COMMAND_FACTORY); }
public static Base[] GetBases(RobotStateCommand state) { return((Base[])state.MORE[POSITION_IN_ROBOT_STATE_COMMAND]); }
static ObstaclesInSight() { COMMAND_MORE_OBTACLES_POSITION = RobotStateCommand.RegisterSubCommandFactory(subCommandFactory); }