Esempio n. 1
0
        public int findOptimalStock()
        {
            double maxExpectation = StocksManager.getStocks().Max(st => st.getExcpectation());
            Stock  s = StocksManager.getStocks().First <Stock>(st => st.getExcpectation() == maxExpectation);

            return(s._id);
        }
        private static void initScenariosInDB()
        {
            int scenariosNumber = int.Parse(ConfigurationManager.AppSettings["NumberOfScenarios"]);
            int turnsNum        = int.Parse(ConfigurationManager.AppSettings["MaxRounds"]);

            List <List <DALType> > writeData = new List <List <DALType> >();

            for (int i = 0; i < scenariosNumber; i++)
            {
                for (int j = 0; j < turnsNum; j++)
                {
                    foreach (Stock s in StocksManager.getStocks())
                    {
                        List <DALType> row = new List <DALType>();

                        row.Add(new DALInt(i + 1));             //scenarioId
                        row.Add(new DALInt(j + 1));             //TurnNum
                        row.Add(new DALInt(s._id));             //srockId
                        row.Add(new DALDouble(s.getEarning())); //stock earning

                        writeData.Add(row);
                    }
                }
            }
            dal.writeData(scenariosTable, writeData);
        }
 public static void initialize()
 {
     if (!StocksManager.HasStocks())
     {
         throw new noStocksException();
     }
     lock (initLockObject)
     {
         bool updateScenariosSummary = false;
         if (dal.isTableEmpty(scenariosTable))
         {
             initScenariosInDB();
             updateScenariosSummary = true;
         }
         initScenarios();
         if (updateScenariosSummary || dal.isTableEmpty(scenariosSummaryTable))
         {
             initScenariosSummary();
         }
     }
 }
 private static void initGame()
 {
     StocksManager.initialize();
     ScenariosManager.initialize();
     isInitialized = true;
 }
Esempio n. 5
0
        public double getEarning()
        {
            IRandomGenerator generator = StocksManager.getGeneratorForStock(_id);

            return(_earnings[generator.getRandomNum()]);
        }