Ejemplo n.º 1
0
        public GameData RunGame(IBot bot1, IBot bot2)
        {
            const int drawLimit = 1000;

            GameData gameData = new GameData()
            {
                P1Name = bot1.Name,
                P2Name = bot2.Name
            };

            GameDataController gameDataController = new GameDataController(gameData);

            bot1.NewGame(bot2.Name);
            bot2.NewGame(bot1.Name);

            while (gameData.currentDrawStreak < drawLimit)
            {
                Battle battle = new Battle(bot1.GetNextWeaponChoice(), bot2.GetNextWeaponChoice());
                gameDataController.NewBattle(battle);
                bot1.HandleBattleResult(battle.P1BattleResult, battle.P1Weapon, battle.P2Weapon);
                bot2.HandleBattleResult(battle.P2BattleResult, battle.P2Weapon, battle.P1Weapon);
                if (gameData.victory != Victory.unknown)
                {
                    return(gameData);
                }
            }

            gameData.victory       = Victory.PlayersKeepDrawing;
            gameData.VictoryReason = "Players have drawed for over :" + (drawLimit * 10).ToString();
            return(gameData);
        }
Ejemplo n.º 2
0
        public GameAndTrainingData RunGame(IBot bot1, IBot bot2)
        {
            const int drawLimit = 1000;

            TrainingData p1TrainingData = new TrainingData();
            TrainingData p2TrainingData = new TrainingData();

            GameData gameData = new GameData()
            {
                P1Name = bot1.Name,
                P2Name = bot2.Name
            };

            GameDataController gameDataController = new GameDataController(gameData);

            bot1.NewGame(bot2.Name);
            bot2.NewGame(bot1.Name);

            while (gameData.currentDrawStreak < drawLimit)
            {
                Battle battle = new Battle(bot1.GetNextWeaponChoice(), bot2.GetNextWeaponChoice());

                if (gameData.currentDrawStreak > 0)
                {
                    p1TrainingData.AddInputs(gameData.currentDrawStreak, 1000 - gameData.P1WinCount, 1000 - gameData.P2WinCount, 100 - gameData.P1DynamiteUsed, 100 - gameData.P2DynamiteUsed);
                    p2TrainingData.AddInputs(gameData.currentDrawStreak, 1000 - gameData.P2WinCount, 1000 - gameData.P1WinCount, 100 - gameData.P2DynamiteUsed, 100 - gameData.P1DynamiteUsed);
                    p1TrainingData.AddOutputs(battle.P1Weapon);
                    p2TrainingData.AddOutputs(battle.P2Weapon);
                }

                gameDataController.NewBattle(battle);
                bot1.HandleBattleResult(battle.P1BattleResult, battle.P1Weapon, battle.P2Weapon);
                bot2.HandleBattleResult(battle.P2BattleResult, battle.P2Weapon, battle.P1Weapon);
                if (gameData.victory != Victory.unknown)
                {
                    return(new GameAndTrainingData {
                        gameData = gameData, P1TrainingData = p1TrainingData, P2TrainingData = p2TrainingData
                    });
                }
            }

            gameData.victory       = Victory.PlayersKeepDrawing;
            gameData.VictoryReason = "Players have drawed for over :" + (drawLimit * 10).ToString();
            return(new GameAndTrainingData {
                gameData = gameData, P1TrainingData = p1TrainingData, P2TrainingData = p2TrainingData
            });
        }
Ejemplo n.º 3
0
        public static Victory RunGame(IBot bot1, IBot bot2)
        {
            int       bot1DynamiteCount;
            int       bot2DynamiteCount;
            int       bot1WinCount;
            int       bot2WinCount;
            int       currentDrawStreak;
            const int WinsNeeded   = 1000;
            const int MaxDynamites = 100;
            const int drawLimit    = 1001;

            bot1DynamiteCount = 0;
            bot2DynamiteCount = 0;
            bot1WinCount      = 0;
            bot2WinCount      = 0;
            currentDrawStreak = 0;

            bot1.NewGame(bot2.Name);
            bot2.NewGame(bot1.Name);

            while (currentDrawStreak < drawLimit)
            {
                var w1 = bot1.GetNextWeaponChoice();

                if (w1 == Weapon.Dynamite)
                {
                    bot1DynamiteCount++;
                    if (bot1DynamiteCount > MaxDynamites)
                    {
                        return(Victory.player2Victory);
                    }
                }

                var w2 = bot2.GetNextWeaponChoice();

                if (w2 == Weapon.Dynamite)
                {
                    bot2DynamiteCount++;
                    if (bot2DynamiteCount > MaxDynamites)
                    {
                        return(Victory.player1Victory);
                    }
                }

                switch (new Battle(w1, w2).P1BattleResult)
                {
                case BattleResult.Draw:

                    currentDrawStreak++;
                    bot1.HandleBattleResult(BattleResult.Draw, w1, w2);
                    bot2.HandleBattleResult(BattleResult.Draw, w2, w1);
                    break;

                case BattleResult.Win:
                    bot1WinCount     += 1 + currentDrawStreak;
                    currentDrawStreak = 0;

                    if (bot1WinCount >= WinsNeeded)
                    {
                        return(Victory.player1Victory);
                    }
                    bot1.HandleBattleResult(BattleResult.Win, w1, w2);
                    bot2.HandleBattleResult(BattleResult.Lose, w2, w1);
                    break;

                case BattleResult.Lose:
                    bot2WinCount     += 1 + currentDrawStreak;
                    currentDrawStreak = 0;

                    if (bot2WinCount >= WinsNeeded)
                    {
                        return(Victory.player2Victory);
                    }
                    bot1.HandleBattleResult(BattleResult.Lose, w1, w2);
                    bot2.HandleBattleResult(BattleResult.Win, w2, w1);
                    break;
                }
            }

            return(Victory.PlayersKeepDrawing);
        }