コード例 #1
0
ファイル: GameManager.cs プロジェクト: kolyan1981by/monop
        public static void CheckAuction(Game g, Player bot)
        {
            var p = bot;

            var cell = g.currAuction.cell;

            var sum = g.GetPlayerCash(p.Id);

            var fact = BotBrain.FactorOfBuy(g, p, cell);

            var aucSum = cell.Cost * fact;

            if (sum >= aucSum && aucSum > g.currAuction.nextBid)
            {
                g.currAuction.currBid = g.currAuction.nextBid;
                g.Tlog("Auction.Yes", "@p{0} дает {1}", "@p{0} bid {1}", p.Id, g.currAuction.currBid.PrintMoney());
                g.currAuction.LastBiddedPlayer = p;

            }
            else
            {
                g.Tlog("Auction.No", "@p{0} выбывает", "@p{0} is out", p.Id);
                //g.aucState.allPlayers = g.aucState.allPlayers.Where(x => x.Id != p.Id).ToList();
                p.InAuction = false;
            }
        }
コード例 #2
0
ファイル: BotBrainTrade.cs プロジェクト: kolyan1981by/monop
        public static bool TryDoTrade(Game g)
        {
            //var res = MakeExchange(g, g.Curr);

            var trs = GetValidTrades(g, g.Curr);

            Trade tr = null;

            foreach (var item in trs)
            {
                var res = g.RejectedTrades.Any(x => x.Equals(item));
                if (!res)
                {
                    tr = item;
                    break;
                }
            }

            if (tr != null)
            {
                g.CurrTrade = tr;
                g.Tlog("CheckTradeJob.FromBotToHuman", "Обмен между {0} и {1}", "Exchange between {0} and {1}", tr.from.Name, tr.to.Name);
                g.SetState(GameState.Trade);
                //GameManager.CheckTradeJob(g);
                return true;
            }

            return false;
        }
コード例 #3
0
ファイル: PlayerAction.cs プロジェクト: kolyan1981by/monop
 public static void MakeAuctionNo(Game g, string userName)
 {
     var p = g.GetPlayer(userName);
     g.Tlog("PlayerAction.AuctionNo.PlayerOut", "@p{0} выбывает", "@p{0} is out", p.Id);
     p.InAuction = false;
     GameManager.CheckAuctionWinner(g);
 }
コード例 #4
0
ファイル: GameManager.cs プロジェクト: kolyan1981by/monop
        public static void CheckAuctionWinner(Game g)
        {
            var count = g.Players.Count(x => x.InAuction);

            if (count == 0 || (g.currAuction.LastBiddedPlayer != null && count == 1))
                g.currAuction.IsFinished = true;

            if (g.currAuction.IsFinished)
            {
                var last = g.currAuction.LastBiddedPlayer;
                if (last != null)
                {
                    if (BotBrain.MortgageSell(g, last, g.currAuction.currBid))
                    {
                        g.Tlog("Game.CheckAuctionWinner.Winner", "@p{0} выиграл", "@p{0} winner", last.Id);
                        //set winner
                        GameManager.SetAuctionWinner(g);
                    }
                }
                //g.Tlog("Game.CheckAuctionWinner.FinishStepForBot", "FinishStepForBot", "FinishStepForBot");

                g.FinishStep();

            }
        }
コード例 #5
0
ファイル: AjaxController.cs プロジェクト: kolyan1981by/monop
        public ActionResult Roll(int roll)
        {
            g = GetGame();
            if (g == null) return RedirectToAction("Index", "Home");

            if (g.State == GameState.BeginStep)
            {
                if (g.IsManualMode)
                {
                    var p = g.GetPlayer(CurrUser);

                    if (p.ManRoll == 0)
                    {
                        p.ManRoll = roll;
                        g.Tlog("step.ManRoll.pressed", "{0} нажал", "{0} pressed", p.htmlName);
                    }
                }
                else
                    if (g.IsCurrPlayer(CurrUser))
                        PlayerStep.MakeStep(g);
            }

            return RenderGame(g);
        }
コード例 #6
0
ファイル: PlayerAction.cs プロジェクト: kolyan1981by/monop
        public static void MakeAuctionYes(Game g, string userName)
        {
            var pl = g.GetPlayer(userName);

            if (pl == null) return;

            //StartAction(g);
            g.CleanTimeOut();

            var mm = g.GetPlayerCash(pl.Id);

            var LastBiddedPlayer = g.currAuction.LastBiddedPlayer;

            if (LastBiddedPlayer != null)
            {
                if (LastBiddedPlayer.Id == pl.Id) return;
            }

            if (mm >= g.currAuction.nextBid)
            {
                g.currAuction.currBid += 50000;
                g.Tlog("Auction.Yes", "@p{0} дает {1}", "@p{0} bid {1}", pl.Id, g.currAuction.currBid.PrintMoney());
                g.currAuction.LastBiddedPlayer = pl;

            }
            else
            {
                g.Tlog("PlayerAction.AuctionYes.NoMoney", "@p{0} не хватает денег ", "@p{0} no money", pl.Id);
                pl.InAuction = false;
            }
            //GameManager.CheckAuctionWinner(g);
        }
コード例 #7
0
ファイル: PlayerAction.cs プロジェクト: kolyan1981by/monop
        public static bool SellHouses(Game g, int pid, IEnumerable<int> ids)
        {
            var p = g.GetPlayer(pid);
            g.Tlog("PlayerAction.SellHouses.Sell", "@p{0} продал дом", "@p{0} sell house", p.Id);

            bool res = false;
            foreach (var id in ids)
            {
                var cell = g.Cells[id];

                if (cell.IsMonopoly)
                {

                    if (cell.HousesCount > 0)
                    {
                        cell.HousesCount--;
                        p.Money += cell.HouseCost;
                        res = true;

                    }

                }

            }

            return res;
        }
