Exemplo n.º 1
0
        public static (RESTResult, string, string) RESTFight(string p1, int minerals)
        {
            Player _opp = new Player();

            _opp.Name   = "Player#2";
            _opp.Pos    = 4;
            _opp.ID     = paxgame.GetPlayerID();
            _opp.Race   = UnitRace.Terran;
            _opp.inGame = true;
            _opp.Units  = new List <Unit>(UnitPool.Units.Where(x => x.Race == _opp.Race));
            GameHistory game = new GameHistory();

            _opp.Game    = game;
            _opp.Game.ID = paxgame.GetGameID();
            _opp.Game.Players.Add(_opp);

            _opp.MineralsCurrent = minerals;
            OppService.BPRandom(_opp).GetAwaiter().GetResult();
            string actions = String.Join('X', _opp.GetAIMoves());

            (RESTResult result, string oppstring) = RESTFight(p1, _opp.GetString());
            return(result, actions, oppstring);

            //return RESTFight(p1, bopp.GetString(_opp));
        }
Exemplo n.º 2
0
 public static void RESTFight(GameHistory _game, bool random = true)
 {
     if (random)
     {
         OppService.BPRandom(_game.Players.First()).GetAwaiter();
         OppService.BPRandom(_game.Players.Last()).GetAwaiter();
     }
     GameService.GenFight(_game).GetAwaiter().GetResult();
     StatsService.GenRoundStats(_game).GetAwaiter().GetResult();
 }
Exemplo n.º 3
0
        public static void BuildJob(object obj)
        {
            BBuildJob   job  = obj as BBuildJob;
            GameHistory game = new GameHistory();

            game.ID          = paxgame.GetGameID();
            game.battlefield = new Battlefield();
            Player myplayer = _player.SoftCopy();

            myplayer.Game = game;
            Player myopp = _opp.SoftCopy();

            myopp.Game = game;
            game.Players.Add(myplayer);
            myplayer.Game = game;
            game.Players.Add(myopp);
            myopp.Game = game;
            myplayer.SetString(job.PlayerBuild);
            myopp.SetString(job.OppBuild);
            myopp.MineralsCurrent = job.Minerals;

            OppService.BPRandom(myopp, true).GetAwaiter().GetResult();
            GameService.GenFight(game).GetAwaiter().GetResult();
            StatsService.GenRoundStats(game, false).GetAwaiter().GetResult();

            Stats result    = new Stats();
            Stats oppresult = new Stats();

            result.DamageDone            = game.Stats.Last().Damage[1];
            result.MineralValueKilled    = game.Stats.Last().Killed[1];
            oppresult.DamageDone         = game.Stats.Last().Damage[0];
            oppresult.MineralValueKilled = game.Stats.Last().Killed[0];
            lock (_refreshBB)
            {
                int check = CheckResult(result, oppresult);
                if (check == 1 || check == 2)
                {
                    _refreshBB.BestBuild = myopp.GetString();
                }
                else if (check == 3)
                {
                    _refreshBB.WorstBuild = myopp.GetString();
                }
            }

            for (int i = 0; i < POSITIONS; i++)
            {
                BBuildJob pjob = new BBuildJob();
                pjob.PlayerBuild = job.PlayerBuild;
                pjob.OppBuild    = myopp.GetString();
                _jobs_position.Add(pjob);
            }

            Interlocked.Increment(ref _refreshBB.TOTAL_DONE);
        }
Exemplo n.º 4
0
        public static void PositionJob(object obj)
        {
            BBuildJob   job  = obj as BBuildJob;
            GameHistory game = new GameHistory();

            game.ID          = paxgame.GetGameID();
            game.battlefield = new Battlefield();
            Player myplayer = _player.SoftCopy();

            myplayer.Game = game;
            Player myopp = _opp.SoftCopy();

            myopp.Game = game;
            game.Players.Add(myplayer);
            myplayer.Game = game;
            game.Players.Add(myopp);
            myopp.Game = game;
            myplayer.SetString(job.PlayerBuild);
            myopp.SetString(job.OppBuild);

            OppService.PositionRandomDistmod(myopp.Units.Where(x => x.Status != UnitStatuses.Available).ToList(), myopp).GetAwaiter();
            GameService.GenFight(game).GetAwaiter().GetResult();
            StatsService.GenRoundStats(game, false).GetAwaiter().GetResult();

            Stats result    = new Stats();
            Stats oppresult = new Stats();

            result.DamageDone            = game.Stats.Last().Damage[1];
            result.MineralValueKilled    = game.Stats.Last().Killed[1];
            oppresult.DamageDone         = game.Stats.Last().Damage[0];
            oppresult.MineralValueKilled = game.Stats.Last().Killed[0];
            lock (_refreshBB)
            {
                int check = CheckResult(result, oppresult);
                if (check == 1 || check == 2)
                {
                    _refreshBB.BestBuild = myopp.GetString();
                }
                else if (check == 3)
                {
                    _refreshBB.WorstBuild = myopp.GetString();
                }
            }
            Interlocked.Increment(ref _refreshBB.TOTAL_DONE);
        }
