Exemplo n.º 1
0
        public bool MakeMove(TicTacToeMove move)
        {
            var(player, i, j) = move;

            if (!CheckBounds(i, j))
            {
                return(false);
            }

            if (player.Mark == CurrentMove && Board[i, j] == TicTacToeMarkEnum.NaN)
            {
                Board[i, j] = player.Mark;
                CurrentMove = CurrentMove == TicTacToeMarkEnum.O ? TicTacToeMarkEnum.X : TicTacToeMarkEnum.O;
            }
            else
            {
                return(false);
            }

            // move is done
            GameHistory.Add(move);


            if (GameEnd())
            {
                OnGameEnd?.Invoke();
            }

            return(true);
        }
Exemplo n.º 2
0
 public GameController(IGameService gameSevice, IPlayerService playerService, ICommandController commandController)
 {
     this.gameService       = gameSevice;
     this.playerService     = playerService;
     this.commandController = commandController;
     gameHistory            = new GameHistory();
 }
Exemplo n.º 3
0
        private async Task <GameHistory> ComputeNewUserPoints(GameHistory gameHistory)
        {
            var users = new Dictionary <string, User>();

            foreach (var(playerId, player) in gameHistory.Summary.Players)
            {
                users[playerId] = await this.Repository.GetUserById(player.WebsiteId !.Value).ConfigureAwait(false);
            }

            var match = new EloMatch();

            var eloPlayers = gameHistory.Summary.Players.Aggregate(new Dictionary <string, IEloPlayer>(), (acc, kvp) =>
            {
                var user     = users[kvp.Key];
                acc[kvp.Key] = match.AddPlayer(kvp.Value.Rank, user.Points);
                return(acc);
            });

            match.ComputeElos();

            foreach (var(playerId, player) in gameHistory.Summary.Players)
            {
                player.Points      = eloPlayers[playerId].NewElo;
                player.DeltaPoints = eloPlayers[playerId].EloChange;
            }

            return(gameHistory);
        }
Exemplo n.º 4
0
        private GameHistory CreatGameHistory(UserGameKey userGameKey, GameResult result)
        {
            var history = new GameHistory
            {
                DateTimeUtc       = result.DateTimeUtc,
                GameTransactionId = result.TransactionId,
                SpinTransactionId = result.SpinTransactionId,
                UserId            = userGameKey.UserId,
                GameId            = userGameKey.GameId,
                Level             = result.Level,
                Bet            = result.Bet,
                Win            = result.Win,
                ExchangeRate   = result.ExchangeRate.GetValueOrDefault(),
                GameResultType = result.GameResultType,
                XmlType        = result.XmlType,
                ResponseXml    = xmlhelper.Serialize(result.ToResponseXml(ResponseXmlFormat.None)),
                HistoryXml     = xmlhelper.Serialize(result.ToResponseXml(ResponseXmlFormat.Legacy | ResponseXmlFormat.History)),
                IsFreeGame     = userGameKey.IsFreeGame,
                IsHistory      = result.IsHistory,
                IsReport       = result.IsReport,
                PlatformType   = result.PlatformType,
                RoundId        = result.RoundId
            };

            return(history);
        }
Exemplo n.º 5
0
 public Server(int numPlayers)
 {
     _gameLock        = new object();
     _gameHistory     = new GameHistory(120);
     _curPlayerInputs = new Dictionary <byte, PlayerInputs>();
     Start(numPlayers).Wait();
 }
Exemplo n.º 6
0
        private void DisplayBonusFreeSpinHistory(GameHistory history)
        {
            var xmlHelper = new XmlHelper();

            BonusXml    = xmlHelper.Deserialize <BonusXml>(history.HistoryXml);
            HistoryType = HistoryType.BFS;
            History     = new List <History>();

            if (BonusXml.Data.Element("history") != null)
            {
                var steps = BonusXml.Data.Element("history").Elements("step").ToArray();
                if (steps != null)
                {
                    foreach (var step in steps)
                    {
                        string rname = "Multiplier";

                        switch (step.Attribute("typew").Value)
                        {
                        case "FS": rname = "Free Spin"; break;

                        case "mode": rname = "Mode"; break;

                        case "wmul": rname = "Wild Multiplier"; break;
                        }

                        History.Add(new History
                        {
                            result = rname,
                            value  = step.Attribute("value").Value
                        });
                    }
                }
            }
        }
