예제 #1
0
파일: Program.cs 프로젝트: akulin/csb
        private static void Main(string[] args)
        {
            var reader    = new StateReader();
            var initData  = reader.ReadInitData();
            var persister = new StatePersister();
            var evaluator = new StateEvaluator();
            var fastAi    = new FastAi();
            var ai        = new SingleTargetAi(10, evaluator, fastAi);

            while (true)
            {
                var state     = reader.ReadState(initData, persister.IsInitialState);
                var countdown = new Countdown(140);
                persister.FillState(state);
                Console.Error.WriteLine("my checkpoints taken:  " + state.MyPods[0].CheckpointsTaken + " " + state.MyPods[1].CheckpointsTaken);
                Console.Error.WriteLine("his checkpoints taken: " + state.HisPods[0].CheckpointsTaken + " " + state.HisPods[1].CheckpointsTaken);
                var bestMoves = ai.GetMoves(state, countdown);
                persister.RegisterMoves(bestMoves);
                Console.Error.WriteLine(countdown);
                foreach (var t in bestMoves)
                {
                    Console.WriteLine(t);
                }
            }
        }
예제 #2
0
        public void SimulateMove_WithoutCollisions(string input, string command, string expectedResult)
        {
            var pod  = StateReader.ReadPod(input);
            var move = PodMove.Parse(command);

            throw new NotImplementedException("Finish this test! Put here simulation of one tick of the pod move without collisions");
            Assert.AreEqual(expectedResult, pod.ToString());
        }
예제 #3
0
파일: State_Should.cs 프로젝트: akulin/csb
        public void TickCorrectly(
            string init, string state1, string move1, string move2, string move3, string move4, string state2)
        {
            var state    = StateReader.Read(init, state1);
            var myMoves  = new[] { PodMove.Parse(move1), PodMove.Parse(move2) };
            var hisMoves = new[] { PodMove.Parse(move3), PodMove.Parse(move4) };

            state.Tick(myMoves, hisMoves);
            var expectedState = StateReader.Read(init, state2);

            EnsureAlmostEqual(state, expectedState);
        }
예제 #4
0
        public void RotatePodOnPlaceToTarget([Range(1, 15, 1)] int simulationTime)
        {
            var state = StateReader.Read("3|2|10000 2000|16000 9000",
                                         "8000 2000 0 0 180 0|0 200 0 0 0 1|0 400 0 0 0 1|0 6000 0 0 0 1");
            var fastAi    = new FastAi();
            var evaluator = new TestStateEvaluator();
            var moves     = new SingleTargetAi(simulationTime, evaluator, fastAi).GetMoves(state, 40);

            state.Tick(moves, fastAi.GetMoves(state, 1));
            double podHeading = state.MyPods[0].HeadingInRadians.NormAngleInRadians();

            Console.WriteLine($"MOVE [{moves[0]}] turn pod0 to {podHeading}");
            Assert.That(Math.Abs(podHeading), Is.LessThan(3));
            Assert.That(state.MyPods[0].V, Is.EqualTo(VecD.Zero));
        }
예제 #5
0
        public void MovePodToTarget([Range(1, 15, 1)] int simulationTime)
        {
            var state = StateReader.Read("3|2|10 000 2000|16000 9000",
                                         "8000 2000 0 0 0 0|0 200 0 0 0 1|0 400 0 0 0 1|0 6000 0 0 0 1");
            var fastAi       = new FastAi();
            var evaluator    = new TestStateEvaluator();
            var initialScore = evaluator.Evaluate(state);
            var moves        = new SingleTargetAi(simulationTime, evaluator, fastAi).GetMoves(state, 40);

            state.Tick(moves, fastAi.GetMoves(state, 1));
            var finalScore = evaluator.Evaluate(state);

            Console.WriteLine($"MOVE [{moves[0]}] change score from {initialScore} to {finalScore}");
            Assert.That(finalScore, Is.GreaterThan(initialScore));
        }
