Пример #1
0
        // tells every client that the game is over
        private void SendGameOver(Player winner, VictoryType vtype)
        {
            ConsoleManager.Instance.WriteLine($"Game over! {winner.Name}, {controllers.Data.Empire.GetEmpire(winner.EmpireID).Name}, has won with a {vtype} victory", MsgType.ServerInfo);
            Packet pOut = new Packet((int)PacketHeader.GameOver, winner, vtype);

            server.SendDataToAll(pOut);
            StopServer();
        }
Пример #2
0
        // parses a packet with the header GameOver
        private void ParseGameOver(Packet p)
        {
            int         i      = 0;
            Player      winner = (Player)p.Items[i++];
            VictoryType vtype  = (VictoryType)p.Items[i++];

            ConsoleManager.Instance.WriteLine($"Game over! {winner.Name} of {winner.EmpireID} has won a {vtype} victory");
            Dissconnect();
            SceneManager.Instance.ChangeScene((int)Scene.Menu);
        }
Пример #3
0
    public void Init(VictoryType victoryType)
    {
        switch (victoryType)
        {
        case VictoryType.THIEVES_VICTORY:
            this.textMeshProUGUI.text = THIEVES_VICTORY;
            break;

        case VictoryType.VIGILS_VICTORY:
            this.textMeshProUGUI.text = VIGILS_VICTORY;
            break;
        }
        panel.SetActive(true);
        Invoke(nameof(ReturnToRoom), 3);
    }
Пример #4
0
    public void CmdSendPlay(int cellNumber)
    {
        if (ServerNetworking.Instance.makePlay(cellNumber, playerSymbol))
        {
            RpcRelayPlay(cellNumber, playerSymbol);
            VictoryType victoryCheck = ServerNetworking.Instance.checkEndGame();
            if (victoryCheck != VictoryType.None)
            {
                RpcRelayWinner(victoryCheck, playerSymbol);
            }

            //Update Turn
            ServerNetworking.Instance.updateTurn();
        }
    }
Пример #5
0
        /// <summary>
        /// Gets the actual score based on victory type.
        /// </summary>
        /// <param name="victoryType">The victory type.</param>
        /// <returns>Actual score.</returns>
        private static double GetActualScore(VictoryType victoryType)
        {
            switch (victoryType)
            {
            case VictoryType.Win:
                return(1);

            case VictoryType.Draw:
                return(0.5);

            case VictoryType.Loss:
                return(0);

            default:
                throw new VictoryTypeNotFoundException("Could not find victory type " + victoryType.ToString());
            }
        }
Пример #6
0
 public void EndGame(int cochesId, VictoryType type)
 {
     if (type == VictoryType.death)
     {
         if (cochesId == 0)
         {
             image2.SetActive(true);
             image4.SetActive(true);
         }
         if (cochesId == 1)
         {
             image.SetActive(true);
             image3.SetActive(true);
         }
     }
     else if (type == VictoryType.goal)
     {
         if (cochesId == 0)
         {
             image.SetActive(true);
             image3.SetActive(true);
         }
         if (cochesId == 1)
         {
             image2.SetActive(true);
             image4.SetActive(true);
         }
     }
     if (type == VictoryType.death)
     {
         for (int i = 0; i < coches.Length; i++)
         {
             coches[i].StopCar();
         }
     }
     Debug.Log("PARAR");
     if (type == VictoryType.goal)
     {
         for (int i = 0; i < coches.Length; i++)
         {
             coches[i].StopCar();
         }
     }
 }
Пример #7
0
    public bool CheckForVictory(List <Unit> units, int ShipsLeft, int EnemiesLeft, int roundNumber, VictoryType vt)
    {
        Debug.Log("checking victory state" + vt);
        switch (vt)
        {
        case VictoryType.waveSurvival:
            if (roundNumber > RoundsToSurvive)
            {
                return(true);
            }
            else
            {
                return(false);
            }

        case VictoryType.bossKill:
            //boss still in unit list = game keeps going
            return(bossDead);

        case VictoryType.destroyAll:
            if (EnemiesLeft <= 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }

        default:
            return(false);
        }
    }