Exemplo n.º 7
0
        public void GameHistoryTest()
        {
            GameHistory gameHistory = new GameHistory();
            Game        game        = new Game(new StartMenu());

            game.GenerateNewGame();

            var robotEnegry = game.Robot.BatteryCharge;

            game.State = new GameProcess();

            Assert.AreEqual(game.Robot.BatteryCharge, robotEnegry);

            gameHistory.Add(new GameMemento(game.Robot.SaveState(), game.MoveCounter, (Map)game.Map.Clone()));
            var res = game.Turn("next");

            Assert.AreEqual(res, "In fronr of you lies: " + game.Map.Stones[1].GetInfo() + "\r\nWhat will U do?\r\n\r\n"
                            + (game.Robot is Cyborg ? "Turns harm: 0, battery charge: " : "Battery charge: ") +
                            +(robotEnegry - 1) + ", battery lost: " + 1 + ", ");
            Assert.AreEqual(game.Robot.BatteryCharge, robotEnegry - 1);

            game.Robot.RestoreState(gameHistory.GetLastState().GetRobotMemento());

            Assert.AreEqual(game.Robot.BatteryCharge, robotEnegry);
        }
Exemplo n.º 8
0
 public Client(string name)
 {
     _name               = name;
     _gameHistory        = new GameHistory(2048);
     _unityGameStepNum   = 0;
     _highestGameStepNum = 0;
 }
        private void DisplayDoubleUpHistory(GameHistory history)
        {
            var xmlHelper = new XmlHelper();

            BonusXml    = xmlHelper.Deserialize <BonusXml>(history.HistoryXml);
            HistoryType = HistoryType.DoubleUp;
            History     = new List <History>();

            if (BonusXml.Data.Element("history") != null)
            {
                var steps = BonusXml.Data.Element("history").Elements("step").ToArray();
                if (steps != null)
                {
                    foreach (var step in steps)
                    {
                        History.Add(new History
                        {
                            selected = DoubleUpDescription[history.Game.Id][step.Attribute("selected").Value],
                            result   = DoubleUpDescription[history.Game.Id][step.Attribute("result").Value],
                            value    = step.Attribute("value").Value
                        });
                    }
                }
            }
        }
Exemplo n.º 10
0
        public void TieBreakNotTheSameNumberOfCardTest()
        {
            Dictionary <int, HandWarGame <CardWarGame> > players = new Dictionary <int, HandWarGame <CardWarGame> >();

            HandWarGame <CardWarGame> Hand1 = new HandWarGame <CardWarGame>();

            Hand1.AddCard(new CardWarGame(CardValueEnum.Five, CardColorEnum.Spade));
            Hand1.AddCard(new CardWarGame(CardValueEnum.Ace, CardColorEnum.Spade));

            HandWarGame <CardWarGame> Hand2 = new HandWarGame <CardWarGame>();

            Hand2.AddCard(new CardWarGame(CardValueEnum.Five, CardColorEnum.Clover));
            Hand2.AddCard(new CardWarGame(CardValueEnum.Three, CardColorEnum.Clover));
            Hand2.AddCard(new CardWarGame(CardValueEnum.King, CardColorEnum.Clover));

            players.Add(1, Hand1);
            players.Add(2, Hand2);

            GameWar dealerWarGame = new GameWar(players);

            dealerWarGame.Play();
            GameHistory history = dealerWarGame.GetHistory();

            Assert.AreEqual(2, history.GetWinner());
        }
Exemplo n.º 11
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.º 12
0
        public void SaveGameToHistory(Game currentGame)
        {
            string winnerName = null;
            string loserName  = null;
            bool   isDraw     = false;

            if (currentGame.Winner == null)
            {
                winnerName = currentGame.Player1.Name;
                loserName  = currentGame.Player2.Name;
                isDraw     = true;
            }
            else
            {
                winnerName = currentGame.Winner.Name;
                loserName  = winnerName == currentGame.Player1.Name ? currentGame.Player2.Name : currentGame.Player1.Name;
            }
            var gameHistory = new GameHistory()
            {
                WinnerId  = _dbContext.Users.Where(u => u.UserName == winnerName).First().Id,
                LoserId   = _dbContext.Users.Where(u => u.UserName == loserName).First().Id,
                StartTime = currentGame.StartTime,
                EndTime   = DateTime.Now,
                IsDraw    = isDraw
            };

            _dbContext.GameHistoryList.Add(gameHistory);
            _dbContext.SaveChanges();
        }
Exemplo n.º 13
0
 public void RequestHistory()
 {
     Debug.Log("Requesting full game history");
     GameHistory response = client.requestHistory(new HistoryRequest {
         PlayerID = 1, GameID = 1
     });
 }
