Esempio n. 1
0
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            ScoringType scoringtype = (ScoringType)value;

            switch (scoringtype)
            {
            case ScoringType.Score:
                writer.WriteValue("0");
                break;

            case ScoringType.Accuracy:
                writer.WriteValue("1");
                break;

            case ScoringType.Combo:
                writer.WriteValue("2");
                break;

            case ScoringType.Scorev2:
                writer.WriteValue("3");
                break;

            default:
                writer.WriteNull();
                break;
            }
        }
Esempio n. 2
0
        public void Score(ScoringType scoringType)
        {
            // Clear old scores:
            foreach (Pair pair in Pairs)
            {
                pair.Score = 0;
            }
            // Score all sessions
            if (scoringType == ScoringType.MatchPoints)
            {
                _scoringEngine = new MatchPointsScoringEngine();
            }
            else if (scoringType == ScoringType.IMPsAcross)
            {
                _scoringEngine = new IMPsAcrossScoringEngine();
            }
            var results = new List <BoardResult>();

            foreach (Session session in Sessions)
            {
                results.AddRange(session.Score(_scoringEngine));
            }
            // Aggregate pair scores
            foreach (BoardResult br in results)
            {
                foreach (Result result in br.Results)
                {
                    result.Table.NorthSouthPair.Score += result.NorthSouthScore;
                    result.Table.EastWestPair.Score   -= result.NorthSouthScore;
                }
            }
            // Sort Pair list:
            Pairs.Sort();
        }
        public ICollection <Player> GetPlayers(ScoringType scoringType)
        {
            string url;

            if (scoringType.Equals(ScoringType.HalfPPR))
            {
                url = configuration["FantasyPros:HalfPointPPR"];
            }
            else if (scoringType.Equals(ScoringType.PPR))
            {
                url = configuration["FantasyPros:PPR"];
            }
            else
            {
                url = configuration["FantasyPros:Standard"];
            }

            HashSet <Player> players = new HashSet <Player>();

            HtmlWeb htmlWeb = new HtmlWeb();

            HtmlDocument doc;

            try
            {
                doc = htmlWeb.Load(url);
            }
            catch (Exception)
            {
                return(players);
            }

            var node = doc.DocumentNode.SelectNodes("//*[@id=\"data\"]/tbody/tr");

            int intRank = 0;

            foreach (var child in node)
            {
                var rank = child.ChildNodes[0].InnerText;
                try
                {
                    int.TryParse(rank, out intRank);
                }
                catch (Exception)
                {
                }
                var name     = child.ChildNodes[2].InnerText;
                var position = child.ChildNodes[4].InnerText;
                var link     = "https://fantasypros.com" + child.ChildNodes[2].FirstChild.Attributes.AttributesWithName("href").FirstOrDefault().Value;

                players.Add(new Player {
                    Rank = intRank, Name = name, Position = position, PlayerUrl = link
                });
            }

            return(players);
        }
        private PlayerScore GetScoreItem(PlayerStatsOnDate playerInfo, ScoringType type)
        {
            var item = playerInfo.PlayerScores.SingleOrDefault(x => x.ScoringType.Name == type.Name);

            if (item == null)
            {
                item = new PlayerScore
                {
                    ScoringType = type,
                    Total       = 0
                };
                playerInfo.PlayerScores.Add(item);
            }
            return(item);
        }
        public string GetUrl(ScoringType scoringType)
        {
            var result = configuration["FantasyPros:Standard"];

            if (scoringType.Equals(ScoringType.HalfPPR))
            {
                result = configuration["FantasyPros:HalfPointPPR"];
            }
            else if (scoringType.Equals(ScoringType.PPR))
            {
                result = configuration["FantasyPros:PPR"];
            }

            return(result);
        }
Esempio n. 6
0
        public void ChangeSettings(MultiplayerRoom room)
        {
            MatchType    = room.MatchType;
            ActiveMods   = room.ActiveMods;
            Name         = room.Name;
            BeatmapName  = room.BeatmapName;
            BeatmapId    = room.BeatmapId;
            BeatmapMd5   = room.BeatmapMd5;
            HostId       = room.HostId;
            PlayMode     = room.PlayMode;
            ScoringType  = room.ScoringType;
            TeamType     = room.TeamType;
            SpecialModes = room.SpecialModes;
            Seed         = room.Seed;

            SetMods(ActiveMods, GetSlotByUserId(HostId));
            Update();
        }
