Ejemplo n.º 1
0
        public void TestGetAllScoresBetfair()
        {
            var allMarkets = new AllMarkets();

            allMarkets.GetAllMarkets(TypeDBO.BetFair);
            if (allMarkets.ParsingInfo.AllMarketsHashSet == null)
            {
                Assert.Fail("Null information from Betfair");
            }
            if (allMarkets.ParsingInfo.AllMarketsHashSet.Count == 0)
            {
                Assert.Fail("(Count = 0) information from Betfair");
            }
            foreach (var market in allMarkets.ParsingInfo.AllMarketsHashSet)
            {
                allMarkets.GetScoreMarket(market.BetfairEventId, TypeDBO.BetFair);
                if ((market.Player1.ScoreBetfair1 == null) && (market.Player1.ScoreBetfair1 == ""))
                {
                    Assert.Fail("Score error from betfair");
                }
                if ((market.Player2.ScoreBetfair1 == null) && (market.Player2.ScoreBetfair1 == ""))
                {
                    Assert.Fail("Score error from betfair");
                }
            }
        }
Ejemplo n.º 2
0
        public MainForm()
        {
            InitializeComponent();

            _allMarkets                = new AllMarkets();
            Market.MarketChanged      += OnMarketChangedEvent;
            ParsingInfo.PlayerChanged += OnPlayerChanged;

            Bet365.PlayerChanged    += OnPlayerChanged;
            NewSkyBet.PlayerChanged += OnPlayerChanged;

            Bet365.MessageChanged    += OnMessageChanged;
            NewSkyBet.MessageChanged += OnMessageChanged;

            AllMarkets.LoadedEvent += OnLoadedEvent;



            UiThread = new Thread(Start)
            {
                Name = "UiThread"
            };
            UiThread.Start();

            CheckConnetionThread = new Thread(CheckConnetion)
            {
                Name = "CheckStatus"
            };
            CheckConnetionThread.Start();
            isStop = false;
        }
Ejemplo n.º 3
0
 public void TestNewDSB()
 {
     AllMarkets.PerformAction(x =>
                              x.ForceDSBRecalculation()
                              //x.getDemandSupplyBalance(null, true)
                              );
     MainCamera.tradeWindow.Refresh();
 }
Ejemplo n.º 4
0
        public Bet365(AllMarkets markteMarkets)
        {
            Debug.WriteLine("Start browser2");
            var cef = Chrome.Instanse;

            isLoad                  = false;
            isIgnoredMarket         = false;
            browser                 = Chrome.InstBet365;
            browser.ConsoleMessage += BrowserOnConsoleMessage;
            allMarkets              = markteMarkets;
        }
Ejemplo n.º 5
0
        public void TestScrapeScorePageSkyBet()
        {
            var allmarkets = new AllMarkets();
            var result     = allmarkets.GetAllMarkets(TypeDBO.SkyBet);

            if (result == false)
            {
                Assert.Fail("No info [market == null]");
            }
            if (allmarkets.ParsingInfo.AllMarketsHashSet.Count == 0)
            {
                Assert.Fail("No elems from parse. Maybee no inplay games?");
            }
            foreach (var marketInfo in allmarkets.ParsingInfo.AllMarketsHashSet)
            {
                if (marketInfo.SkyBetEventId == null)
                {
                    Assert.Fail("No info eventId from skybet");
                }
                var statusScore = allmarkets.GetScoreMarket(marketInfo.SkyBetEventId, TypeDBO.SkyBet);
                if (statusScore == false)
                {
                    Assert.Fail("No info result from skybet");
                }
                if (marketInfo.Player1 == null)
                {
                    Assert.Fail("No info about player1 in some markets");
                }
                if (marketInfo.Player1 == null)
                {
                    Assert.Fail("No info about player2 in some markets");
                }
                if ((marketInfo.Player1.ScoreSkyBet == null) || (marketInfo.Player1.ScoreSkyBet == ""))
                {
                    Debug.WriteLine("ScoreBet366:" + marketInfo.Player2.ScoreBet366);
                    Debug.WriteLine("ScoreBetfair:" + marketInfo.Player2.ScoreBetfair1);
                    Assert.Fail("No info about score1 one in some markets");
                }
                if ((marketInfo.Player2.ScoreSkyBet == null) || (marketInfo.Player2.ScoreSkyBet == ""))
                {
                    Debug.WriteLine("ScoreBet366:" + marketInfo.Player2.ScoreBet366);
                    Debug.WriteLine("ScoreBetfair:" + marketInfo.Player2.ScoreBetfair1);
                    Assert.Fail("No info about score2 one in some markets");
                }
                if (marketInfo.MarketName.Length < 4)
                {
                    Assert.Fail("No info about player1 in some markets");
                }
            }
            Debug.WriteLine("In-plays markets: " + allmarkets.ParsingInfo.AllMarketsHashSet.Count);
        }