Exemplo n.º 14
0
 public HistoryViewModel(ServiceRecord serviceRecord, VariantClass variantClass, uint page, GameHistory gameHistory)
     : base(serviceRecord)
 {
     VariantClass = variantClass;
     Page         = page;
     GameHistory  = gameHistory;
 }
Exemplo n.º 15
0
        public void TestModelIntegrity()
        {
            GameHistory history = new GameHistory("../../../COMP7082/bin/debug/gamehistory.bin");

            if (history.games.Count <= 0)
            {
                Assert.Inconclusive("History empty.");
            }

            foreach (Game g in history.games)
            {
                Assert.IsNotNull(g.player);
                Assert.IsTrue(g.player.Length > 0);

                Assert.IsNotNull(g.opponent);
                Assert.IsTrue(g.opponent.Length > 0);

                Assert.IsNotNull(g.stage);
                Assert.IsTrue(g.stage.Length > 0);

                DateTime date = DateTime.Parse(g.timeStamp);
                Assert.IsNotNull(date);
                Assert.IsTrue(date < DateTime.UtcNow);
            }
        }
Exemplo n.º 16
0
 public HistoryViewModel(ServiceRecord serviceRecord, GameHistory <T> gameHistory, GameMode gameMode, int page) :
     base(serviceRecord)
 {
     GameHistory = gameHistory;
     GameMode    = gameMode;
     Page        = page;
 }
Exemplo n.º 17
0
        public ComputerPong()
        {
            myLatestSave = new SaveGame();
            mySaveGameXML = new XMLHelper<SaveGame>();

            myGameTime = DateTime.Now;

            //Transition Time
            TransitionOnTime = TimeSpan.FromSeconds(mySettings.TransitionOnTime);
            TransitionOffTime = TimeSpan.FromSeconds(mySettings.TransitionOffTime);

            //Load Player Info
            myPlayers = new GamePlayers();
            myPlayersXML = new XMLHelper<GamePlayers>();
            myPlayersXML.Load(ref myPlayers);

            //Load GameHistory
            myGameHistoryXML = new XMLHelper<GameHistory>();
            myGameList = new GameHistory();
            myGameHistoryXML.Load(ref myGameList);

            //Load Game Objects
            ObstaclePosition = new Obstacle(mySettings.MaxWidth / 2 - 10, mySettings.MaxHeight / 2 - 80);
            BallPosition = new Ball(mySettings.MaxWidth / 2 - 10, mySettings.MaxHeight / 2 - 10);
            RightPaddlePosition = new Paddle(mySettings.MaxWidth - 25, mySettings.MaxHeight / 2 - 40, mySettings.PaddleMoveFactor);
            LeftPaddlePosition = new Paddle(10, mySettings.MaxHeight / 2 - 40, mySettings.PaddleMoveFactor);
            playerPosition = new Vector2(mySettings.InitPosX, mySettings.InitPosY);
            enemyPosition = new Vector2(mySettings.InitPosX, mySettings.InitPosY);

            //Check if Both Users are In System or if Quick Play is Enabled
            if (myPlayers.myPlayers.Length != mySettings.NumberOfPlayers && !mySettings.QuickPlay)
                throw new Exception("There Need to be " + mySettings.NumberOfPlayers + " Active users in the system");
        }
Exemplo n.º 18
0
        public static float GetScore(GameHistory game, int minerals)
        {
            float reward    = 0;
            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;

            float fmins   = (float)minerals;
            float scoreP1 = (((float)rgame.MinValueP1 / fmins) * 2 + ((float)rgame.DamageP1 / fmins)) / 3;
            float scoreP2 = (((float)rgame.MinValueP2 / fmins) * 2 + ((float)rgame.DamageP2 / fmins)) / 3;

            reward = scoreP1 + 1 - scoreP2;
            reward = MathF.Round(reward, 1, MidpointRounding.AwayFromZero);
            return(reward);
        }
Exemplo n.º 19
0
        public async Task ResumeGameAsync()
        {
            var gameHistoryEntry = GameHistory.Last();

            Game.SetPreview(gameHistoryEntry.History.Last().BoardState);
            await PlayGameAsync(gameHistoryEntry);
        }
