Example #1
0
 private void matchMessage(Looter looter, Match match)
 {
     looter.message = match.Groups["message"].Value;
     if (looter.message != null && looter.message.Length > 19)
     {
         looter.message = looter.message.Substring(0, 17) + "...";
     }
 }
Example #2
0
        public SkillEffect(int type, double x, double y, double radius, int duration, int order, Looter looter) :
            base(x, y)
        {
            id = Referee.GLOBAL_ID++;

            this.type     = type;
            this.radius   = radius;
            this.duration = duration;
            this.looter   = looter;
            this.order    = order;
        }
Example #3
0
        public void handlePlayerOutput(int frame, int round, int playerIdx, String[] outputs)
        {
            Player player   = players[playerIdx];
            String expected = EXPECTED;

            for (int i = 0; i < LOOTER_COUNT; ++i)
            {
                String line = outputs[i];
                Match  match;
                try {
                    Looter looter = players[playerIdx].looters[i];

                    match = PLAYER_WAIT_PATTERN.Match(line);
                    if (match.Success)
                    {
                        looter.attempt = Action.WAIT;
                        matchMessage(looter, match);
                        continue;
                    }

                    match = PLAYER_MOVE_PATTERN.Match(line);
                    if (match.Success)
                    {
                        looter.attempt = Action.MOVE;
                        int x     = Int32.Parse(match.Groups["x"].Value);
                        int y     = Int32.Parse(match.Groups["y"].Value);
                        int power = Int32.Parse(match.Groups["power"].Value);

                        looter.setWantedThrust(new Point(x, y), power);
                        matchMessage(looter, match);
                        continue;
                    }

                    match = PLAYER_SKILL_PATTERN.Match(line);
                    if (match.Success)
                    {
                        if (!looter.skillActive)
                        {
                            // Don't kill the player for that. Just do a WAIT instead
                            looter.attempt = Action.WAIT;
                            matchMessage(looter, match);
                            continue;
                        }

                        looter.attempt = Action.SKILL;
                        int x = Int32.Parse(match.Groups["x"].Value);
                        int y = Int32.Parse(match.Groups["y"].Value);

                        SkillResult result = new SkillResult(x, y);
                        looter.skillResult = result;

                        try {
                            SkillEffect effect = looter.skill(new Point(x, y));
                            skillEffects.Add(effect);
                        } catch (NoRageException /*e*/) {
                            result.code = SkillResult.NO_RAGE;
                        } catch (TooFarException /*e*/) {
                            result.code = SkillResult.TOO_FAR;
                        }
                        matchMessage(looter, match);
                        continue;
                    }

                    throw new InvalidInputException(expected, line);
                } catch (InvalidInputException e) {
                    player.Kill();
                    throw e;
                } catch (Exception e) {
                    //StringWriter errors = new StringWriter();
                    //e.printStackTrace(new PrintWriter(errors));
                    //printError(e.getMessage() + "\n" + errors.toString());
                    System.Diagnostics.Debug.WriteLine(e);
                    player.Kill();
                    throw new InvalidInputException(expected, line);
                }
            }
        }
Example #4
0
        public void initReferee(int playerCount, Properties prop)
        {
            this.playerCount = playerCount;

            if (int.TryParse(prop.getProperty("seed", DateTime.Now.Millisecond.ToString()), out this.seed) == false)
            {
                this.seed = DateTime.Now.Millisecond;
            }

            Random random = new Random(this.seed);


            TANKERS_BY_PLAYER = TANKERS_BY_PLAYER_MIN + random.Next(TANKERS_BY_PLAYER_MAX - TANKERS_BY_PLAYER_MIN + 1);

            units       = new List <Unit>();
            looters     = new List <Looter>();
            tankers     = new List <Tanker>();
            deadTankers = new List <Tanker>();
            wrecks      = new List <Wreck>();
            players     = new List <Player>();


            frameData = new List <string>();

            skillEffects = new SortedSet <SkillEffect>(new SkillEffectComparer());

            // Create players
            for (int i = 0; i < playerCount; ++i)
            {
                Player player = new Player(i);
                players.Add(player);
            }

            // Generate the map
            Queue <TankerSpawn> queue = new Queue <TankerSpawn>();

            for (int i = 0; i < 500; ++i)
            {
                queue.Enqueue(new TankerSpawn(TANKER_MIN_SIZE + random.Next(TANKER_MAX_SIZE - TANKER_MIN_SIZE),
                                              random.NextDouble()));
            }
            players.ForEach(p => p.tankers = queue);

            // Create looters
            foreach (Player player in players)
            {
                for (int i = 0; i < LOOTER_COUNT; ++i)
                {
                    Looter looter = createLooter(i, player, 0, 0);
                    player.looters[i] = looter;
                    units.Add(looter);
                    looters.Add(looter);
                }
            }

            // Random spawns for looters
            bool finished = false;

            while (!finished)
            {
                finished = true;

                for (int i = 0; i < LOOTER_COUNT && finished; ++i)
                {
                    double distance = random.NextDouble() * (MAP_RADIUS - LOOTER_RADIUS);
                    double angle    = random.NextDouble();

                    foreach (Player player in players)
                    {
                        double looterAngle = (player.index + angle) * (Math.PI * 2.0 / ((double)playerCount));
                        double cos         = Math.Cos(looterAngle);
                        double sin         = Math.Sin(looterAngle);

                        Looter looter = player.looters[i];
                        looter.Move(cos * distance, sin * distance);

                        // If the looter touch a looter, reset everyone and try again
                        if (units.Any(u => u != looter && looter.Distance(u) <= looter.radius + u.radius))
                        {
                            finished = false;
                            looters.ForEach(l => l.Move(0.0, 0.0));
                            break;
                        }
                    }
                }
            }

            // Spawn start tankers
            for (int j = 0; j < Referee.TANKERS_BY_PLAYER; ++j)
            {
                foreach (Player player in players)
                {
                    SpawnTanker(player);
                }
            }

            adjust();
            newFrame(1.0);
            snapshot();
        }