예제 #6
0
파일: State_Should.cs 프로젝트: akulin/csb
        public void DoesNotEliminatePlayer_WhenOnlyOneHisPodCantTakeCheckpointsTooLongTime()
        {
            var state = StateReader.Read(
                "3|4|8024 7881|13301 5550|9567 1403|3663 4439|",
                "7822 7424 0 0 -1 1|8226 8338 0 0 -1 1|7418 6509 0 0 -1 1|8630 9253 0 0 -1 1|");
            var ai = new FastAi();

            for (int time = 0; time < 200; time++)
            {
                var myMoves  = ai.GetMoves(state, 0);
                var hisMoves = ai.GetMoves(state.WithSwappedPlayers(), 0);
                hisMoves[0] = new PodMove(VecD.Zero, 0);
                state.Tick(myMoves, hisMoves);
            }
            Assert.That(state.HisPods[0].TimeWithoutCheckpoint, Is.GreaterThan(100));
            Assert.That(state.IsDead, Is.All.EqualTo(false));
        }
예제 #7
0
파일: State_Should.cs 프로젝트: akulin/csb
        public void EliminatePlayer_WhenHeCantTakeCheckpointsTooLongTime()
        {
            var state = StateReader.Read(
                "3|4|8024 7881|13301 5550|9567 1403|3663 4439|",
                "7822 7424 0 0 -1 1|8226 8338 0 0 -1 1|7418 6509 0 0 -1 1|8630 9253 0 0 -1 1|");
            var ai = new FastAi();

            for (int time = 0; time < 101; time++)
            {
                Assert.That(state.IsDead, Does.Not.Contains(true));
                var moves = ai.GetMoves(state, 0);
                state.Tick(moves, new[] { new PodMove(VecD.Zero, 0), new PodMove(VecD.Zero, 0) });
            }
            Assert.That(state.HisPods[0].TimeWithoutCheckpoint, Is.GreaterThan(100));
            Assert.That(state.HisPods[1].TimeWithoutCheckpoint, Is.GreaterThan(100));
            Assert.That(state.IsDead[1], Is.True);
        }
예제 #8
0
파일: State_Should.cs 프로젝트: akulin/csb
        public void SimulateGameLogCorrectly(string filename)
        {
            var   lines     = File.ReadAllLines(Path.Combine(TestContext.CurrentContext.TestDirectory, filename));
            var   iLine     = 0;
            var   initData  = new StateReader(lines[iLine++]).ReadInitData();
            var   persister = new StatePersister();
            var   tick      = 0;
            State prevStateAfterMovesApplied = null;

            while (iLine < lines.Length)
            {
                var state = new StateReader(lines[iLine++]).ReadState(initData, persister.IsInitialState);
                persister.FillState(state);
                if (prevStateAfterMovesApplied != null)
                {
                    try
                    {
                        EnsureAlmostEqual(prevStateAfterMovesApplied, state);
                    }
                    catch
                    {
                        Console.Error.WriteLine("    simulation result: ");
                        Console.Error.WriteLine(prevStateAfterMovesApplied);
                        Console.Error.WriteLine("    true result:");
                        Console.Error.WriteLine(state);
                        throw;
                    }
                }
                iLine++;
                // ReSharper disable once AccessToModifiedClosure
                var myMoves  = 2.Times(i => PodMove.Parse(lines[iLine++])).ToArray();
                var hisMoves = 2.Times(i => PodMove.Parse(lines[iLine++])).ToArray();
                Console.Error.WriteLine($"=== TICK {tick} ===");
                Console.Error.WriteLine(state);
                Console.Error.WriteLine("myPod[0]:  " + myMoves[0]);
                Console.Error.WriteLine("myPod[1]:  " + myMoves[1]);
                Console.Error.WriteLine("hisPod[0]: " + hisMoves[0]);
                Console.Error.WriteLine("hisPod[1]: " + hisMoves[1]);
                state.Tick(myMoves, hisMoves);
                persister.RegisterMoves(myMoves, hisMoves);
                prevStateAfterMovesApplied = state;
                tick++;
            }
        }