Exemplo n.º 20
0
        public async Task GameTurn(CancellationTokenSource cancellationTokenSource)
        {
            if (PlayerOnTurn.IsAI)
            {
                await(PlayerOnTurn.TryToPlay(GameBoard, cancellationTokenSource));
            }
            if (!cancellationTokenSource.IsCancellationRequested)
            {
                if (!PlayerOnTurn.Finished)
                {
                    await PlayerOnTurn.Selection(ToIntToRow(SelectedPosition), ToIntToCol(SelectedPosition), GameBoard, cancellationTokenSource);

                    if (PlayerOnTurn.PlayerMove[(int)GameConstants.MoveParts.result] == (int)GameConstants.MoveResult.Fail && !PlayerOnTurn.StartPositionSelected)
                    {
                        SelectedPosition = "none - Failed Move, Play again.";
                    }
                }
                if (PlayerOnTurn.Finished)
                {
                    GameHistory.Push(new List <int>(PlayerOnTurn.PlayerMove));
                    PlayerOnTurn.PlayerMove.ForEach(Console.Write);
                    PlayerOnTurn.Finished = false;
                    CheckEndGame();
                    RedoStack.Clear();
                    BestMove = null;
                    EndTurn();
                }
            }
        }
Exemplo n.º 21
0
    public static JSONNode GetUserInfo()
    {
        //string requestString = String.Format("http://182.18.139.143/WITSCLOUD/DEVELOPMENT/dartweb/index.php/api/getUserInfo");
        string         requestString = String.Format("https://dartbet.io/index.php/api/getUserInfo");
        HttpWebRequest request       = (HttpWebRequest)WebRequest.Create(requestString);

        //request.Headers.Add("Authorization", "Bearer "+GameManager.userToken);
        request.Headers.Add("token", GameManager.userToken);
        request.Timeout = 9000;
        request.Method  = "POST";

        HttpWebResponse response     = (HttpWebResponse)request.GetResponse();
        StreamReader    reader       = new StreamReader(response.GetResponseStream());
        string          jsonResponse = reader.ReadToEnd();
        JSONNode        jsonNode     = SimpleJSON.JSON.Parse(jsonResponse);

        string status = jsonNode["status"].Value;

        if (status == "Success")
        {
            GameManager.userInfo = JsonUtility.FromJson <UserInfo>(jsonNode["userData"].ToString());
            List <GameHistory> tempGameHistory = new List <GameHistory>();
            for (int i = 0; i < 3; i++)
            {
                GameHistory gh = JsonUtility.FromJson <GameHistory>(jsonNode["gameData"][i].ToString());
                tempGameHistory.Add(gh);
            }
            GameManager.gameHistory = tempGameHistory;
        }

        return(jsonNode);
    }
        private void DisplayGambleHistory(GameHistory history)
        {
            var xmlHelper = new XmlHelper();

            BonusXml    = xmlHelper.Deserialize <BonusXml>(history.HistoryXml);
            HistoryType = HistoryType.Gamble;
            History     = new List <History>();

            if (BonusXml.Data.Element("history") != null)
            {
                var steps = BonusXml.Data.Element("history").Elements("step").ToArray();
                if (steps?.Length > 0)
                {
                    foreach (var step in steps)
                    {
                        History.Add(new History
                        {
                            selected = step.Attribute("selected").Value == "1" ? "Double Half" : "Double",
                            bet      = step.Attribute("bet").Value,
                            value    = step.Attribute("value").Value,
                            dcard    = step.Attribute("dcard").Value,
                            pcard    = step.Attribute("pcard").Value
                        });
                    }
                }
            }
        }
Exemplo n.º 23
0
        private string CheckForStalemate(string board)
        {
            if (GameHistory.Count > 1)
            {
                List <char[]> lastTwoMoves = GameHistory
                                             .Skip(GameHistory.Count - 2)
                                             .Select(m => m.ToCharArray())
                                             .ToList()
                ;

                char[] lastMove = lastTwoMoves.First();
                char[] thisMove = lastTwoMoves.Last();

                //50 Move Rule
                string result = Stalemate_50MoveRule(lastMove, thisMove);
                if (result != "GameOn")
                {
                    return(result);
                }


                //Solitary King vs too few pieces.
                result = Stalemate_TooFewPieces(thisMove);
                if (result != "GameOn")
                {
                    return(result);
                }
            }
            ;

            return("GameOn");
        }
