// Update the DGV after a winner is drawn for 1st or 2nd overall private void UpdateDGV_WinningEntry(LotteryTeam Selected, int place) { // Show all tickets that can still win by team selected in combo box Dictionary <int, List <int> > PotentialMatches = new Dictionary <int, List <int> >(); List <int> Matches = new List <int>(); foreach (int index in Selected.Entries) { if (Ticket[index].Intersect(WinningCombo[place]).ToList().Count.Equals(4)) { Matches.Add(index); } } BSource.DataSource = from num in Matches orderby num select new { EntryNumber = num, Combination = Ticket[num][0] + " " + Ticket[num][1] + " " + Ticket[num][2] + " " + Ticket[num][3] }; }
// Event handler to get an immediate winner for the current drawing (1st/2nd/3rd overall) private void UI_BTN_Result_Click(object sender, EventArgs e) { LotteryTeam Winner = GetWinnerImmediately(); switch (BallsDrawn / 4) { case 1: UI_TB_1Winner.Text = Winner.TeamName; UI_PB1.Image = Winner.Logo; UpdateDGV_WinningEntry(Winner, 1); break; case 2: UI_TB_2Winner.Text = Winner.TeamName; UI_PB2.Image = Winner.Logo; UpdateDGV_WinningEntry(Winner, 2); break; case 3: UI_TB_3Winner.Text = Winner.TeamName; UI_PB3.Image = Winner.Logo; UI_BTN_Draw.Enabled = false; UI_BTN_Result.Enabled = false; UpdateDGV_FinalDraftOrder(); break; } }
private LotteryTeam GetWinner(int place) { // Find the team with the current winning selection string WinningNumbers = ""; string WinningTeam = ""; LotteryTeam Winner = null; WinningCombo[place].ForEach(o => WinningNumbers += o + " "); WinningCombo[place].Sort(); foreach (KeyValuePair <int, List <int> > kvp in Ticket) { if (kvp.Value.SequenceEqual(WinningCombo[place])) { WinningTeam = TeamWithTicketNumber[kvp.Key]; LottoTeams.ForEach(o => { if (o.TeamName.Equals(WinningTeam)) { Winner = o; } }); } } return(Winner); }
private void UpdateDataGridView() { // Ball 1 or 2 for current draw if ((BallsDrawn - 1) % 4 == 0 || (BallsDrawn - 1) % 4 == 1) { UpdateDGV_TeamOdds(); } else if ((BallsDrawn - 1) % 4 == 2) // Ball 3 for current draw { UpdateDGV_LastDraw(WinningCombo.Keys.Count); } else if (BallsDrawn == 4) { LotteryTeam Winner = GetWinner(1); UpdateDGV_WinningEntry(Winner, 1); } else if (BallsDrawn == 8) { LotteryTeam Winner = GetWinner(2); UpdateDGV_WinningEntry(Winner, 2); } else if (BallsDrawn == 12) // All 12 balls drawn { UpdateDGV_FinalDraftOrder(); } }
private LotteryTeam GetWinnerImmediately() { int PlaceToDrawFor = BallsDrawn / 4 + 1; // No balls drawn yet for current draft position 1, 2, or 3 - create new list to hold winning numbers if (BallsDrawn == 0 || BallsDrawn == 4 || BallsDrawn == 8) { if (!WinningCombo.ContainsKey(PlaceToDrawFor)) { WinningCombo.Add(PlaceToDrawFor, new List <int>()); } } // Keep drawing balls until you find a possible winner do { WinningCombo[PlaceToDrawFor].Add(DrawNewBall(WinningCombo[PlaceToDrawFor])); ++BallsDrawn; } while (WinningCombo[PlaceToDrawFor].Count < 4); LotteryTeam Winner = GetWinner(PlaceToDrawFor); string WinningTeam = Winner.TeamName; string WinningNumbers = ""; WinningCombo[PlaceToDrawFor].ForEach(o => WinningNumbers += o + " "); WinningCombo[PlaceToDrawFor].Sort(); // Check if the team has already won if (WinningTeam == UI_TB_1Winner.Text || WinningTeam == UI_TB_2Winner.Text) { BallsDrawn -= 4; WinningCombo[PlaceToDrawFor].Clear(); Winner = GetWinnerImmediately(); } // Display the winner combo switch (PlaceToDrawFor) { case 1: UI_TB_1Overall.Text = WinningNumbers; break; case 2: UI_TB_2Overall.Text = WinningNumbers; break; case 3: UI_TB_3Overall.Text = WinningNumbers; break; } return(Winner); }
// Drop down box - team selected change event handler private void UI_CB_SelectTeam_SelectedIndexChanged(object sender, EventArgs e) { int place = WinningCombo.Keys.Count; int ballCount = place > 0 ? WinningCombo[place].Count : 0; LotteryTeam Selected = LottoTeams.First(o => o.TeamName == (string)UI_CB_SelectTeam.SelectedItem); // No balls draw, show all combinations if (BallsDrawn == 0) { BSource.DataSource = from num in Selected.Entries orderby num select new { Entry = num, Combination = Ticket[num][0] + " " + Ticket[num][1] + " " + Ticket[num][2] + " " + Ticket[num][3] }; } else { // Show all tickets that can still win by team selected in combo box Dictionary <int, List <int> > PotentialMatches = new Dictionary <int, List <int> >(); List <int> Matches = new List <int>(); foreach (int index in Selected.Entries) { if (Ticket[index].Intersect(WinningCombo[place]).ToList().Count.Equals(ballCount)) { Matches.Add(index); } } BSource.DataSource = from num in Matches orderby num select new { EntryNumber = num, Combination = Ticket[num][0] + " " + Ticket[num][1] + " " + Ticket[num][2] + " " + Ticket[num][3] }; } }