예제 #9
0
        public void FillShieldState()
        {
            var persister = new StatePersister();
            var s1 = StateReader.Read("1|2|1000 1000|9000 1000",
                "0 1000 0 0 186 1|7314 817 0 0 186 1|9313 881 0 0 185 1|6315 785 0 0 187 1");
            s1.IsInitialState = true;
            persister.FillState(s1);
            Assert.That(s1.MyPods[0].ShieldTicksLeft, Is.Zero);
            Assert.That(s1.MyPods[1].ShieldTicksLeft, Is.Zero);
            persister.RegisterMoves(new[] {
                new PodMove(new VecD(0, 0), 0, MoveType.Shield),
                new PodMove(new VecD(0, 0), Constants.MaxThrust)
            });
            var s2 = StateReader.Read("1|2|1000 1000|9000 1000",
                "2000 1000 0 0 186 2|7314 817 0 0 186 1|9313 881 0 0 185 1|6315 785 0 0 187 1");
            persister.FillState(s2);

            Assert.That(s2.MyPods[0].ShieldTicksLeft, Is.EqualTo(3));
            Assert.That(s2.MyPods[1].ShieldTicksLeft, Is.EqualTo(0));
        }
예제 #10
0
        public void FillBoostAbility()
        {
            var persister = new StatePersister();
            var s1 = StateReader.Read("1|2|1000 1000|9000 1000",
                "0 1000 0 0 186 1|7314 817 0 0 186 1|9313 881 0 0 185 1|6315 785 0 0 187 1");
            s1.IsInitialState = true;
            persister.FillState(s1);
            Assert.That(s1.MyPods[0].CanBoost, Is.True);
            Assert.That(s1.MyPods[1].CanBoost, Is.True);
            persister.RegisterMoves(new[]
            {
                new PodMove(new VecD(0, 0), 0, MoveType.Boost),
                new PodMove(new VecD(0, 0), Constants.MaxThrust)
            });
            var s2 = StateReader.Read("1|2|1000 1000|9000 1000",
                "2000 1000 0 0 186 2|7314 817 0 0 186 1|9313 881 0 0 185 1|6315 785 0 0 187 1");
            persister.FillState(s2);

            Assert.That(s2.MyPods[0].CanBoost, Is.False);
            Assert.That(s2.MyPods[1].CanBoost, Is.True);
        }
예제 #11
0
        public void FillCheckpointsData()
        {
            var persister = new StatePersister();
            var s1 = StateReader.Read("1|2|1000 1000|9000 1000",
                "0 1000 0 0 186 1|7314 817 0 0 186 1|9313 881 0 0 185 1|6315 785 0 0 187 1");
            s1.IsInitialState = true;
            persister.FillState(s1);
            Assert.That(s1.MyPods[0].CheckpointsTaken, Is.EqualTo(0));
            var s2 = StateReader.Read("1|2|1000 1000|9000 1000",
                "2000 1000 0 0 186 2|7314 817 0 0 186 1|9313 881 0 0 185 1|6315 785 0 0 187 1");
            persister.FillState(s2);

            Assert.That(s2.MyPods[0].CheckpointsTaken, Is.EqualTo(1));
            Assert.That(s2.MyPods[1].CheckpointsTaken, Is.EqualTo(0));
            Assert.That(s2.HisPods[0].CheckpointsTaken, Is.EqualTo(0));
            Assert.That(s2.HisPods[1].CheckpointsTaken, Is.EqualTo(0));

            Assert.That(s2.MyPods[0].TimeWithoutCheckpoint, Is.EqualTo(0));
            Assert.That(s2.MyPods[1].TimeWithoutCheckpoint, Is.EqualTo(1));
            Assert.That(s2.HisPods[0].TimeWithoutCheckpoint, Is.EqualTo(1));
            Assert.That(s2.HisPods[1].TimeWithoutCheckpoint, Is.EqualTo(1));

        }
예제 #12
0
        public static State Read(string init, string state)
        {
            var initData = new StateReader(init).ReadInitData();

            return(new StateReader(state).ReadState(initData));
        }