Ejemplo n.º 6
0
        public NewSkyBet(AllMarkets marktes)
        {
            var cef = Chrome.Instanse;

            isLoad  = false;
            browser = Chrome.InstSkyBet;
            browser.ConsoleMessage      += BrowserOnConsoleMessage;
            browser.LoadingStateChanged += BrowserOnLoadingStateChanged;
            browser.BrowserInitialized  += BrowserOnBrowserInitialized;
            allMarkets = marktes;

            State           = ThreadState.Running;
            isIgnoredMarket = false;
        }
Ejemplo n.º 7
0
        public void TestGetAllInfoBetfair()
        {
            var allMarkets = new AllMarkets();

            allMarkets.GetAllMarkets(TypeDBO.BetFair);
            if (allMarkets.ParsingInfo.AllMarketsHashSet == null)
            {
                Assert.Fail("Null information from Betfair");
            }
            if (allMarkets.ParsingInfo.AllMarketsHashSet.Count == 0)
            {
                Assert.Fail("(Count = 0) information from Betfair");
            }
            Debug.WriteLine("Count get's elems from bet365 = " + allMarkets.ParsingInfo.AllMarketsHashSet.Count);
        }
Ejemplo n.º 8
0
        //private static void calcBattles()
        //{
        //    foreach (Staff attacker in Staff.getAllStaffs().ToList())
        //    {
        //        foreach (var attackerArmy in attacker.getAttackingArmies().ToList())
        //        {
        //            var movement = attacker as Movement;
        //            if (movement == null || movement.isValidGoal()) // movements attack only if goal is still valid
        //            {
        //                var result = attackerArmy.attack(attackerArmy.getDestination());
        //                if (result.isAttackerWon())
        //                {
        //                    if (movement == null)
        //                        (attacker as Country).TakeProvince(attackerArmy.getDestination(), true);
        //                    //attackerArmy.getDestination().secedeTo(attacker as Country, true);
        //                    else
        //                    {
        //                        if (movement.getReformType() == null)//separatists
        //                            movement.onRevolutionWon();
        //                        else
        //                            movement.getReformType().setValue(movement.getGoal());

        //                    }
        //                }
        //                else if (result.isDefenderWon())
        //                {
        //                    if (movement != null)
        //                        movement.onRevolutionLost();
        //                }
        //                if (result.getAttacker() == Game.Player || result.getDefender() == Game.Player)
        //                    result.createMessage();
        //            }
        //            attackerArmy.sendTo(null); // go home
        //        }
        //        //attacker.consolidateArmies();
        //    }
        //}

        public static void prepareForNewTick()
        {
            AllMarkets.PerformAction(x => x.SetStatisticToZero());

            foreach (Country country in World.AllExistingCountries())
            {
                country.SetStatisticToZero();
                foreach (Province province in country.AllProvinces)
                {
                    foreach (var item in province.AllAgents)
                    {
                        item.SetStatisticToZero();
                    }
                }
            }
            PopType.sortNeeds(Market.TemporalSingleMarket);       //getAllExistingCountries().Random().market
            Product.sortSubstitutes(Market.TemporalSingleMarket); //getAllExistingCountries().Random().market
        }
