Exemplo n.º 1
0
        public static Dictionary <LRTKey, Power> getHistoryDict(SqlConnection connection)
        {
            string q = "SELECT * FROM dbo.history WHERE grStrength IS NOT NULL ORDER BY Country,League,Season,Team,Round";
            Dictionary <LRTKey, Power> dict = new Dictionary <LRTKey, Power>();
            LRTKey lrtKey = new LRTKey();

            using (SqlDataReader reader = new SqlCommand(q, connection).ExecuteReader())
            {
                while (reader.Read())
                {
                    lrtKey.Country   = reader["Country"].ToString();
                    lrtKey.League    = reader["League"].ToString();
                    lrtKey.OtherTeam = reader["OtherTeam"].ToString();
                    lrtKey.Round     = (byte)reader["Round"];
                    lrtKey.Season    = reader["Season"].ToString();
                    lrtKey.Team      = reader["Team"].ToString();
                    dict[lrtKey]     = new Power(reader);
                }
            }
            return(dict);
        }
Exemplo n.º 2
0
        private void doBetSomeMoney()
        {
            byte       i = DoublingXForm.STARTROUND, j;
            byte?      scoreA, scoreH;
            double     bank = DoublingXForm.BANKMONEY, bet = DoublingXForm.BETMONEYPERROUND;
            int        r;
            string     aTeam, hTeam, q = @"SELECT * FROM dbo.archive WHERE Round>=" + DoublingXForm.STARTROUND + " ORDER BY Country,League,Season,Round";
            ArchiveVal aVal;
            Brush      color;
            Dictionary <LRTKey, ArchiveVal> aDict = new Dictionary <LRTKey, ArchiveVal>();
            Dictionary <LRTKey, Power>      hDict;

            backgroundWorker.ReportProgress(25, new BGReport("Processing dbo.archive ..."));
            using (SqlDataReader reader = new SqlCommand(q, this.connection).ExecuteReader())
            {
                while (reader.Read())
                {
                    aTeam  = reader["AwayTeam"].ToString();
                    hTeam  = reader["HomeTeam"].ToString();
                    scoreA = reader["ScoreA"] is DBNull ? null : (byte?)reader["ScoreA"];
                    scoreH = reader["ScoreH"] is DBNull ? null : (byte?)reader["ScoreH"];
                    aDict[new LRTKey(reader, hTeam, aTeam)] = new ArchiveVal(scoreH, scoreA, reader["DrawOdds"]);
                    aDict[new LRTKey(reader, aTeam, hTeam)] = new ArchiveVal(scoreA, scoreH, reader["DrawOdds"]);
                }
            }

            backgroundWorker.ReportProgress(50, new BGReport("Processing dbo.history ..."));
            hDict = MethodAForm.getHistoryDict(this.connection);

            var dictSortedByRound = from item in hDict
                                    let otherKey = LRTKey.getOtherKey(item.Key)
                                                   where item.Key.Season == "2011/12" && Math.Abs(item.Value.PrevAvgStrength - hDict[otherKey].PrevAvgStrength) <= 1
                                                   orderby item.Key.Round select item;
            var dictRound = from item in dictSortedByRound where item.Key.Round == i select item;

            while (dictRound.Count() > 0)
            {
                using (var cursor = dictRound.GetEnumerator())
                {
                    r = (new Random()).Next(dictRound.Count()) + 1;
                    for (j = 0; j < r; j++)
                    {
                        cursor.MoveNext();
                    }
                    if (aDict[cursor.Current.Key].result == null)
                    {
                        cursor.Reset();
                        while (cursor.MoveNext())
                        {
                            if (aDict[cursor.Current.Key].result != null)
                            {
                                break;
                            }
                        }
                    }
                    aVal = aDict[cursor.Current.Key];
                    if (aVal.result == 0)
                    {
                        bank += bet * (aVal.DrawOdds - 0.15);
                        bet   = DoublingXForm.BETMONEYPERROUND;
                        color = Brushes.Blue;
                    }
                    else
                    {
                        bank -= bet;
                        bet  *= 2;
                        color = Brushes.Black;
                    }
                    if (bank < 0)
                    {
                        color = Brushes.Red;
                    }
                    backgroundWorker.ReportProgress(70, new BGReport(
                                                        String.Format("{0} {1} - Bet:{2} Bank:{3}", cursor.Current.Key, aVal, bet, bank), color
                                                        ));
                }
                if (bank < 0)
                {
                    break;
                }
                i++;
                dictRound = from item in dictSortedByRound where item.Key.Round == i select item;
            }
        }