예제 #1
0
        public static bool MakeTradeFromPlayer(Game g)
        {
            var ptrade = g.CurrTrade;
            if (ptrade.to.IsBot)
            {
                var trs = GetValidTrades(g, g.CurrTrade.to);

                if (IsGoodTrade(ptrade, trs))
                {
                    GameManager.MakeTrade(g);
                    g.FixAction("trade_completed");
                    return true;
                }
            }
            g.ToBeginRound();
            return false;
        }
예제 #2
0
        public static void BuildHouses(Game g, int Sum, int? Group)
        {
            //if (!g.Curr.IsBot) return;

            var p = g.Curr;

            var groupCells = from x in g.Map.CellsByUserByType(p.Id, 1)
                             where x.IsMonopoly
                             group x by x.Group into gr
                             where gr.All(a => !a.IsMortgage)
                             select new { Key = gr.Key, Vals = gr };

            if (Group.HasValue)
                groupCells = groupCells.Where(x => x.Key == Group);

            //var amSpent = GetCashForHouses(g, p);

            string text = "";

            foreach (var gr in groupCells.
               OrderByDescending(x => x.Vals.Max(a => a.HousesCount)))
            {
                var cost = gr.Vals.First().HouseCost;

                while (BotBrain.Mortgage(g, p, cost) && gr.Vals.Any(c => c.HousesCount < 5))
                    foreach (var cell in gr.Vals.OrderBy(c => c.HousesCount).ThenByDescending(x => x.Id))
                    {
                        if (p.Money < cell.HouseCost)
                            BotBrain.Mortgage(g, p, cell.HouseCost);

                        if (p.Money >= cell.HouseCost && cell.HousesCount < 5)
                        {
                            cell.HousesCount++;
                            p.Money -= cell.HouseCost;
                            text = text + "_" + cell.Id;
                        }
                    }

            }
            if (text != "")
            {
                g.FixAction("build" + text);
            }
        }
예제 #3
0
        public static void UnMortgageLands(Game g, Player p)
        {
            //if (!BotBrain.NeedBuildHouses(g)) return;

            var trans = g.Map.CellsByUserByGroup(p.Id, 11);

            string text = "";

            if (trans.Count() > 2)
                text += UnMortg(g, trans);

            var cellsMon = g.Map.CellsByUser(p.Id).Where(x => x.IsMortgage && x.IsMonopoly)
                .GroupBy(x => x.Group);

            if (cellsMon.Any())
            {
                //Mortgage(g, p, cellsMon.First().UnMortgageAmount);
                text += UnMortg(g, cellsMon.FirstOrDefault());
            }

            //var cells = g.Map.CellsByUser(p.Id).Where(x => x.IsMortgage);
            //UnMortg(g, cells);

            if (text != "")
            {
                g.FixAction("unmortgage" + text);
            }
        }
예제 #4
0
        public static bool Mortgage(Game g, Player p, int PayAmount, bool InclMon = false)
        {
            if (p.Money >= PayAmount) return true;

            var cells = g.Map.CellsByUser(p.Id).Where(a => !a.IsMortgage);

            //select non monopoly cells-type1
            var lands = cells.Where(x => !x.IsMonopoly && x.Type == 1);

            //select trans and power cells
            var transPower = cells.Where(x => x.Type == 2 || x.Type == 3);

            //select monopoly without houses
            IEnumerable<CellInf> q = lands.Union(transPower);

            if (InclMon)
            {
                var landsMon000 = cells.Where(x => x.IsMonopoly).GroupBy(x => x.Group).
                Where(x => x.All(a => a.HousesCount == 0)).SelectMany(x => x);
                q = q.Union(landsMon000);
            }

            string text = "";

            foreach (var cell in q)
            {
                if (p.Money >= PayAmount) break;

                p.Money += cell.MortgageAmount;
                cell.IsMortgage = true;
                text = text + "_" + cell.Id;
            }

            if (!string.IsNullOrEmpty(text))
            {
                g.FixAction("mortgage" + text);
            }

            return (p.Money >= PayAmount);
        }
예제 #5
0
        public static void SellHouses(Game g, int PayAmount)
        {
            var p = g.Curr;

            var grCells = from x in g.Map.CellsByUser(p.Id)
                          where x.IsMonopoly && !x.IsMortgage
                          //group x by x.Value.Group into gg
                          //select new { gg.Key, Vals = gg };
                          select x;

            string text = "";

            while (grCells.Where(x => x.HousesCount > 0).Any())
            {
                foreach (var cell in grCells.OrderByDescending(x => x.HousesCount))
                {
                    if (p.Money >= PayAmount) return;

                    if (cell.HousesCount > 0)
                    {
                        cell.HousesCount--;
                        p.Money += cell.HouseCostWhenSell;
                        text = text + "_" + cell.Id;
                    }
                }
            }
            if (text != "")
            {
                g.FixAction("sell_houses" + text);
            }
        }
예제 #6
0
        public static void ProcessPosition(Game g)
        {
            var p = g.Curr;

            //general land
            var cell = g.Cells[p.Pos];

            if (cell.IsLand)
            {
                ProcessLand(g, p, cell);

            }

            //interpol
            if (p.Pos == 30)
            {
                PlayerStep.MoveFrom30(g);
                //g.MoveToCell();

            }

            // tax
            if (cell.Type == 6)
            {
                //g.logp(g.Text("ProcessPosition.PayTax", "заплатите налог", "you need pay tax "));
                g.ToPay(cell.Rent);
            }

            //var offPos = new[] { 2, 7, 17, 22, 33, 36 };

            if (cell.Type == 4)
            {
                g.Map.TakeRandomCard();
                g.FixAction("random");
                ProcessRandom(g, p);

            }
            else if (p.Pos == 20 || p.Pos == 0 || (p.Pos == 10 && p.Police == 0))
                g.FinishStep("cell_" + p.Pos);
        }
예제 #7
0
        public static void MakeTrade(Game g)
        {
            g.CompletedTrades.Add(g.CurrTrade);

            Player firstPlayer = g.CurrTrade.from;
            Player secondPlayer = g.CurrTrade.to;

            var first_give = g.CurrTrade.give_cells.Select(x => g.Cells[x]).ToList();
            var second_give = g.CurrTrade.get_cells.Select(x => g.Cells[x]).ToList();

            first_give.ForEach(x => x.Owner = secondPlayer.Id);
            second_give.ForEach(x => x.Owner = firstPlayer.Id);
            //money
            firstPlayer.Money += g.CurrTrade.getMoney * 1000;
            firstPlayer.Money -= g.CurrTrade.giveMoney * 1000;

            secondPlayer.Money += g.CurrTrade.giveMoney * 1000;
            secondPlayer.Money -= g.CurrTrade.getMoney * 1000;

            g.Map.UpdateMap();
            g.Tlog("Trade.TradeOk", "обмен соостоялся", "Trade completed");
            g.FixAction(string.Format("tradeOk_give[{0}]_get[{1}]",
                string.Join(",", g.CurrTrade.give_cells),
                string.Join(",", g.CurrTrade.get_cells)));

            g.ToBeginRound();
        }
예제 #8
0
 public static void MakeRollFrom(Game g, int r1, int r2)
 {
     //make step
     g.LastRoll = new[] { r1, r2 };
     g.Curr.LastRoll = g.LastRoll;
     g.FixAction("roll");
 }
예제 #9
0
 public static void MakeRoll(Game g)
 {
     //make step
     g.LastRoll = g.IsManualMode ? ManualRolls(g) : RandomRolls();
     g.Curr.LastRoll = g.LastRoll;
     g.FixAction("roll");
 }