Exemplo n.º 24
0
        public static long NewRESTGame()
        {
            Player _player = new Player();

            _player.Pos  = 1;
            _player.Race = UnitRace.Terran;
            _player.ID   = paxgame.GetPlayerID();
            _player.Name = "Terran AI " + _player.ID;
            _player.Mode = new GameMode();

            Player _opp = new Player();

            _opp.Pos  = 4;
            _opp.Race = UnitRace.Terran;
            _opp.ID   = paxgame.GetPlayerID();
            _opp.Name = "Terran Bot " + _opp.ID;

            GameHistory game = new GameHistory();

            game.ID = paxgame.GetGameID();
            game.Players.Add(_player);
            game.Players.Add(_opp);
            _player.Game  = game;
            _opp.Game     = game;
            _player.Units = UnitPool.Units.Where(x => x.Race == _player.Race && x.Cost > 0).ToList();
            _opp.Units    = UnitPool.Units.Where(x => x.Race == _opp.Race && x.Cost > 0).ToList();

            _data.SetGame(game);
            _data.SetPlayer(_player);
            _data.SetPlayer(_opp);
            return((long)game.ID);
        }
Exemplo n.º 25
0
        /// <summary>
        /// Startet - abhängig davon, ob die KI zufällig oder lernend ist- die Funktion MakeTurn des Objektes AI.
        /// Im Anschluss werden die Funktionen für das Spielende, Spielerwechsel und die Aktualisierung der View aufgerufen.
        ///
        /// Speichert die Ausgangslage (GameHistory) und die erfolgte Entscheidung(DecisionHistory) in den entsprechenden Variablen.
        /// </summary>
        /// <param name="learning_AI"> Ist die KI eine lernende KI?</param>
        private void MakeTurn_AI(Boolean learning_AI)
        {
            //aktuelle Spielsituation wird gespeichert
            GameHistory.Add(GameState.Board.Clone() as int[]);

            if (!learning_AI)
            {
                GameState.Board = AI.Random_MakeTurn(GameState.Board, GameState.ActivePlayer);
            }
            else if (learning_AI)
            {
                GameState.Board = AI.Learning_MakeTurn(GameState.Board, GameState.ActivePlayer);
            }

            //Entscheidung der KI wird gespeichert, nachdem der letzte Zug der KI ermittelt wurde.
            for (int i = 0; i < 9; i++)
            {
                if (GameState.Board[i] != GameHistory.Last()[i] &&
                    GameState.Board[i] == GameState.ActivePlayer)
                {
                    DecisionHistory.Add(i);
                }
            }
            TestForEndCondition();
            PlayerChange();
            SendInformationToVM();
        }
Exemplo n.º 26
0
        public void UpdateGame(GameHistory gameHistory)
        {
            var gameData = gameHistory.Data;

            RedCar00.Visibility = RedCarVisibility(gameData[0, 0]);
            RedCar01.Visibility = RedCarVisibility(gameData[0, 1]);
            RedCar02.Visibility = RedCarVisibility(gameData[0, 2]);

            RedCar10.Visibility = RedCarVisibility(gameData[1, 0]);
            RedCar11.Visibility = RedCarVisibility(gameData[1, 1]);
            RedCar12.Visibility = RedCarVisibility(gameData[1, 2]);

            RedCar20.Visibility = RedCarVisibility(gameData[2, 0]);
            RedCar21.Visibility = RedCarVisibility(gameData[2, 1]);
            RedCar22.Visibility = RedCarVisibility(gameData[2, 2]);

            RedCar30.Visibility = RedCarVisibility(gameData[3, 0]);
            RedCar31.Visibility = RedCarVisibility(gameData[3, 1]);
            RedCar32.Visibility = RedCarVisibility(gameData[3, 2]);

            YellowCar0.Visibility = YellowCarVisibility(gameData[3, 0]);
            YellowCar1.Visibility = YellowCarVisibility(gameData[3, 1]);
            YellowCar2.Visibility = YellowCarVisibility(gameData[3, 2]);

            Bang0.Visibility = BangVisibility(gameData[3, 0]);
            Bang1.Visibility = BangVisibility(gameData[3, 1]);
            Bang2.Visibility = BangVisibility(gameData[3, 2]);

            ScoreValue.Content  = gameHistory.Score;
            FinishValue.Content = gameHistory.Finish;
            GameOver.Visibility = gameHistory.GameOver.ToVisibility();
            Finished.Visibility = gameHistory.Finished.ToVisibility();
        }
Exemplo n.º 27
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));
        }
Exemplo n.º 28
0
        public void ReturnASingleGameResultFromDatabase()
        {
            var result = new GameHistory().GetSingleGameHistory(1);


            result.Count.ShouldBe(1);
            result[0].Result.ShouldBe("W");
        }
