コード例 #1
0
ファイル: Game.cs プロジェクト: TortueGit/CodingGame
        private void Evaluate(GameTurnInfos infosTurn, SimulationResult sr)
        {
            int tmpPoints;
            int humanNum           = infosTurn.Humans.Count;
            int humanPoints        = 10 * humanNum * humanNum;
            var killableZombies    = new List <Zombie>();
            var killableZombiesLen = ZombiesInRangeOfPlayer(killableZombies, infosTurn);

            var tmpId = (infosTurn.Nash.Target != null) ? infosTurn.Nash.Target.Id : GameInfos.EMPTY_ZOMBIE;

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

                if (killableZombiesLen > 1)
                {
                    tmpPoints *= Tools.Fibonacci(i + 1);
                }
                sr.Points += tmpPoints;
            }

            if (killableZombies.Any(x => x.Id == tmpId))
            {
                infosTurn.Nash.Target            = null;
                infosTurn.NashTargetDiedThisTurn = true;
            }

            var zombiesToRemove = new HashSet <Zombie>(killableZombies);

            infosTurn.Zombies.RemoveAll(x => zombiesToRemove.Contains(x));
        }
コード例 #2
0
ファイル: Game.cs プロジェクト: TortueGit/CodingGame
        private Tuple <int, int> Turn(GameTurnInfos infosTurn, SimulationResult simResult, SimulationInfos simInfos)
        {
            var move = new Tuple <int, int>(-1, -1);

            foreach (Zombie zombie in infosTurn.Zombies)
            {
                FindZombieTarget(zombie, infosTurn);
                MoveZombie(zombie, infosTurn.Nash);
            }

            move = GetPlayerDestination(infosTurn.Nash);

            MovePlayer(infosTurn.Nash);

            Evaluate(infosTurn, simResult);

            ZombiesEat(infosTurn);

            if ((infosTurn.Humans.Count) > 0 && (infosTurn.Zombies.Count > 0))
            {
                if (infosTurn.Nash.Arrived || infosTurn.NashTargetDiedThisTurn)
                {
                    ComputePlayerTarget(infosTurn, simInfos);
                    infosTurn.NashTargetDiedThisTurn = false;
                }
            }
            else
            {
                simInfos.SimFailure       = (infosTurn.Humans.Count <= 0);
                simInfos.SimZombieAllDead = (infosTurn.Zombies.Count <= 0);
            }

            return(move);
        }
コード例 #3
0
ファイル: Game.cs プロジェクト: TortueGit/CodingGame
        public SimulationResult Simulation(GameInfosForDebug gameInfosDebug)
        {
            var simResult = new SimulationResult();
            var agent     = new SimulationAgent();

            while (agent.TotalMs < GameInfos.TIMEOUT_FOR_A_TURN_IN_MS && agent.SimRun <= GameInfos.MAX_SIMULATIONS_RUN)
            {
                var t0 = DateTime.UtcNow;

                var infosTurn = new GameTurnInfos(
                    nash: TurnInfos.Nash,
                    humans: TurnInfos.Humans,
                    zombies: TurnInfos.Zombies
                    );

                var tmpResult = SimulateGame(infosTurn, gameInfosDebug);

                if (tmpResult.Points >= simResult.Points)
                {
                    simResult = new SimulationResult(tmpResult);
                }

                var t1 = DateTime.UtcNow;
                agent.TotalMs += Tools.TimeDifferenceInMillisecond(t0, t1);
                agent.SimRun++;
            }

            DebugInfos.WriteDebugMessage(
                functionName: "Simulation end",
                strings: new string[] { $"total sim run {agent.SimRun} in {agent.TotalMs} ms\n" },
                debugLevel: DebugInfos.INFOS
                );

            return(simResult);
        }
コード例 #4
0
ファイル: Game.cs プロジェクト: TortueGit/CodingGame
        private SimulationResult SimulateGame(GameTurnInfos infosTurn, GameInfosForDebug gameInfosDebug)
        {
            var rand           = new Random();
            var sr             = new SimulationResult();
            var simInfos       = new SimulationInfos();
            var moves          = new List <Tuple <int, int> >();
            var gameDebug      = new GameInfosForDebug();
            var turnInfosDebug = new DebugInfosForEachTurn();

            simInfos.SimStartingRandomMovesNum = rand.Next(GameInfos.MAX_SIMULATION_RANDOM_STARTING_MOVES + 1);

            ComputePlayerTarget(infosTurn, simInfos);

            while (!simInfos.SimZombieAllDead && !simInfos.SimFailure && simInfos.SimMovesCount < GameInfos.MAX_MOVES)
            {
                // Simulate a turn of the game.
                simInfos.Moves.Add(Turn(infosTurn, sr, simInfos));

    #if DEBUG_MODE
                turnInfosDebug.Nash = infosTurn.Nash;
                turnInfosDebug.SetHumansOrZombies(infosTurn.Humans);
                turnInfosDebug.SetHumansOrZombies(infosTurn.Zombies);
                turnInfosDebug.Points  = sr.Points;
                turnInfosDebug.Move    = simInfos.Moves.Last();
                turnInfosDebug.NumTurn = simInfos.SimMovesCount;
                gameDebug.DebugInfosForTurn.Add(new DebugInfosForEachTurn(turnInfosDebug));
    #endif

                simInfos.SimMovesCount++;
            }

            if (simInfos.SimZombieAllDead &&
                !simInfos.SimFailure &&
                ((sr.Points + ActualScore) > BestSimulation.SimPoints ||
                 (sr.Points + ActualScore) == BestSimulation.SimPoints && (simInfos.SimMovesCount < (BestSimulation.SimMovesCount - NumTurn))))
            {
                simInfos.SimPoints = sr.Points + ActualScore;
                BestSimulation     = simInfos;
                NewBest            = true;
    #if DEBUG_MODE
                gameInfosDebug.SetDebugInfosForTurn(gameDebug.DebugInfosForTurn);
    #endif
            }

            return(sr);
        }
コード例 #5
0
ファイル: Game.cs プロジェクト: TortueGit/CodingGame
 public SimulationResult(SimulationResult simResult)
 {
     Points       = simResult.Points;
     NumberOfTurn = simResult.NumberOfTurn;
 }