コード例 #8
0
ファイル: GameManager.cs プロジェクト: kolyan1981by/monop
        private static Player GetNextAuctionPlayer(Game g)
        {
            int nextId = g.currAuction.LastBiddedPlayer != null ?
                g.currAuction.LastBiddedPlayer.Id :
                g.Curr.Id;

            var pls = g.Players.Where(x => x.InAuction).Select(x => x.Id).ToArray();

            Player next = null;

            for (int i = 0; i < pls.Length; i++)
            {
                if (pls[i] == nextId)
                    if (i != pls.Length - 1)
                        next = g.GetPlayer(pls[i + 1]);
                    else next = g.GetPlayer(pls[0]);
            }

            g.currAuction.CurrPlayer = next;

            if (g.conf.DebugMode)
                g.Tlog("GetNextAuctionPlayer", "next {0}", "next {0}", next.Id);
            return next;
        }
コード例 #9
0
ファイル: GameManager.cs プロジェクト: kolyan1981by/monop
        public static void RunTradeJob(Game g)
        {
            var trade = g.CurrTrade;
            if (trade != null)
            {
                if (trade.from.IsBot && trade.to.IsBot)
                {
                    GameManager.MakeTrade(g);
                    if (g.conf.DebugMode) g.Tlog("GameMan.CheckTradeJob.Bot2Bot", "[DebugMode][MakeTrade] bot->bot ", "[DebugMode][MakeTrade] bot->bot ");
                }

                if (!trade.from.IsBot && trade.to.IsBot)
                {
                    var res = BotBrainTrade.MakeTradeFromPlayer(g);
                    if (!res)
                    {
                        g.Tlog("GameMan.CheckTradeJob.Human2Bot", "[{0} don't want trade]", "[{0} не хочет меняться]", trade.to.Id);
                    }
                    //if (g.DebugMode) g.Tlog("[DebugMode][MakeTradeFromPlayer] human->bot");
                }

                if (!trade.to.IsBot)
                {
                    var res = CheckBotToHumanRejectedTrades(g);
                    if (res)
                    {
                        g.ToBeginRound();
                    }
                }

            }
        }
コード例 #10
0
ファイル: GameManager.cs プロジェクト: kolyan1981by/monop
        public static void RunBeginStepJob(Game g)
        {
            try
            {
                if (g.IsManualMode)
                {
                    var allPlayersRoll = g.Players.Where(x => !x.IsBot).All(x => x.ManRoll != 0);

                    if (allPlayersRoll)
                    {
                        PlayerStep.MakeStep(g);
                    }
                }
                else
                {
                    if (g.Curr.IsBot)
                        PlayerStep.MakeStep(g);
                }

            }
            catch (Exception ex)
            {
                g.Tlog("GameMan.CheckState.rror", "exception {0}", "exception {0}", ex.StackTrace);
                throw;
            }
        }
コード例 #11
0
ファイル: GameManager.cs プロジェクト: kolyan1981by/monop
        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();
        }
コード例 #12
0
ファイル: GameManager.cs プロジェクト: kolyan1981by/monop
        public static void LeaveGame(Game g, string uname)
        {
            if (g.IsFinished) return;

            var p = g.GetPlayer(uname);

            if (p == null) return;

            if (g.Players.Count > 2)
            {
                foreach (var cell in g.Map.CellsByUser(p.Id))
                {
                    cell.Owner = null;
                    cell.HousesCount = 0;
                }
                g.Tlog("Game.LeaveGame.PlayerLeaveGame", "@p{0} покинул игру", "@p{0} leave Game ", p.Id);
                //g.Players.Remove(p);
                p.Deleted = true;
                g.pcount--;
                g.OnLeave(p.Name, false);

            }
            else
                if (g.Players.Count == 2)
                {
                    g.Winner = g.Players.First(x => x.Id != p.Id);
                    g.Tlog("Game.LeaveGame.PlayerIsWinner", "@p{0} ПОБЕДИТЕЛЬ", "@p{0} is WINNER ", g.Winner.Id);
                    g.SetState(GameState.FinishGame);
                    g.OnLeave(p.Name, false);
                    g.OnLeave(g.Winner.Name, true);

                }
        }
コード例 #13
0
ファイル: GameManager.cs プロジェクト: kolyan1981by/monop
        public static void InitAuction(Game g)
        {
            var cell = g.CurrCell;

            g.Tlog("GameMan.InitAuction", "[Аукцион] земля={0}", "[Auction] cell={0}", cell.Name);

            g.currAuction = new AuctionState();

            g.currAuction.cell = cell;
            g.currAuction.currBid = cell.Cost;

            g.currAuction.CurrPlayer = g.Curr;

            g.Players.ForEach(x => x.InAuction = true);

            //if (g.aucState.allPlayers.Count() < 1)
            //{
            //    g.Tlog("step.Auction.NoPlayers", "АУКЦИОН нет игроков с деньгами для аукциона", "AUCTION no players with money");
            //    g.Finish();
            //}
            //else if (g.aucState.allPlayers.Count() == 1)
            //{
            //    g.Tlog("step.Auction.OnePlayer", "АУКЦИОН вы можете купить", "AUCTION you can buy");
            //}
        }