Exemplo n.º 29
0
 public void Insert(GameHistory history)
 {
     _GameHistories.Add(history);
     if (_GameHistories.Count > 5)
     {
         _GameHistories.RemoveAt(0);
     }
 }
Exemplo n.º 30
0
    private void OnGameHistoryReceived(object _data)
    {
        GameHistory    gameHistory    = JsonConvert.DeserializeObject <GameHistory>(_data.ToString());
        MatchHistoryGO matchHistoryGO = Instantiate(GameHistoryGO, HistoryContentPlaceholder.transform).GetComponent <MatchHistoryGO>();

        matchHistoryGO.Initialize(gameHistory);
        gameHistories.Add(matchHistoryGO);
    }
Exemplo n.º 31
0
        public static Unit UnitEventToUnit(UnitEvent unit, int pos, GameHistory game)
        {
            Vector2 vec  = MoveService.RotatePoint(new Vector2(unit.x, unit.y), center, -45);
            float   newx = 0;

            // postition 1-3 => 4-6 and 4-6 => 1-3 ...
            if (pos > 3)
            {
                newx = ((vec.X - 62.946175f) / 2);
            }
            else if (pos <= 3)
            {
                newx = ((vec.X - 177.49748f) / 2);
            }

            float newy = vec.Y - 107.686295f;

            // Team2
            // Ymax: 131,72792 => Battlefield.YMax
            // Ymin: 107,686295 => 0

            // Xmax: 78,502525 => 10
            // Xmin: 62,946175 => 0

            // Fix Names
            if (unit.Name.EndsWith("Lightweight"))
            {
                unit.Name = unit.Name.Replace("Lightweight", "");
            }

            if (unit.Name.EndsWith("Starlight"))
            {
                unit.Name = unit.Name.Replace("Starlight", "");
            }

            Unit punit  = null;
            Unit myunit = UnitPool.Units.SingleOrDefault(x => x.Name == unit.Name);

            if (myunit == null)
            {
                myunit      = UnitPool.Units.SingleOrDefault(x => x.Name == "NA").DeepCopy();
                myunit.Name = unit.Name;
            }

            if (myunit != null)
            {
                punit    = myunit.DeepCopy();
                punit.ID = game.GetUnitID();

                newx = MathF.Round((MathF.Round(newx * 2, MidpointRounding.AwayFromZero) / 2), 1);
                newy = MathF.Round((MathF.Round(newy * 2, MidpointRounding.AwayFromZero) / 2), 1);

                punit.PlacePos = new Vector2(newy, newx);
                punit.Owner    = pos;
            }

            return(punit);
        }
Exemplo n.º 32
0
        public GameManager()
        {
            History = new GameHistory();
            _board = new GameBoard();
            _aiEngine = new Minimax();

            _aiEngine.BestMoveChosen += new EventHandler(_aiEngine_BestMoveChosen);

            CurrentPlayer = PlayerColor.White;
        }
        public static CloudBallGameReplay Create(GameHistory history)
        {
            var game = new CloudBallGameReplay()
            {
                Turns = new List<CloudBallTurnReplay>(),
                TeamRed = history.Team1Name,
                TeamBlue = history.Team2Name,
            };

            int scoreRed = 0;
            int socreBlue = 0;

            foreach (var s in history)
            {
                var turn = new CloudBallTurnReplay()
                {
                    Players = new List<CloudBallPlayerReplay>(),
                    Turn = game.Turns.Count,
                };

                turn.RedScored = s.GetScore.Team1Score > scoreRed;
                turn.BlueScored = s.GetScore.Team2Score > socreBlue;

                scoreRed = s.GetScore.Team1Score;
                socreBlue = s.GetScore.Team2Score;

                turn.Ball = new CloudBallBallReplay() { X = s.GetBall.Pos.X, Y = s.GetBall.Pos.Y };

                var r = s.GetTeams[0];
                var b = s.GetTeams[1];

                for (int i = 0; i < 6; i++)
                {
                    var rp = r.GetPlayers[i];
                    var bp = b.GetPlayers[i];

                    turn.Players.Add(new CloudBallPlayerReplay() { F = rp.HasFallen(), X = rp.Pos.X, Y = rp.Pos.Y, N = (int)rp.PlayerType, T = 0 });
                    turn.Players.Add(new CloudBallPlayerReplay() { F = bp.HasFallen(), X = bp.Pos.X, Y = bp.Pos.Y, N = (int)bp.PlayerType, T = 1 });
                }
                game.Turns.Add(turn);
            }

            return game;
        }