Пример #8
0
 public GameOverType(string id, string reason, VictoryType victoryType) : base(id)
 {
     Reason      = reason;
     VictoryType = victoryType;
 }
Пример #9
0
 /// <summary>
 /// Initializes a new instance of the <c>GameEndedEventArgs</c> class.
 /// </summary>
 /// <param name="victor"></param>
 /// <param name="typeOfVictory"></param>
 public GameEndedEventArgs(Country victor, VictoryType typeOfVictory)
 {
     _victoryType = typeOfVictory;
     _victor      = victor;
 }
Пример #10
0
 private void RpcEndGame(VictoryType victoryType)
 {
     VictoryScreen.Instance.Init(victoryType);
 }
Пример #11
0
        private void Worker_DoWork(object sender, DoWorkEventArgs e)
        {
            List <Action>           games   = new List <Action>();
            List <TournamentResult> results = new List <TournamentResult>();

            int completedGames = 0;

            foreach (var engine1 in _players)
            {
                foreach (var engine2 in _players)
                {
                    if (engine1 != engine2 || _allowSelfPlay)
                    {
                        games.Add(() =>
                        {
                            Stopwatch killswitch = Stopwatch.StartNew();
                            VolcanoGame game     = new VolcanoGame();

                            VictoryType victory = VictoryType.None;
                            game.OnGameOver    += (p, v) => victory = v;

                            try
                            {
                                game.RegisterEngine(Player.One, _engines.GetEngine(engine1));
                                game.RegisterEngine(Player.Two, _engines.GetEngine(engine2));
                                game.SecondsPerEngineMove = _secondsPerMove;
                                game.StartNewGame();
                                game.ComputerPlay();

                                while (victory == VictoryType.None && game.CurrentState.Winner == Player.Empty && game.CurrentState.Turn < VolcanoGame.Settings.TournamentAdjudicateMaxTurns && killswitch.ElapsedMilliseconds < VolcanoGame.Settings.TournamentAdjudicateMaxSeconds * 1000)
                                {
                                    System.Threading.Thread.Sleep(100);
                                }

                                var termination = TournamentTerminationType.Normal;
                                if (game.CurrentState.Winner == Player.Empty)
                                {
                                    if (game.CurrentState.Turn >= VolcanoGame.Settings.TournamentAdjudicateMaxTurns)
                                    {
                                        termination = TournamentTerminationType.AdjudicateMoves;
                                    }
                                    else if (killswitch.ElapsedMilliseconds >= VolcanoGame.Settings.TournamentAdjudicateMaxSeconds * 1000)
                                    {
                                        termination = TournamentTerminationType.AdjudicateTime;
                                    }
                                }
                                if (victory == VictoryType.ArenaAdjudication)
                                {
                                    if (game.BackgroundError != null)
                                    {
                                        if (game.CurrentState.Winner == Player.One)
                                        {
                                            termination = TournamentTerminationType.PlayerTwoError;
                                        }
                                        else if (game.CurrentState.Winner == Player.Two)
                                        {
                                            termination = TournamentTerminationType.PlayerOneError;
                                        }
                                        else
                                        {
                                            termination = TournamentTerminationType.Error;
                                        }
                                    }
                                    else
                                    {
                                        termination = TournamentTerminationType.IllegalMove;
                                    }
                                }

                                lock (results)
                                {
                                    results.Add(new TournamentResult(game, engine1, engine2, termination, killswitch.ElapsedMilliseconds));
                                }
                            }
                            catch (Exception ex)
                            {
                                using (StreamWriter w = new StreamWriter("errors.txt", true))
                                {
                                    w.WriteLine("Failed to play \"" + engine1 + "\" and \"" + engine2 + "\"! :: " + ex.Message);
                                }

                                try
                                {
                                    var termination = game?.CurrentState?.Player == Player.One ? TournamentTerminationType.PlayerOneError : TournamentTerminationType.PlayerTwoError;

                                    lock (results)
                                    {
                                        results.Add(new TournamentResult(game, engine1, engine2, termination, killswitch.ElapsedMilliseconds));
                                    }
                                }
                                catch (Exception eotw)
                                {
                                    using (StreamWriter w2 = new StreamWriter("errors.txt", true))
                                    {
                                        w2.WriteLine("Failed to log result! :: " + eotw.Message);
                                    }
                                }
                            }

                            completedGames++;
                            worker.ReportProgress(0, new TournamentStatus(completedGames, totalGames));
                        });
                    }
                }
            }

            for (int r = 0; r < _rounds; r++)
            {
                Parallel.ForEach(games, x => x());
            }

            using (StreamWriter w = new StreamWriter(_gameDataFile))
            {
                w.WriteLine("Player_One,Player_Two,Winner,Termination,Total_Moves,Total_Milliseconds,Starting_Tile_Index,Transcript,Winning_Path,Win_Condition,Seconds_Per_Move");
                foreach (var result in results)
                {
                    string gameResult = "Draw";
                    if (result.PlayerOneScore > result.PlayerTwoScore)
                    {
                        gameResult = "One";
                    }
                    if (result.PlayerTwoScore > result.PlayerOneScore)
                    {
                        gameResult = "Two";
                    }

                    string transcript = "";
                    if (result.Moves.Count > 0)
                    {
                        try
                        {
                            transcript = result.Moves.Select(x => x.Tile + (VolcanoGame.Settings.IndicateTranscriptMoveType && x.Addition ? "+" : "")).Aggregate((c, n) => c + " " + n);
                        }
                        catch (Exception ex)
                        {
                            transcript = ex.Message;
                        }
                    }

                    string winningPath = "";
                    if (result.WinningPath != null && result.WinningPath.Count > 0)
                    {
                        try
                        {
                            winningPath = result.WinningPath.Select(x => Constants.TileNames[x]).Aggregate((c, n) => c + " " + n);
                        }
                        catch (Exception ex)
                        {
                            winningPath = ex.Message;
                        }
                    }

                    string winCondition = "";
                    if (result.WinCondition == 1)
                    {
                        winCondition = "Tie-breaker";
                    }
                    else
                    {
                        winCondition = "Normal Win (no tie-breaker)";
                    }

                    w.WriteLine(result.PlayerOne + "," + result.PlayerTwo + "," + gameResult + "," + result.Termination.ToString() + "," + result.TotalMoves + "," + result.ElapsedMilliseconds + "," + result.FirstTile + "," + transcript + "," + winningPath + "," + winCondition + "," + _secondsPerMove);
                }
            }

            List <TournamentResultLine> lines = new List <TournamentResultLine>();

            foreach (var engine1 in _players)
            {
                decimal score             = 0m;
                TournamentResultLine line = new TournamentResultLine();
                line.Name = engine1;
                foreach (var engine2 in _players)
                {
                    if (engine1 != engine2 || _allowSelfPlay)
                    {
                        decimal wins = results.Where(x => x.PlayerOne == engine1 && x.PlayerTwo == engine2).Sum(x => x.PlayerOneScore) + results.Where(x => x.PlayerOne == engine2 && x.PlayerTwo == engine1).Sum(x => x.PlayerTwoScore);
                        score += wins;
                        line.Data.Add(engine2, wins);
                    }
                    else
                    {
                        line.Data.Add(engine2, -1);
                    }
                }
                decimal total = results.Where(x => x.PlayerOne == engine1 || x.PlayerTwo == engine1).Count();
                line.TotalScore      = score;
                line.TotalPercentage = score * 100m / total;
                line.Score           = score;
                lines.Add(line);
            }

            lines.Sort((c, n) => n.Sort.CompareTo(c.Sort));

            List <string> names = new List <string>();

            for (int i = 0; i < lines.Count; i++)
            {
                lines[i].CrossTableName = (i + 1) + ". " + lines[i].Name;
                names.Add((i + 1).ToString());

                lines[i].NeustadtlScore = 0m;
                foreach (var opponent in lines)
                {
                    if (opponent.Name != lines[i].Name)
                    {
                        lines[i].NeustadtlScore += opponent.TotalScore * lines[i].Data[opponent.Name];
                    }
                }
            }

            // It doesn't make sense to save a cross table when there's only one person competing
            if (!string.IsNullOrEmpty(_crossTableFile) && lines.Count > 1)
            {
                using (StreamWriter w = new StreamWriter(_crossTableFile))
                {
                    // cs = common score
                    // ns = neustadtl score (figures in strength of opposition)
                    w.WriteLine("," + names.Aggregate((c, n) => c + "," + n) + ",cs,ns");
                    foreach (var player in lines)
                    {
                        w.Write(player.CrossTableName);
                        foreach (var opponent in lines)
                        {
                            string val = player.Data[opponent.Name] >= 0 ? player.Data[opponent.Name].ToString() : "";
                            w.Write("," + val);
                        }
                        w.Write(", " + player.TotalScore);
                        w.Write(", " + player.NeustadtlScore.ToString("0.00"));
                        w.WriteLine();
                    }
                }
            }
        }