Esempio n. 7
0
        public void ReadFromStream(MStreamReader sr)
        {
            MatchId     = sr.ReadInt16();
            InProgress  = sr.ReadBoolean();
            MatchType   = (MatchType)sr.ReadByte();
            ActiveMods  = (Mod)sr.ReadUInt32();
            Name        = sr.ReadString();
            Password    = sr.ReadString();
            BeatmapName = sr.ReadString();
            BeatmapId   = sr.ReadInt32();
            BeatmapMd5  = sr.ReadString();

            for (var i = 0; i < MaxPlayers; i++)
            {
                Slots[i].Status = (MultiSlotStatus)sr.ReadByte();
            }

            for (var i = 0; i < MaxPlayers; i++)
            {
                Slots[i].Team = (MultiSlotTeam)sr.ReadByte();
            }

            for (var i = 0; i < MaxPlayers; i++)
            {
                Slots[i].UserId = (Slots[i].Status & (MultiSlotStatus)124) > 0 ? sr.ReadInt32() : -1;
            }

            HostId       = sr.ReadInt32();
            PlayMode     = (PlayMode)sr.ReadByte();
            ScoringType  = (ScoringType)sr.ReadByte();
            TeamType     = (TeamType)sr.ReadByte();
            SpecialModes = (MatchSpecialModes)sr.ReadByte();

            if (SpecialModes == MatchSpecialModes.Freemods)
            {
                for (var i = 0; i < MaxPlayers; i++)
                {
                    Slots[i].Mods = (Mod)sr.ReadUInt32();
                }
            }

            Seed = sr.ReadInt32();
        }
        public string GetPageHeading(ScoringType type)
        {
            var heading = "";

            if (type.Equals(ScoringType.HalfPPR))
            {
                heading = "Half Point PPR";
            }
            else if (type.Equals(ScoringType.PPR))
            {
                heading = "PPR";
            }
            else
            {
                heading = "Standard";
            }

            return(heading);
        }
Esempio n. 9
0
        public void ChangeSettings(Match room)
        {
            MatchType    = room.MatchType;
            Name         = room.Name;
            BeatmapName  = room.BeatmapName;
            BeatmapId    = room.BeatmapId;
            BeatmapMd5   = room.BeatmapMd5;
            HostId       = room.HostId;
            PlayMode     = room.PlayMode;
            ScoringType  = room.ScoringType;
            TeamType     = room.TeamType;
            Seed         = room.Seed;
            SpecialModes = room.SpecialModes;
            ActiveMods   = room.ActiveMods;

            if (SpecialModes == MatchSpecialModes.Normal)
            {
                SetMods(ActiveMods, GetSlotByUserId(HostId));
            }
        }
Esempio n. 10
0
        private void UpdateScores(Mobile died, Mobile killer)
        {
            if (m_ScoreTable == null)
            {
                return;
            }

            ScoreKeeper scoreKeeper;

            double pointValue = ScoreModifier;

            if (died != null && m_ScoreTable.TryGetValue(died.Serial, out scoreKeeper))
            {
                pointValue = ScoringType.Equals(Scoring.Standard) ? ScoreModifier : (ScoreModifier * scoreKeeper.Kills) + 1;

                if (pointValue == 0.0)
                {
                    pointValue = ScoreModifier;
                }
                scoreKeeper.Deaths++;

                if (killer == null) //Minus points if suicide
                {
                    scoreKeeper.Points -= pointValue;
                    if (scoreKeeper.Points < 0.0)
                    {
                        scoreKeeper.Points = 0.0;
                    }
                }
            }

            if (killer != null && m_ScoreTable.TryGetValue(killer.Serial, out scoreKeeper))
            {
                scoreKeeper.Kills++;
                scoreKeeper.Points += pointValue;
            }
        }