Exemplo n.º 5
0
        public static (RESTResult, string, string) RESTFight(string p1, ulong GameID, int minerals)
        {
            Player _opp = _store.GetPlayer(GameID);

            if (_opp == null)
            {
                _opp        = new Player();
                _opp.Name   = "RESTPlayer " + GameID;
                _opp.Pos    = 4;
                _opp.ID     = GameID;
                _opp.Race   = UnitRace.Terran;
                _opp.inGame = true;
                _opp.Units  = new List <Unit>(UnitPool.Units.Where(x => x.Race == _opp.Race));
                GameHistory game = new GameHistory();
                _opp.Game    = game;
                _opp.Game.ID = paxgame.GetGameID();
                _opp.Game.Players.Add(_opp);

                _opp.MineralsCurrent = paxgame.Income;
                _store.SetPlayer(_opp);
            }
            else
            {
                foreach (Unit unit in _opp.Units.Where(x => x.Status == UnitStatuses.Placed))
                {
                    unit.Status = UnitStatuses.Spawned;
                }
                _opp.Game.Spawn++;
                //_opp.MineralsCurrent = minerals - (_opp.Game.Spawn * paxgame.Income);
                _opp.MineralsCurrent += paxgame.Income;
            }
            OppService.BPRandom(_opp).GetAwaiter().GetResult();
            string actions = String.Join('X', _opp.GetAIMoves());

            (RESTResult result, string oppstring) = RESTFight(p1, _opp.GetString());
            return(result, actions, oppstring);
        }
Exemplo n.º 6
0
        public static RandomGame RandomFight(int minerals = 2000, bool save = false)
        {
            Player _player = new Player();

            _player.Name   = "Player#1";
            _player.Pos    = 1;
            _player.ID     = paxgame.GetPlayerID();
            _player.Race   = UnitRace.Terran;
            _player.inGame = true;
            _player.Units  = new List <Unit>(UnitPool.Units.Where(x => x.Race == _player.Race));

            Player _opp = new Player();

            _opp.Name   = "Player#2";
            _opp.Pos    = 4;
            _opp.ID     = paxgame.GetPlayerID();
            _opp.Race   = UnitRace.Terran;
            _opp.inGame = true;
            _opp.Units  = new List <Unit>(UnitPool.Units.Where(x => x.Race == _opp.Race));

            GameHistory game = new GameHistory();

            _player.Game    = game;
            _player.Game.ID = paxgame.GetGameID();
            _player.Game.Players.Add(_player);
            _player.Game.Players.Add(_opp);

            _opp.Game = _player.Game;

            _player.Units = new List <Unit>(UnitPool.Units.Where(x => x.Race == _player.Race && x.Cost > 0));
            _opp.Units    = new List <Unit>(UnitPool.Units.Where(x => x.Race == _opp.Race && x.Cost > 0));

            _player.MineralsCurrent = minerals;
            _opp.MineralsCurrent    = minerals;

            OppService.BPRandom(_player).GetAwaiter().GetResult();
            OppService.BPRandom(_opp).GetAwaiter().GetResult();

            BBuild bplayer = new BBuild(_player);
            BBuild bopp    = new BBuild(_opp);

            bplayer.SetBuild(_player);
            bopp.SetBuild(_opp);

            GameService.GenFight(_player.Game).GetAwaiter().GetResult();
            StatsService.GenRoundStats(game, false).GetAwaiter().GetResult();
            Stats result    = new Stats();
            Stats oppresult = new Stats();

            result.DamageDone            = game.Stats.Last().Damage[1];
            result.MineralValueKilled    = game.Stats.Last().Killed[1];
            oppresult.DamageDone         = game.Stats.Last().Damage[0];
            oppresult.MineralValueKilled = game.Stats.Last().Killed[0];

            RandomResult result1 = new RandomResult();

            result1.DamageDone         = oppresult.DamageDone;
            result1.MineralValueKilled = oppresult.MineralValueKilled;
            RandomResult result2 = new RandomResult();

            result2.DamageDone         = result.DamageDone;
            result2.MineralValueKilled = result.MineralValueKilled;

            RandomGame rgame = new RandomGame();

            rgame.player1 = bplayer;
            rgame.player2 = bopp;
            rgame.result1 = result1;
            rgame.result2 = result2;
            rgame.Result  = game.Stats.Last().winner;

            if (save == true)
            {
                SaveGame(rgame, _player, _opp);
            }

            return(rgame);
        }