Beispiel #1
0
        public double getExpectancy(int scenarioId)
        {
            CommisionFactory commFactory = new CommisionFactory();
            Comission        comm        = commFactory.GetCommission(ConfigurationManager.AppSettings["CommissionType"]);

            GameManager gm = new GameManager(false);

            gm.relevantScenario = scenarioId;

            AgentsFactory factory = new AgentsFactory();
            InvestAgent   agent   = factory.CreateAgent(ConfigurationManager.AppSettings["AgentType"], gm, comm, false);

            int    startMoney = int.Parse(ConfigurationManager.AppSettings["InitialMoneyAmount"]);
            double currMoney  = startMoney;

            History hist     = new History();
            int     roundNum = 1;

            foreach (KeyValuePair <int, ScenarioTurn> p in _turns)
            {
                InvestmentData data = agent.Invest((float)currMoney, hist, p.Key);
                hist.addRecord(new HistoryRecord(data, currMoney, data.endMoney, roundNum));
                currMoney = data.endMoney;
                ++roundNum;
            }
            return(currMoney);
        }
        private void doInvestment(float moneyInput, bool isTrain)
        {
            double      money = float.Parse(Session["Money"].ToString());
            GameManager gm    = (GameManager)Session["GM"];
            User        user  = (User)Session["User"];

            int roundNum = isTrain ? (int)Session["TrainingRound"] : (int)Session["Round"];

            CommisionFactory commFactory = new CommisionFactory();
            Comission        comm        = commFactory.GetCommission(ConfigurationManager.AppSettings["CommissionType"]);

            AgentsFactory factory = new AgentsFactory();
            InvestAgent   a       = factory.CreateAgent(ConfigurationManager.AppSettings["AgentType"], gm, comm, isTrain);

            InvestmentData investment_data = a.Invest(moneyInput, (History)Session["History"], roundNum);

            double AfterMoney = floor2(money - moneyInput + investment_data.endMoney);

            Session["Money"] = AfterMoney;

            History hist = (History)Session["History"];

            hist.addRecord(new HistoryRecord(investment_data, money, AfterMoney, roundNum));
            Session["History"] = hist;

            InvestmentsRecorder recorder = new InvestmentsRecorder(user);
            int scenarioNum = isTrain ? gm.relevantTrainingScenario : gm.relevantScenario;

            recorder.RecordInvestment(investment_data, money, AfterMoney, roundNum, scenarioNum, investment_data.stockId, isTrain);


            if (isTrain)
            {
                Session["TrainingRound"] = (int)Session["TrainingRound"] + 1;
                if ((int)Session["TrainingRound"] > (int)Session["MinTrainigRounds"])
                {
                    Session["isMinTrainingDone"] = 1;
                }
            }
            else
            {
                Session["Round"] = (int)Session["Round"] + 1;
            }

            MoneyInput.Text = "";

            if (investment_data.investmentMoney == 0)
            {
                Session["InvestmentMessageInvestedMoney"] = "You invested $0.";
                Session["InvestmentMessageEarning"]       = String.Format("The agent earned $0.", Session["Money"]);
                Session["InvestmentMessageCommission"]    = String.Format("Commission of $0 has been taken from your investment.", Session["Money"]);
                Session["InvestmentMessageFinal"]         = String.Format("You get back $0, so now you have ${0} in your account.", Session["Money"]);
            }
            else if (investment_data.earn > 0)
            {
                Session["InvestmentMessageInvestedMoney"] = String.Format("You invested ${0}.", investment_data.investmentMoney);
                Session["InvestmentMessageEarning"]       = String.Format("The agent earned ${0} ({1}%).", floor2(investment_data.earnMoney), floor2(100 * investment_data.earn));
                Session["InvestmentMessageCommission"]    = String.Format("Commission of {0}%  (${1}) has been taken from your investment.", floor2(investment_data.commission_percent), floor2(investment_data.commission));
                Session["InvestmentMessageFinal"]         = String.Format("You get back ${0}, so now you have ${1} in your account", floor2(investment_data.endMoney), Session["Money"]);
            }
            else if (investment_data.earn < 0)
            {
                Session["InvestmentMessageInvestedMoney"] = String.Format("You invested ${0}.", investment_data.investmentMoney);
                Session["InvestmentMessageEarning"]       = String.Format("The agent lost ${0} ({1}%).", floor2(investment_data.earnMoney) * (-1), floor2(100 * investment_data.earn) * (-1));
                Session["InvestmentMessageCommission"]    = String.Format("Commission of {0}%  (${1}) has been taken from your investment.", floor2(investment_data.commission_percent), floor2(investment_data.commission));
                Session["InvestmentMessageFinal"]         = String.Format("You get back ${0}, so now you have ${1} in your account", floor2(investment_data.endMoney), Session["Money"]);
            }
            else if (investment_data.earn == 0)
            {
                Session["InvestmentMessageInvestedMoney"] = String.Format("You invested ${0}.", investment_data.investmentMoney);
                Session["InvestmentMessageEarning"]       = String.Format("The agent earned nothing ({0}%).", floor2(investment_data.earn) * 100);
                Session["InvestmentMessageCommission"]    = String.Format("Commission of {0}%  (${1}) has been taken from your investment.", floor2(investment_data.commission_percent), floor2(investment_data.commission));
                Session["InvestmentMessageFinal"]         = String.Format("You get back ${0}, so now you have ${1} in your account", floor2(investment_data.endMoney), Session["Money"]);
            }
        }