Esempio n. 11
0
    private int Scoring(ScoringType type)
    {
        int score = 0;

        if (type == ScoringType.stone)
        {
            for (int x = 0; x < boardSize; x++)
            {
                for (int y = 0; y < boardSize; y++)
                {
                    for (int z = 0; z < boardSize; z++)
                    {
                        score = score + boardArray[x, y, z];
                    }
                }
            }
        }

        else if (type == ScoringType.china)
        {
            //Zerujemy tablice
            bool[,,] boardArrayMask = new bool[boardSize, boardSize, boardSize];
            for (int x = 0; x < boardSize; x++)
            {
                for (int y = 0; y < boardSize; y++)
                {
                    for (int z = 0; z < boardSize; z++)
                    {
                        boardArrayMask[x, y, z] = false;
                    }
                }
            }
            //usuwanie martwych grup
            for (int x = 0; x < boardSize; x++)
            {
                for (int y = 0; y < boardSize; y++)
                {
                    for (int z = 0; z < boardSize; z++)
                    {
                        if (boardArrayMask[x, y, z] == false)
                        {
                            List <Vector3> squad = new List <Vector3>();
                            if (boardArray[x, y, z] == 0)
                            {
                                boardArrayMask[x, y, z] = true;
                            }
                            else
                            {
                                CheckCapturing(new Vector3(x, y, z), squad, true);
                                if (DoesItHaveProperEyes(squad))
                                {
                                    foreach (Vector3 unit in squad)
                                    {
                                        boardArrayMask[(int)unit.x, (int)unit.y, (int)unit.z] = true;
                                    }
                                }
                                else
                                {
                                    if (IsItIsolatedGroup(squad))
                                    {
                                        foreach (Vector3 unit in squad)
                                        {
                                            boardArrayMask[(int)unit.x, (int)unit.y, (int)unit.z] = true;
                                        }
                                        DestroySquad(squad);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            //podliczanie
            for (int x = 0; x < boardSize; x++)
            {
                for (int y = 0; y < boardSize; y++)
                {
                    for (int z = 0; z < boardSize; z++)
                    {
                        if (boardArray[x, y, z] != 0)
                        {
                            score = score + boardArray[x, y, z];
                        }
                        else
                        {
                            score = score + WhoseTerritoryIsIt(new Vector3(x, y, z));
                        }
                    }
                }
            }
        }

        else if (type == ScoringType.japan)
        {
        }
        return(score);
    }
        public async Task <List <PlayerStatsOnDate> > GetScoresForDateAsync(string dateId)
        {
            //var playersResult = this.m_context.HockeyPlayers.ToListAsync();
            //https://statsapi.web.nhl.com/api/v1/schedule?startDate=2016-04-13&endDate=2016-04-13&expand=schedule.decisions,schedule.scoringplays&site=en_nhl&teamId=
            var url        = string.Format("{0}/schedule?startDate={1}&endDate={1}&expand=schedule.decisions,schedule.scoringplays,schedule.game.seriesSummary&site=en_nhl&teamId=", _settings.StatsUrlRoot, dateId);
            var dateResult = await _client.GetAsync(url);

            if (!dateResult.IsSuccessStatusCode)
            {
                return(null);
            }

            var goalType = new ScoringType {
                Name = "Goal"
            };
            var assistType = new ScoringType {
                Name = "Assist"
            };
            var winType = new ScoringType {
                Name = "Win"
            };
            var shutoutType = new ScoringType {
                Name = "Shutout"
            };
            var shorthandedType = new ScoringType {
                Name = "Shorthanded Goal"
            };
            var gameWinningType = new ScoringType {
                Name = "Game Winning Goal"
            };
            var seriesClinchingType = new ScoringType {
                Name = "Series Clinching Goal"
            };
            var overtimeGoalType = new ScoringType {
                Name = "Overtime Goal"
            };

            var content = await dateResult.Content.ReadAsStringAsync();

            var value = JsonConvert.DeserializeObject <Data.DateResult>(content);
            var list  = new List <PlayerStatsOnDate>();

            foreach (var date in value.dates)
            {
                foreach (var game in date.games)
                {
                    var gwgNumber   = -1;
                    var winningTeam = string.Empty;
                    if (game.status.IsOver)
                    {
                        // Determine GWG and Winner
                        var awayScore = game.teams.away.score;
                        var homeScore = game.teams.home.score;
                        if (awayScore < homeScore)
                        {
                            gwgNumber   = awayScore + 1;
                            winningTeam = game.teams.home.team.name;
                        }
                        else
                        {
                            gwgNumber   = homeScore + 1;
                            winningTeam = game.teams.away.team.name;
                        }
                    }

                    // Scores
                    int position = 1;
                    foreach (var play in game.scoringPlays)
                    {
                        var strength = play.result.strength;
                        foreach (var player in play.players)
                        {
                            var data = this.GetPlayerStat(list, date.date, player.player.id);
                            if (player.playerType == "Assist")
                            {
                                var score = this.GetScoreItem(data, assistType);
                                score.Total++;
                            }
                            else if (player.playerType == "Scorer")
                            {
                                var goal = this.GetScoreItem(data, goalType);
                                goal.Total++;

                                if (play.result.strength.code == Data.StrengthCode.SHG)
                                {
                                    var shorthanded = this.GetScoreItem(data, shorthandedType);
                                    shorthanded.Total++;
                                }
                                if (play.about.periodType == Data.PeriodType.OVERTIME)
                                {
                                    var overtimeGoal = this.GetScoreItem(data, overtimeGoalType);
                                    overtimeGoal.Total++;
                                }

                                if (winningTeam.Equals(play.team.name) && position == gwgNumber && game.seriesSummary != null)
                                {
                                    // Calculate if scg
                                    if (game.seriesSummary.IsOver)
                                    {
                                        var seriesClinch = this.GetScoreItem(data, seriesClinchingType);
                                        seriesClinch.Total++;
                                    }
                                    // GWG
                                    var gameWinning = this.GetScoreItem(data, gameWinningType);
                                    gameWinning.Total++;
                                }
                            }
                        }
                        if (winningTeam.Equals(play.team.name))
                        {
                            position++;
                        }
                    }

                    // goalie
                    if (game?.decisions?.winner != null)
                    {
                        var goalieWinnerId = game.decisions.winner.id;
                        var data           = this.GetPlayerStat(list, date.date, goalieWinnerId);

                        var win = this.GetScoreItem(data, winType);
                        win.Total++;
                        if (game.teams.LosingScore == 0)
                        {
                            var shutout = this.GetScoreItem(data, shutoutType);
                            shutout.Total++;
                        }
                    }
                    if (game.decisions == null && game.status.IsOver)
                    {
                        Console.Out.WriteLine($"Warning game is over but no decisions. Date: {game.gameDate} {game.teams.away.team.name} at {game.teams.home.team.name}");
                    }
                }
            }

            return(list);
        }
    public static int CalculateScore(ScoringType st, int die1, int die2, int d3, int dieFour, int fifthDie)
    {
        const int bigScore = 50;

        switch (st)
        {
        case ScoringType.Pair:
        {
            const int value = 2;
            int[]     tallies1;
            tallies1 = new int[6];
            tallies1[die1 - 1]++;
            tallies1[die2 - 1]++;
            tallies1[d3 - 1]++;
            tallies1[dieFour - 1]++;
            tallies1[fifthDie - 1]++;
            for (var i = 6 - 1; i >= 0; i--)
            {
                if (tallies1[i] >= value)
                {
                    return((i + 1) * value);
                }
            }

            return(0);
        }

        case ScoringType.TwoPair:
        {
            var counts1 = new int[6];
            counts1[die1 - 1]++;
            counts1[die2 - 1]++;
            counts1[d3 - 1]++;
            counts1[dieFour - 1]++;
            counts1[fifthDie - 1]++;
            var n     = 0;
            var score = 0;
            for (var i = 0; i < 6; i += 1)
            {
                if (counts1[6 - i - 1] >= 2)
                {
                    n++;
                    score += 6 - i;
                }
            }

            if (n == 2)
            {
                return(score * 2);
            }

            return(0);
        }

        case ScoringType.FullHouse:
        {
            int[] tallies;
            var   _2 = false;
            int   i;
            var   _2_at = 0;
            var   _3    = false;
            var   _3_at = 0;


            tallies                = new int[6];
            tallies[die1 - 1]     += 1;
            tallies[die2 - 1]     += 1;
            tallies[d3 - 1]       += 1;
            tallies[dieFour - 1]  += 1;
            tallies[fifthDie - 1] += 1;

            for (i = 0; i != 6; i += 1)
            {
                if (tallies[i] == 2)
                {
                    _2    = true;
                    _2_at = i + 1;
                }
            }

            for (i = 0; i != 6; i += 1)
            {
                if (tallies[i] == 3)
                {
                    _3    = true;
                    _3_at = i + 1;
                }
            }

            if (_2 && _3)
            {
                return(_2_at * 2 + _3_at * 3);
            }

            return(0);
        }

        case ScoringType.FiveOfAKind:
        {
            int[] dice1   = { die1, die2, d3, dieFour, fifthDie };
            var   counts2 = new int[6];
            foreach (var die in dice1)
            {
                counts2[die - 1]++;
            }

            for (var i1 = 0; i1 != 6; i1++)
            {
                if (counts2[i1] == 5)
                {
                    return(bigScore);
                }
            }

            return(0);
        }
        }

        return(0);
    }
Esempio n. 14
0
        public string AddGame(FormCollection form)
        {
            try
            {
                var  dao   = new GameDAO();
                Game model = new Game();
                //if edit
                if (string.IsNullOrWhiteSpace(form["game-id"]))
                {
                    model = dao.Table.Where(x => x.UserId == AppCookies.UserId && x.ID == Convert.ToInt32(form["game-id"])).FirstOrDefault();
                    if (model == null)
                    {
                        throw new Exception("Game not found");
                    }
                }
                //step 1
                model.Name        = form["game-name"];
                model.UserId      = AppCookies.UserId;
                model.GameType    = form["game-game"];
                model.Description = form["game-description"];
                //step 2
                string[] stages = form.AllKeys.Where(x => x.StartsWith("ingress-")).Select(x => x.Split('-')[1]).ToArray();

                string[] competitionTypes = form["competitiontype-" + stages[0]].Split(',').ToArray();
                int      index            = -1;
                model.Stages = new List <Stage>();
                foreach (var stage in stages)
                {
                    index++;
                    Stage new_stage = new Stage();

                    CompetitionType c_type = (CompetitionType)Convert.ToInt32(competitionTypes[index]);
                    new_stage.CompetitionType = c_type;
                    new_stage.Egress          = Convert.ToInt32(form["egress-" + stage]);
                    new_stage.Ingress         = Convert.ToInt32(form["ingress-" + stage]);
                    model.Stages.Add(new_stage);
                }
                model.StageListJson = JsonConvert.SerializeObject(model.Stages);
                //step 3
                Score       score  = new Score();
                ScoringType s_type = (ScoringType)Convert.ToInt32(form["score-type"]);
                score.ScoringType = s_type;
                if (s_type != ScoringType.Percentage)
                {
                    score.Ranged = form["has-range"] == "on" ? true : false;
                    if (score.Ranged)
                    {
                        score.Minimum = Convert.ToDecimal(form["minimum-score"]);
                        score.Maximum = Convert.ToDecimal(form["maximum-score"]);
                    }
                }
                model.ScoreParams = score;
                model.ScoreJson   = JsonConvert.SerializeObject(model.ScoreParams);
                //step 4
                model.LiveStreamUrl = form["live-video-stream"];
                model.BannerImages  = form["banner-images"];
                model.Avatar        = form["game-avatar"];

                //save or update
                model.DateUpdated = DateTime.Now;
                if (model.ID == 0)//save
                {
                    model.DateCreated = DateTime.Now;
                    dao.Save(model);
                }
                else //update
                {
                    dao.Update(model);
                }
                return(AppConstants.SuccessBigBox("Game Setup Successful!", "templates/addgame"));
            }
            catch (Exception e)
            {
                string fullExceptionMessage = e.Message + " ";
                if (e.InnerException != null)
                {
                    fullExceptionMessage += e.InnerException.Message;
                }
                return(AppConstants.ErrorBigBox(fullExceptionMessage, "templates/addgame"));
            }
        }
Esempio n. 15
0
 public ScoringHandModel(HandModel cards, ScoringType scoreType)
 {
     this.cards = cards.Cards;
     this.ScoreType = scoreType;
 }