Ejemplo n.º 1
0
        internal GameView(Board gameBoard, TwoPlayerGame gamePage)
        {
            _gameBoard = gameBoard;
            _gamePage  = gamePage;

            gameBoard.SquareTapped += OnBoardSquareClicked;
        }
Ejemplo n.º 2
0
        public IActionResult Post([FromBody] TwoPlayerGame model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Game game = new Game();

            var gamePlayers = new GamePlayer[]
            {
                new GamePlayer(model.playerOneId, 1, game.GameId, true),
                new GamePlayer(model.playerTwoId, 2, game.GameId, true)
            };

            foreach (GamePlayer g in gamePlayers)
            {
                context.GamePlayer.Add(g);
            }

            game.GamePlayers  = gamePlayers.ToList();
            game.TeamOneScore = model.teamOneScore;
            game.TeamTwoScore = model.teamTwoScore;

            //Check scores against each other to calculate Point Differential
            //and decide who won

            if (model.teamOneScore > model.teamTwoScore)
            {
                //Modify the GamePlayer instances
                gamePlayers[0].Won       = true;
                gamePlayers[0].PointDiff = (model.teamOneScore - model.teamTwoScore);
                gamePlayers[1].Won       = false;
                gamePlayers[1].PointDiff = (model.teamTwoScore - model.teamOneScore);

                //Modify the Stats classes for each player
                var playerOneStats = context.Stats.Single(s => s.PlayerId == model.playerOneId);
                var playerTwoStats = context.Stats.Single(s => s.PlayerId == model.playerTwoId);
                playerOneStats.AddWin();
                playerTwoStats.AddLoss();
            }
            else
            {
                gamePlayers[0].Won       = false;
                gamePlayers[0].PointDiff = (model.teamOneScore - model.teamTwoScore);
                gamePlayers[1].Won       = true;
                gamePlayers[1].PointDiff = (model.teamTwoScore - model.teamOneScore);

                //Modify the Stats classes for each player
                var playerOneStats = context.Stats.Single(s => s.PlayerId == model.playerOneId);
                var playerTwoStats = context.Stats.Single(s => s.PlayerId == model.playerTwoId);
                playerTwoStats.AddWin();
                playerOneStats.AddLoss();
            }

            context.Game.Add(game);
            context.SaveChanges();
            return(Ok(game));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Samples from the model.
        /// </summary>
        /// <param name="truth">The truth.</param>
        /// <param name="players">The players.</param>
        /// <param name="performanceVariance">The performance variance.</param>
        /// <param name="drawMargin">The draw margin.</param>
        /// <returns>
        /// The <see cref="Game" />.
        /// </returns>
        public static Game Sample(Marginals truth, IList <string> players, double performanceVariance, double drawMargin)
        {
            double perf1 = new Gaussian(truth.Skills[players[0]].GetMean(), performanceVariance).Sample();
            double perf2 = new Gaussian(truth.Skills[players[1]].GetMean(), performanceVariance).Sample();

            double       diff    = perf1 - perf2;
            MatchOutcome outcome = diff < drawMargin ? MatchOutcome.Draw : (diff > 0 ? MatchOutcome.Player1Win : MatchOutcome.Player2Win);

            return(TwoPlayerGame.CreateGame(Guid.NewGuid().ToString(), players[0], players[1], outcome));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Samples from the model.
        /// </summary>
        /// <param name="truth">The truth.</param>
        /// <param name="players">The players.</param>
        /// <param name="performanceVariance">The performance variance.</param>
        /// <returns>The <see cref="Game"/>.</returns>
        public static TwoPlayerGame Sample(Marginals truth, IList <string> players, double performanceVariance)
        {
            double perf1 = new Gaussian(truth.Skills[players[0]].GetMean(), performanceVariance).Sample();
            double perf2 = new Gaussian(truth.Skills[players[1]].GetMean(), performanceVariance).Sample();

            return(TwoPlayerGame.CreateGame(
                       Guid.NewGuid().ToString(),
                       players[0],
                       players[1],
                       perf1 > perf2 ? MatchOutcome.Player1Win : MatchOutcome.Player2Win));
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Predicts the outcome of a game.
 /// </summary>
 /// <param name="game">The game.</param>
 /// <param name="posteriors">The posteriors.</param>
 /// <returns>
 /// The <see cref="TwoPlayerPrediction" />.
 /// </returns>
 /// <exception cref="System.InvalidOperationException">Multi-player/team games not supported</exception>
 public TwoPlayerPrediction PredictOutcome(TwoPlayerGame game, Marginals posteriors)
 {
     return(new TwoPlayerPrediction
     {
         Actual = game.Outcome,
         Predicted =
             this.Parameters.IncludeDraws
                            ? (MatchOutcome)this.OutcomeDistribution.Sample()
                            : (Rand.Int(2) == 0 ? MatchOutcome.Player1Win : MatchOutcome.Player2Win),
         IncludeDraws = this.Parameters.IncludeDraws
     });
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Creates the toy inputs.
        /// </summary>
        /// <param name="matchOutcomes">The match outcomes.</param>
        /// <returns>The <see cref="Inputs{TwoPlayerGame}"/>.</returns>
        public static Inputs <TwoPlayerGame> CreateToyInputs(IEnumerable <MatchOutcome> matchOutcomes)
        {
            var inputs = new Inputs <TwoPlayerGame>
            {
                Mu    = 120,
                Sigma = 40,
                Beta  = 5,
                Gamma = 1.2,
                Games = new KeyedCollectionWithFunc <string, TwoPlayerGame>(ia => ia.Id),
            };

            inputs.Games.AddRange(matchOutcomes.Select((ia, i) => TwoPlayerGame.CreateGame(i.ToString("N"), Jill, Fred, ia)));

            return(inputs);
        }
Ejemplo n.º 7
0
    static void Main( )
    {
        bool xo = true;

        TwoPlayerGame twoplayer = new TwoPlayerGame(xo);
    }