コード例 #1
0
ファイル: WorldParserTests.cs プロジェクト: gleroi/k-rabbit
        public void ValidWorld_ShouldSucceed()
        {
            var msg = "worldstate::25;1,12,15,2,playing:2,21,51,-3,stunned;" +
                      "12,15:42,64;1,5023,-8963:2,12,15;";
            var parser = new WorldParser(msg);
            var world = parser.Parse();

            Assert.NotNull(world);
            Assert.Equal(25, world.Round);

            Assert.Equal(2, world.Players.Count);
            Assert.Equal(2, world.Compteurs.Count);
            Assert.Equal(2, world.Caddies.Count);

            var firstPlayer = world.Players[0];
            APlayer.Is(firstPlayer, 12, 15, 2, PlayerState.Playing);

            var secondPlayer = world.Players[1];
            APlayer.Is(secondPlayer, 21, 51, -3, PlayerState.Stunned);

            this.IsCompteur(world.Compteurs[0], 12, 15);
            this.IsCompteur(world.Compteurs[1], 42, 64);

            this.IsCaddy(world.Caddies[0], 5023, -8963);
            this.IsCaddy(world.Caddies[1], 12, 15);

            Assert.True(firstPlayer.HasCompteur);
            Assert.False(secondPlayer.HasCompteur);
        }
コード例 #2
0
ファイル: KRabbit.cs プロジェクト: gleroi/k-rabbit
        private void HandleWorldState(Message msg)
        {
            Stopwatch watch = Stopwatch.StartNew();
            var parser = new WorldParser(msg.Data);
            var world = parser.Parse();
            this.Id = world.Players.FindIndex(p => p.Id == Program.TeamId);
            this.Ai.Id = this.Id;
            Log.Info("Player {0} round {1}", this.Id, world.Round);
            Direction direction;

            try
            {
                direction = this.Ai.Decide(world);
            }
            catch (Exception e)
            {
                Log.Error(e.ToString());
                direction = (Direction) this.random.Next(0, 4);
                Log.Error("Player {0} decides randomly {1}", this.Id, direction);
            }

            watch.Stop();

            this.Client.SendMove(world.Round, direction);

            Log.Info("Player {0} decides {1} in {2}ms", this.Id, direction, watch.ElapsedMilliseconds);
        }
コード例 #3
0
ファイル: WorldParserTests.cs プロジェクト: gleroi/k-rabbit
        public void ParseFromServer_ShouldSucceed(string data)
        {
            var parser = new WorldParser(data);
            var world = parser.Parse();

            Assert.NotNull(world);
            Assert.Equal(6, world.Players.Count);
        }