Пример #12
0
        /// <summary>
        /// Calculates a new Elo rating for a player after a game.
        /// </summary>
        /// <param name="rating">Rating of the player.</param>
        /// <param name="opponentRating">Rating of the opponent.</param>
        /// <param name="totalGamesPlayed">Number of games the player has played.</param>
        /// <param name="victoryType">Type of victory: Win, Draw or Loss.</param>
        /// <returns></returns>
        public static int CalculateNewElo(int rating, int opponentRating, int totalGamesPlayed, VictoryType victoryType)
        {
            double ratingChange;

            // Find variables
            double kCoefficient  = GetKCoefficient(rating, totalGamesPlayed);
            double expectedScore = CalculateExpectedScore(rating, opponentRating);
            double actualScore   = GetActualScore(victoryType);

            // Calculate rating change
            ratingChange = kCoefficient * (actualScore - expectedScore);

            // Return new Elo
            return((int)Math.Round(rating + ratingChange));
        }
Пример #13
0
    //Display Winner
    public void displayWinner(VictoryType victoryType, bool winner)
    {
        //Outline Cells
        if (victoryType == VictoryType.Line1)
        {
            outlineCell(0);
            outlineCell(1);
            outlineCell(2);
        }
        else if (victoryType == VictoryType.Line2)
        {
            outlineCell(3);
            outlineCell(4);
            outlineCell(5);
        }
        else if (victoryType == VictoryType.Line3)
        {
            outlineCell(6);
            outlineCell(7);
            outlineCell(8);
        }
        else if (victoryType == VictoryType.Column1)
        {
            outlineCell(0);
            outlineCell(3);
            outlineCell(6);
        }
        else if (victoryType == VictoryType.Column2)
        {
            outlineCell(1);
            outlineCell(4);
            outlineCell(7);
        }
        else if (victoryType == VictoryType.Column3)
        {
            outlineCell(2);
            outlineCell(5);
            outlineCell(8);
        }
        else if (victoryType == VictoryType.MainDiagonal)
        {
            outlineCell(0);
            outlineCell(4);
            outlineCell(8);
        }
        else if (victoryType == VictoryType.SecondaryDiagonal)
        {
            outlineCell(2);
            outlineCell(4);
            outlineCell(6);
        }

        //Display Correct Message
        if (victoryType == VictoryType.Draw)
        {
            winnerPanel.GetComponentInChildren <Text>().text = "Draw";
        }
        else if (winner)
        {
            winnerPanel.GetComponentInChildren <Text>().text = "Victory!";
        }
        else
        {
            winnerPanel.GetComponentInChildren <Text>().text = "Defeat!";
        }

        //Enable Panel
        winnerPanel.SetActive(true);
    }
