Esempio n. 1
0
        private Tuple <int, int> GetPlayerDestination(PlayerNash nash)
        {
            Zombie target;

            if (nash.Target != null)
            {
                target = nash.Target;
                NextPosZombie(target, nash, out var destination);

                if (destination is null)
                {
                    return(new Tuple <int, int>(-1, -1));
                }

                return(destination);
            }
            else
            {
                if (nash.NextPosition is null)
                {
                    return(new Tuple <int, int>(-1, -1));
                }

                return(nash.NextPosition);
            }
        }
Esempio n. 2
0
        private bool NextPosZombie(Zombie zombie, PlayerNash nash, out Tuple <int, int> posOut)
        {
            var arrived = false;
            Tuple <int, int> targetPos;
            float            dist;
            float            t;

            // If the zombie has a human target he well go for eat it; otherwise the target must be Nash, so the zombie will try to go to Nash position.
            if (zombie.Target != null)
            {
                targetPos = zombie.Target.Position;
            }
            else
            {
                targetPos = nash.Position;
            }

            dist = Tools.GetDistance(zombie.Position, targetPos);
            if (dist <= Zombie.MOUVEMENT)
            {
                arrived = true;
                posOut  = new Tuple <int, int>(targetPos.Item1, targetPos.Item2);
            }
            else
            {
                t      = Zombie.MOUVEMENT / dist;
                posOut = new Tuple <int, int>(
                    (int)Math.Floor(zombie.Position.Item1 + (t * (targetPos.Item1 - zombie.Position.Item1))),
                    (int)Math.Floor(zombie.Position.Item2 + (t * (targetPos.Item2 - zombie.Position.Item2)))
                    );
            }

            return(arrived);
        }
Esempio n. 3
0
 public PlayerNash(PlayerNash nash)
 {
     Position     = nash.Position;
     NextPosition = nash.NextPosition;
     Arrived      = nash.Arrived;
     Target       = nash.Target;
 }
Esempio n. 4
0
 public GameTurnInfos(PlayerNash nash, List <Human> humans, List <Zombie> zombies)
 {
     Nash = new PlayerNash(nash);
     SetHumansOrZombies(humans);
     SetHumansOrZombies(zombies);
     NashTargetDiedThisTurn = false;
 }
Esempio n. 5
0
 private void MovePlayer(PlayerNash nash)
 {
     nash.Arrived  = NextPosNash(nash, out var nashNextPos);
     nash.Position = nashNextPos;
 }
Esempio n. 6
0
 private void MoveZombie(Zombie zombie, PlayerNash nash)
 {
     zombie.Arrived  = NextPosZombie(zombie, nash, out var zombiePosition);
     zombie.Position = zombiePosition;
 }
Esempio n. 7
0
        static void Main(string[] args)
        {
            string[] inputs;
            var      previousHumansCount  = 0;
            var      previousZombiesCount = 0;
            var      simulation           = new SimulationGame();

            var gameInfosDebug = new GameInfosForDebug();

            // game loop
            while (true)
            {
                inputs = Console.ReadLine().Split(' ');
                var nashPosition = new Tuple <int, int>(int.Parse(inputs[0]), int.Parse(inputs[1]));
                var nash         = new PlayerNash(nashPosition);

                int humanCount = int.Parse(Console.ReadLine());
                var humans     = new List <Human>();
                for (var i = 0; i < humanCount; i++)
                {
                    inputs = Console.ReadLine().Split(' ');
                    var human = new Human(
                        id: int.Parse(inputs[0]),
                        pos: new Tuple <int, int>(int.Parse(inputs[1]), int.Parse(inputs[2]))
                        );
                    humans.Add(human);
                }

                int zombieCount = int.Parse(Console.ReadLine());
                var zombies     = new List <Zombie>();
                for (var i = 0; i < zombieCount; i++)
                {
                    inputs = Console.ReadLine().Split(' ');
                    var zombie = new Zombie(
                        id: int.Parse(inputs[0]),
                        pos: new Tuple <int, int>(int.Parse(inputs[1]), int.Parse(inputs[2])),
                        nextPos: new Tuple <int, int>(int.Parse(inputs[3]), int.Parse(inputs[4]))
                        );
                    zombies.Add(zombie);
                }

                if (zombieCount < previousZombiesCount)
                {
                    int zombiesDead = previousZombiesCount - zombieCount;
                    int humanPoints = 10 * previousHumansCount * previousHumansCount;

                    for (var i = 0; i < zombiesDead; i++)
                    {
                        var tmpPoints = humanPoints;

                        if (zombiesDead > 1)
                        {
                            tmpPoints *= Tools.Fibonacci(i + 1);
                        }
                        simulation.ActualScore += tmpPoints;
                    }
                }

                var turnInfos = new GameTurnInfos(nash, humans, zombies);

                // For each turn, we want to simulate the maximum of game played to find the best next move possible.
                simulation.InitTurnInfos(turnInfos);
                var simResult = simulation.Simulation(gameInfosDebug);

                if (simulation.NewBest)
                {
                    simulation.NumTurn = 0;
                    simulation.NewBest = false;
                }

    #if DEBUG_MODE
                DebugInfos.WriteSimulTurnInfos(gameInfosDebug.DebugInfosForTurn[simulation.NumTurn], DebugInfos.DEBUG);
    #endif

                Tools.PrintMove(simulation.BestSimulation.Moves[simulation.NumTurn]);

                previousHumansCount  = humanCount;
                previousZombiesCount = zombieCount;

                simulation.NumTurn++;
            }
        }