Example #1
0
        /// <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);
        }
Example #2
0
            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;
                    }
                }
            }
Example #3
0
            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;
                    }
                }
            }
Example #4
0
        /// <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++;
            }
        }
Example #5
0
 /// <inheritdoc />
 protected override RobotStateCommand addToRobotStateCommand(RobotStateCommand robotStateCommand, BattlefieldRobot r)
 {
     return(robotStateCommand);
 }
Example #6
0
 /// <inheritdoc />
 protected override RobotStateCommand addToRobotStateCommand(RobotStateCommand robotStateCommand, BattlefieldRobot r)
 {
     robotStateCommand.MORE[FlagCapture.POSITION_IN_ROBOT_STATE_COMMAND] = flags.ToArray();
     return(robotStateCommand);
 }
Example #7
0
 public static IObstacle[] GetFromState(RobotStateCommand robotStateCommand)
 {
     return(robotStateCommand.MORE[COMMAND_MORE_OBTACLES_POSITION] as IObstacle[]);
 }
Example #8
0
 public void AddToRobotStateCommand(RobotStateCommand robotStateCommand)
 {
     robotStateCommand.MORE[COMMAND_MORE_OBTACLES_POSITION] = OBTACLES;
 }
Example #9
0
 static ObstaclesAroundRobot()
 {
     COMMAND_MORE_OBTACLES_POSITION = RobotStateCommand.RegisterSubCommandFactory(SUB_COMMAND_FACTORY);
 }
Example #10
0
 static BaseCapture()
 {
     POSITION_IN_ROBOT_STATE_COMMAND = RobotStateCommand.RegisterSubCommandFactory(SUB_COMMAND_FACTORY);
 }
Example #11
0
 public static Base[] GetBases(RobotStateCommand state)
 {
     return((Base[])state.MORE[POSITION_IN_ROBOT_STATE_COMMAND]);
 }
Example #12
0
 static ObstaclesInSight()
 {
     COMMAND_MORE_OBTACLES_POSITION = RobotStateCommand.RegisterSubCommandFactory(subCommandFactory);
 }