Пример #14
0
 public void RpcRelayWinner(VictoryType victoryType, Symbol winnerSymbol)
 {
     ServerNetworking.Instance.currentTurn = Player.None;
     GameView.Instance.displayWinner(victoryType, winnerSymbol == ClientNetworking.getLocalClientNetworking().playerSymbol);
 }
Пример #15
0
 private void VictoryToPlayer(int player)
 {
     if (player == 0){
         victory = VictoryType.playerOne;
     }else if(player == 1){
         victory = VictoryType.playerTwo;
     }
 }
Пример #16
0
        private void QueueGame(string engine1, string engine2)
        {
            games.Add(() =>
            {
                Stopwatch killswitch = Stopwatch.StartNew();
                VolcanoGame game     = new VolcanoGame();

                VictoryType victory = VictoryType.None;
                game.OnGameOver    += (p, v) => victory = v;

                try
                {
                    game.RegisterEngine(Player.One, _engines.GetEngine(engine1), true);
                    game.RegisterEngine(Player.Two, _engines.GetEngine(engine2), true);
                    game.SecondsPerEngineMove = _secondsPerMove;
                    game.StartNewGame();
                    game.ComputerPlay();

                    while (victory == VictoryType.None &&
                           game.CurrentState.Winner == Player.Empty &&
                           game.CurrentState.Turn < VolcanoGame.Settings.TournamentAdjudicateMaxTurns &&
                           killswitch.ElapsedMilliseconds < VolcanoGame.Settings.TournamentAdjudicateMaxSeconds * 1000)
                    {
                        System.Threading.Thread.Sleep(100);
                    }

                    game.ForceStop();

                    var termination = TournamentTerminationType.Normal;
                    if (game.CurrentState.Winner == Player.Empty)
                    {
                        if (game.CurrentState.Turn >= VolcanoGame.Settings.TournamentAdjudicateMaxTurns)
                        {
                            termination = TournamentTerminationType.AdjudicateMoves;
                        }
                        else if (killswitch.ElapsedMilliseconds >= VolcanoGame.Settings.TournamentAdjudicateMaxSeconds * 1000)
                        {
                            termination = TournamentTerminationType.AdjudicateTime;
                        }
                    }
                    if (victory == VictoryType.ArenaAdjudication)
                    {
                        if (game.BackgroundError != null)
                        {
                            if (game.CurrentState.Winner == Player.One)
                            {
                                termination = TournamentTerminationType.PlayerTwoError;
                            }
                            else if (game.CurrentState.Winner == Player.Two)
                            {
                                termination = TournamentTerminationType.PlayerOneError;
                            }
                            else
                            {
                                termination = TournamentTerminationType.Error;
                            }
                        }
                        else
                        {
                            termination = TournamentTerminationType.IllegalMove;
                        }
                    }
                    else if (victory == VictoryType.OpponentTimeout)
                    {
                        termination = TournamentTerminationType.Timeout;
                    }

                    lock (results)
                    {
                        results.Add(new TournamentResult(game, engine1, engine2, termination, killswitch.ElapsedMilliseconds));
                    }
                }
                catch (Exception ex)
                {
                    using (StreamWriter w = new StreamWriter("errors.txt", true))
                    {
                        w.WriteLine("Failed to play \"" + engine1 + "\" and \"" + engine2 + "\"! :: " + ex.Message);
                    }

                    try
                    {
                        var termination = game?.CurrentState?.Player == Player.One ? TournamentTerminationType.PlayerOneError : TournamentTerminationType.PlayerTwoError;

                        lock (results)
                        {
                            results.Add(new TournamentResult(game, engine1, engine2, termination, killswitch.ElapsedMilliseconds));
                        }
                    }
                    catch (Exception eotw)
                    {
                        using (StreamWriter w2 = new StreamWriter("errors.txt", true))
                        {
                            w2.WriteLine("Failed to log result! :: " + eotw.Message);
                        }
                    }
                }

                completedGames++;
                worker.ReportProgress(0, new TournamentStatus(completedGames, totalGames, timeouts));
            });
        }