public async Task<PartialViewResult> PostRound(Round round)
        {
            var model = await db.Rounds.FindAsync(round.ID);

            if (!model.Game.IsDemo)
            {
                if (User.Identity.IsAuthenticated)
                {
                    if (db.Users.Find(User.Identity.GetUserId()).Club.ID != model.Game.Club.ID)
                    {
                        Response.Redirect("~/Account/Login?returnUrl=" + Request.Url.LocalPath);
                        return null;
                    }
                }
                else
                {
                    Response.Redirect("~/Account/Login?returnUrl=" + Request.Url.LocalPath);
                    return null;
                }
            }


            if (model.Throws != null)
            {
                foreach (var item in model.Throws)
                {
                    model.Game.Throws.Remove(item);
                }
                model.Throws.Clear();
            }

            List<Throw> Throws = new List<Throw>();
            var team1 = model.Teams.First(t => t.ID == model.Team1ID);
            var team2 = model.Teams.First(t => t.ID == model.Team2ID);
            model.Done = true;
            model.UpdateID = string.Format("r{0}", model.ID);
            model.T1R1 = round.T1R1;
            model.T1R2 = round.T1R2;
            model.T2R1 = round.T2R1;
            model.T2R2 = round.T2R2;
            Throws.Add(new Throw() { Game = model.Game, Team = team1, ThrowNumber = 1, Points = round.T1R1, });
            Throws.Add(new Throw() { Game = model.Game, Team = team2, ThrowNumber = 1, Points = round.T2R1 });
            Throws.Add(new Throw() { Game = model.Game, Team = team1, ThrowNumber = 2, Points = round.T1R2 });
            Throws.Add(new Throw() { Game = model.Game, Team = team2, ThrowNumber = 2, Points = round.T2R2 });
            model.Throws = Throws;
            foreach (var item in model.Throws)
            {
                var t1 = team1;
                var t2 = team2;
                if (item.ThrowNumber == 2)
                {
                    item.Result = model.GetResult(item.Team == t1 ? t1 : t2, item.Team == t1 ? t2 : t1);
                }
            }
            model.Game.LastActive = DateTime.Now;
            await db.SaveChangesAsync();
            return PartialView("_LockedRound", model);
        }
Beispiel #2
0
        public int ContainsPoints(Round other)
        {
            int restult = 0;
            //var array = other.Teams.ToArray();
            if (this.Teams.First().AltName == other.Teams.First().AltName || this.Teams.First().AltName == other.Teams.Last().AltName) restult++;
            if (this.Teams.Last().AltName == other.Teams.First().AltName || this.Teams.Last().AltName == other.Teams.Last().AltName) restult++;

            //if (Contains(other.Teams.First(t=> t.AltName == other.Team1ID))) restult++;
            //if (Contains(other.Teams.First(t =>t.AltName == other.Team2ID))) restult++;
            return restult;
        }
Beispiel #3
0
        public static List<Round> RoundRobinScramble3(List<Round> Opponents, List<Lane> Lanes)
        {

            List<Round> result = new List<Round>();

            List<Round> row;
            List<Lane> Remaining = new List<Lane>();
            Team[] rowTeams = null;
            Round[] resultRow = new Round[Lanes.Count];
            Team team1 = null;
            Team team2 = null;
            for (int i = 0; i < Opponents.Count; i += Lanes.Count)
            {
                row = Opponents.GetRange(i, Lanes.Count <= Opponents.Count - i ? Lanes.Count : Opponents.Count - i);
                resultRow = new Round[Lanes.Count];
                Remaining = ResetRemainingLanes(Lanes);

                while (row.Count > 0)
                {
                    foreach (Round opponent in row)
                    {
                        //Ordna prio på mattor för dessa två lag
                        opponent.GetLanePrios(Remaining);
                    }
                    row.OrderBy(r => r.LanePrios);
                    //Om bara ett alternativ återstår.
                    if (row.Count == 1)
                    {
                        team1 = row[0].Teams.First(t => t.ID == row[0].Team1ID);
                        team2 = row[0].Teams.First(t => t.ID == row[0].Team1ID);
                        //rowTeams = row[0].Teams.ToArray();
                        //Sätt matta
                        row[0].Lane = row[0].LanePrios[0].Lane;
                        //Öka antalet matcher på mattan för båda lagen
                        team1.TeamLane[Lanes.IndexOf(row[0].Lane)].Count++;
                        team2.TeamLane[Lanes.IndexOf(row[0].Lane)].Count++;

                        //Lägg till omgången på rätt matta i resultatraden
                        resultRow[Lanes.IndexOf(row[0].LanePrios[0].Lane)] = row[0];

                        //Plocka bort mattan som alternativ i framtiden
                        Remaining.Remove(row[0].Lane);

                        //Plocka bort spelare som alternativ i framtiden på raden
                        row.RemoveAt(0);

                        //Plocka bort banan ur priolistan för motståndarna på raden
                        foreach (Round o in row)
                        {
                            //o.LanePrios.Remove(o.LanePrios.Where(t => t.Lane == row[0].Lane).ToArray()[0]);
                            o.GetLanePrios(Remaining);
                        }
                        break;
                    }

                    for (int p = 0; p < row[0].LanePrios.Count; p++)
                    {
                        //Om prio är samma för de två översta lagen i listan, gå till nästa prio för att avgöra vem som bör få platsen.
                        if (row[0].LanePrios[p].Lane == row[1].LanePrios[p].Lane && row[0].LanePrios[p].Count == row[1].LanePrios[p].Count && p < Remaining.Count - 2)
                        {
                            continue;
                        }

                        else
                        {
                            //rowTeams = row[0].Teams.ToArray();
                            //Sätt matta
                            row[0].Lane = row[0].LanePrios[p].Lane;
                            //Öka antalet matcher på mattan för båda lagen
                            team1.TeamLane[Lanes.IndexOf(row[0].Lane)].Count++;
                            team2.TeamLane[Lanes.IndexOf(row[0].Lane)].Count++;

                            //Lägg till omgången på rätt matta i resultatraden
                            resultRow[Lanes.IndexOf(row[0].LanePrios[p].Lane)] = row[0];

                            //Plocka bort mattan som alternativ i framtiden
                            Remaining.Remove(row[0].Lane);

                            //Plocka bort spelare som alternativ i framtiden på raden
                            row.RemoveAt(0);

                            //Plocka bort banan ur priolistan för motståndarna på raden
                            foreach (Round o in row)
                            {

                                // o.LanePrios.Remove(o.LanePrios.Where(t => t.Lane == row[0].Lane).ToArray()[0]);
                                o.GetLanePrios(Remaining);
                            }
                            break;
                        }
                    }
                }
                if (resultRow.Contains(null))
                {
                    for (int e = 0; e < resultRow.Length; e++)
                    {
                        if (resultRow[e] != null) result.Add(resultRow[e]);
                    }
                    return result;
                }
                result.AddRange(resultRow);

            }
            return result;
        }