Exemplo n.º 1
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());
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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));
        }
Exemplo n.º 4
0
        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++;
            }
        }