Ejemplo n.º 9
0
        public void TestGetAllInformationBet365()
        {
            var startTime  = DateTime.Now;
            var allMarkets = new AllMarkets();

            allMarkets.GetAllMarkets(TypeDBO.Bet365);
            if (allMarkets.ParsingInfo.AllMarketsHashSet == null)
            {
                Assert.Fail("Null information from Bet365");
            }
            if (allMarkets.ParsingInfo.AllMarketsHashSet.Count == 0)
            {
                Assert.Fail("(Count = 0) information from Bet365");
            }
            var endTime = DateTime.Now;

            Debug.WriteLine("Time for get info: " + (startTime - endTime).TotalSeconds);
            Debug.WriteLine("Count get's elems from bet365 = " + allMarkets.ParsingInfo.AllMarketsHashSet.Count);
        }
Ejemplo n.º 10
0
        public void TestGetAllScoreBet365()
        {
            var startTime  = DateTime.Now;
            var allMarkets = new AllMarkets();

            //var threadControl = new ThreadControl(allMarkets);
            allMarkets.GetAllMarkets(TypeDBO.Bet365);
            if (allMarkets.ParsingInfo.AllMarketsHashSet == null)
            {
                Assert.Fail("Null information from Bet365");
            }
            if (allMarkets.ParsingInfo.AllMarketsHashSet.Count == 0)
            {
                Assert.Fail("(Count = 0) information from Bet365");
            }
            foreach (var market in allMarkets.ParsingInfo.AllMarketsHashSet)
            {
                if (market.MarketName == null)
                {
                    Debug.WriteLine("MarketName is null!!! ");
                    continue;
                }
                if (market.Bet365EventId == null)
                {
                    Debug.WriteLine("Empty Event id, market: " + market.MarketName);
                    continue;
                }
                allMarkets.GetScoreMarket(market.Bet365EventId, TypeDBO.Bet365);
                if ((market.Player1.ScoreBet366 == null) && (market.Player1.ScoreBet366 == ""))
                {
                    Assert.Fail("Score error from bet365");
                }
                if ((market.Player2.ScoreBet366 == null) && (market.Player2.ScoreBet366 == ""))
                {
                    Assert.Fail("Score error from bet365");
                }
                Thread.Sleep(100);
            }
            var endTime = DateTime.Now;

            Debug.WriteLine("Time for get info: " + (startTime - endTime).TotalMilliseconds);
        }
Ejemplo n.º 11
0
        public void TestScrapeTennisPageSkybet()
        {
            var allmarkets = new AllMarkets();
            var result     = allmarkets.GetAllMarkets(TypeDBO.SkyBet);

            if (result == false)
            {
                Assert.Fail("No info [market == null]");
            }
            if (allmarkets.ParsingInfo.AllMarketsHashSet.Count == 0)
            {
                Assert.Fail("No elems from parse. Maybee no inplay games?");
            }
            foreach (var marketInfo in allmarkets.ParsingInfo.AllMarketsHashSet)
            {
                if (marketInfo.Player1 == null)
                {
                    Assert.Fail("No info about player1 in some markets");
                }
                if (marketInfo.Player2 == null)
                {
                    Assert.Fail("No info about player2 in some markets");
                }
                if (marketInfo.MarketName.Length < 4)
                {
                    Assert.Fail("No info about player1 in some markets");
                }
            }
            Debug.WriteLine("Elems from skyBet: " + allmarkets.ParsingInfo.AllMarketsHashSet.Count);
            Debug.WriteLine("Names of players: ");
            foreach (var market in allmarkets.ParsingInfo.AllMarketsHashSet)
            {
                Debug.WriteLine(market.Player1.Name + " : " + market.Player2.Name);
            }
            Debug.WriteLine("");
        }
