Example #1
0
        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);
        }
Example #2
0
        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);
        }
Example #3
0
        public void Given5_ShouldSucceed()
        {
            var parser = new WorldParser("5");

            int five = parser.ReadDigit();
            Assert.Equal(5, five);
        }
Example #4
0
        public void ParseFromServer_ShouldSucceed(string data)
        {
            var parser = new WorldParser(data);
            var world = parser.Parse();

            Assert.NotNull(world);
            Assert.Equal(6, world.Players.Count);
        }
Example #5
0
        public void Given0_9_ShouldSucceed()
        {
            var parser = new WorldParser("0123456789");

            for (int i = 0; i < 10; i++)
            {
                int read = parser.ReadDigit();
                Assert.Equal(i, read);
            }
        }
Example #6
0
 public void ReadUnexpected_ShouldThrow()
 {
     var parser = new WorldParser("abc");
     Assert.Throws<UnexpectedTokenException>(() => parser.Read('?'));
     Assert.Equal('a', parser.Current);
 }
Example #7
0
 public void ReadString_ShouldSucceed()
 {
     var parser = new WorldParser("abcdefhhhhh");
     var str = parser.ReadString("abcdef");
     Assert.Equal("abcdef", str);
 }
Example #8
0
 public void ReadExpected_ShouldSucceed()
 {
     var parser = new WorldParser(",");
     var c = parser.Read(',');
     Assert.Equal(',', c);
 }