Exemple #1
0
        public static (RESTResult, string) RESTFight(string p1, string p2)
        {
            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;


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

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

            bplayer.SetString(p1, _player);
            bopp.SetString(p2, _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];

            RESTResult rgame = new RESTResult();

            rgame.Result     = game.Stats.Last().winner;
            rgame.DamageP1   = oppresult.DamageDone;
            rgame.MinValueP1 = oppresult.MineralValueKilled;
            rgame.DamageP2   = result.DamageDone;
            rgame.MinValueP2 = result.MineralValueKilled;

            return(rgame, bopp.GetString(_opp));
        }
Exemple #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();
 }
Exemple #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);
        }
Exemple #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);
        }
Exemple #5
0
        public static async Task GetBestBuild([NotNull] Player player, [NotNull] Player opp, [NotNull] RefreshBB refreshBB, int builds = 100, int positions = 200, int cores = 8)
        {
            if (Running == true)
            {
                return;
            }
            _refreshBB = refreshBB;
            _refreshBB.Init();
            Running = true;
            opp.SoftReset();
            opp.Units             = UnitPool.Units.Where(x => x.Race == opp.Race && x.Cost > 0).ToList();
            _refreshBB.Bopp       = opp.GetString();
            _refreshBB.Bplayer    = player.GetString();
            _refreshBB.BestBuild  = _refreshBB.Bplayer;
            _refreshBB.WorstBuild = _refreshBB.Bplayer;

            _player = player;
            _opp    = opp;

            source   = new CancellationTokenSource();
            token    = source.Token;
            _empty   = new ManualResetEvent(false);
            CORES    = cores;
            MaxValue = 0;

            BUILDS                = builds;
            POSITIONS             = positions;
            _refreshBB.TOTAL_DONE = 0;
            _refreshBB.TOTAL      = builds * positions + builds;

            START = DateTime.UtcNow;
            END   = DateTime.MinValue;

            _jobs_build    = new BlockingCollection <BBuildJob>();
            _jobs_position = new BlockingCollection <BBuildJob>();

            foreach (Unit unit in player.Units.Where(y => y.Status != UnitStatuses.Available))
            {
                MaxValue += unit.Cost;
            }

            GameHistory game = new GameHistory();

            game.ID          = paxgame.GetGameID();
            game.battlefield = new Battlefield();
            Player myplayer = player.SoftCopy();
            Player myopp    = opp.SoftCopy();

            game.Players.Add(myplayer);
            myplayer.Game = game;
            game.Players.Add(myopp);
            myopp.Game = game;
            myplayer.SetString(_refreshBB.Bplayer);
            _refreshBB.MineralsCurrent = myplayer.MineralsCurrent;
            myopp.SetString(_refreshBB.Bopp);
            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];
            _refreshBB.BestStats         = result;
            _refreshBB.BestStatsOpp      = oppresult;

            for (int i = 0; i < BUILDS; i++)
            {
                BBuildJob job = new BBuildJob();
                job.PlayerBuild = _refreshBB.Bplayer;
                job.OppBuild    = _refreshBB.Bopp;
                job.Minerals    = _refreshBB.MineralsCurrent;
                _jobs_build.Add(job);
            }

            for (int i = 0; i < 1; i++)
            {
                Thread thread = new Thread(OnHandlerStartBuild)
                {
                    IsBackground = true
                };                      //Mark 'false' if you want to prevent program exit until jobs finish
                thread.Start();
            }

            for (int i = 0; i < 8; i++)
            {
                Thread thread = new Thread(OnHandlerStartPosition)
                {
                    IsBackground = true
                };                      //Mark 'false' if you want to prevent program exit until jobs finish
                thread.Start();
            }

            while (!_empty.WaitOne(1000))
            {
                Console.WriteLine(_jobs_position.Count + _jobs_build.Count);
                _refreshBB.Update = !_refreshBB.Update;
                if (!_jobs_position.Any())
                {
                    break;
                }
            }
            END               = DateTime.UtcNow;
            Running           = false;
            _refreshBB.Update = !_refreshBB.Update;
        }
Exemple #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);
        }