Ejemplo n.º 12
0
        public static void simulate()
        {
            if (haveToStepSimulation)
            {
                haveToStepSimulation = false;
            }

            Date.Simulate();
            if (Game.devMode)
            {
                Debug.Log("New date! - " + Date.Today);
            }
            // strongly before PrepareForNewTick
            AllMarkets.PerformAction(x => x.simulatePriceChangeBasingOnLastTurnData());

            // rise event on day passed
            // DayPassed?.Invoke(World.Get, EventArgs.Empty);

            var @event = DayPassed;

            if (@event != null)                     // check for subscribers
            {
                @event(World.Get, EventArgs.Empty); //fires event for all subscribers
            }
            // should be before PrepareForNewTick cause PrepareForNewTick hires dead workers on factories
            //calcBattles();

            // includes workforce balancing
            // and sets statistics to zero. Should go after price calculation
            prepareForNewTick();

            // big PRODUCE circle
            foreach (Country country in World.AllExistingCountries())
            {
                foreach (Province province in country.AllProvinces)
                {
                    foreach (var producer in province.AllProducers)
                    {
                        producer.produce();
                    }
                }
            }

            // big CONCUME circle
            foreach (Country country in World.AllExistingCountries())
            {
                country.consumeNeeds();
                if (country.economy == Economy.PlannedEconomy)
                {
                    //consume in PE order
                    foreach (Factory factory in country.Provinces.AllFactories)
                    {
                        factory.consumeNeeds();
                    }

                    if (country.Science.IsInvented(Invention.ProfessionalArmy))
                    {
                        foreach (var item in country.Provinces.AllPops.Where(x => x.Type == PopType.Soldiers))
                        {
                            item.consumeNeeds();
                        }
                    }

                    foreach (var item in country.Provinces.AllPops.Where(x => x.Type == PopType.Workers))
                    {
                        item.consumeNeeds();
                    }

                    foreach (var item in country.Provinces.AllPops.Where(x => x.Type == PopType.Farmers))
                    {
                        item.consumeNeeds();
                    }

                    foreach (var item in country.Provinces.AllPops.Where(x => x.Type == PopType.Tribesmen))
                    {
                        item.consumeNeeds();
                    }
                }
                else  //consume in regular order
                {
                    foreach (Province province in country.AllProvinces)//Province.allProvinces)
                    {
                        foreach (Factory factory in province.AllFactories)
                        {
                            factory.consumeNeeds();
                        }
                        foreach (PopUnit pop in province.AllPops)
                        {
                            //That placed here to avoid issues with Aristocrats and Clerics
                            //Otherwise Aristocrats starts to consume BEFORE they get all what they should
                            if (country.serfdom == Serfdom.SerfdomAllowed || country.serfdom == Serfdom.Brutal)
                            {
                                if (pop.shouldPayAristocratTax())
                                {
                                    pop.payTaxToAllAristocrats();
                                }
                            }
                        }
                        foreach (PopUnit pop in province.AllPops)
                        {
                            pop.consumeNeeds();
                        }
                    }
                }
            }
            //force DSB recalculation. Helped with precise calculation of DSB & how much money seller should get
            //AllMarkets.PerformAction(x =>
            ////x.ForceDSBRecalculation()
            //x.getDemandSupplyBalance(null, true)
            //);
            if (Game.logMarket)
            {
                //Money res = new Money(0m);
                //foreach (var product in Product.getAll())

                //    res.Add(Country.market.getCost(Country.market.getMarketSupply(product, true)).Copy().Multiply((decimal)Country.market.getDemandSupplyBalance(product, false))
                //        );
                //if (!Country.market.moneyIncomeThisTurn.IsEqual(res))
                //{
                //    Debug.Log("Market income: " + Country.market.moneyIncomeThisTurn + " total: " + Country.market.Cash);
                //    Debug.Log("Should pay: " + res);
                //}
            }
            // big AFTER all and get money for sold circle
            foreach (Country country in World.AllExistingCountries())
            {
                Market.GiveMoneyForSoldProduct(country);
                foreach (Province province in country.AllProvinces)//Province.allProvinces)
                {
                    foreach (Factory factory in province.AllFactories)
                    {
                        if (country.economy == Economy.PlannedEconomy)
                        {
                            if (country.isAI() && factory.IsClosed && !factory.isBuilding())
                            {
                                Rand.Call(() => factory.open(country, false), Options.howOftenCheckForFactoryReopenning);
                            }
                        }
                        else
                        {
                            Market.GiveMoneyForSoldProduct(factory);
                            factory.paySalary();   // workers get gold or food here
                            factory.ChangeSalary();
                            factory.payDividend(); // also pays taxes inside
                            factory.CloseUnprofitable();
                            factory.ownership.CalcMarketPrice();
                            Rand.Call(() =>
                            {
                                factory.ownership.SellLowMarginShares();
                            }, 20);
                        }
                    }
                    province.DestroyAllMarkedfactories();
                    // get pop's income section:
                    foreach (PopUnit pop in province.AllPops)
                    {
                        if (pop.Type == PopType.Workers)
                        {
                            pop.LearnByWork();
                        }
                        if (pop.canSellProducts())
                        {
                            Market.GiveMoneyForSoldProduct(pop);
                        }

                        if (country.Science.IsInvented(Invention.ProfessionalArmy) && country.economy != Economy.PlannedEconomy)
                        // don't need salary with PE
                        {
                            var soldier = pop as Soldiers;
                            if (soldier != null)
                            {
                                soldier.takePayCheck();
                            }
                        }

                        pop.takeUnemploymentSubsidies();
                        pop.TakeUBISubsidies();
                        pop.TakePovertyAid();// should be least


                        //because income come only after consuming, and only after FULL consumption
                        //if (pop.canTrade() && pop.hasToPayGovernmentTaxes())
                        // POps who can't trade will pay tax BEFORE consumption, not after
                        // Otherwise pops who can't trade avoid tax
                        // pop.Country.TakeIncomeTax(pop, pop.moneyIncomethisTurn, pop.Type.isPoorStrata());//pop.payTaxes();
                        pop.calcLoyalty();

                        if (Rand.Chance(Options.PopPopulationChangeChance))
                        {
                            pop.Growth();
                        }

                        if (Rand.Chance(Options.PopPopulationChangeChance))
                        {
                            pop.Promote();
                        }

                        if (pop.needsFulfilled.isSmallerOrEqual(Options.PopNeedsEscapingLimit))
                        {
                            if (Rand.Chance(Options.PopPopulationChangeChance))
                            {
                                pop.ChangeLife(pop.GetAllPossibleDemotions().Where(x => x.Value.isBiggerThan(pop.needsFulfilled, Options.PopNeedsEscapingBarrier)).MaxBy(x => x.Value.get()).Key, Options.PopDemotingSpeed);
                            }
                        }

                        if (Rand.Chance(Options.PopPopulationChangeChance))
                        {
                            pop.ChangeLife(pop.GetAllPossibleMigrations().Where(x => x.Value.isBiggerThan(pop.needsFulfilled, Options.PopNeedsEscapingBarrier)).MaxBy(x => x.Value.get()).Key, Options.PopMigrationSpeed);
                        }

                        if (Rand.Chance(Options.PopPopulationChangeChance))
                        {
                            pop.Assimilate();
                        }
                    }
                }
            }
            //investments circle. Needs to be separate, otherwise cashed  investments can conflict
            foreach (Country country in World.AllExistingCountries())
            {
                foreach (var province in country.AllProvinces)
                {
                    foreach (var pop in province.AllPops)
                    {
                        if (country.economy != Economy.PlannedEconomy)
                        {
                            Rand.Call(() => pop.invest(), Options.PopInvestRate);
                        }
                    }

                    if (country.isAI())
                    {
                        country.invest(province);
                    }
                    //if (Rand.random2.Next(3) == 0)
                    //    province.consolidatePops();
                    province.RemoveDeadPops();
                    foreach (PopUnit pop in PopUnit.PopListToAddToGeneralList)
                    {
                        PopUnit targetToMerge = pop.Province.getSimilarPopUnit(pop);
                        if (targetToMerge == null)
                        {
                            pop.Province.RegisterPop(pop);
                        }
                        else
                        {
                            targetToMerge.mergeIn(pop);
                        }
                    }

                    PopUnit.PopListToAddToGeneralList.Clear();
                    province.simulate();
                    province.BalanceEmployableWorkForce();
                }
                country.simulate();
                if (country.isAI())
                {
                    country.AIThink();
                }
            }
        }