Example #1
0
        public Tuple <Player, int> Run()
        {
            Card cardOnBoard = RoundDeck.Draw();

            BoardInfo      = new BoardInfo(PlayersList, PlayersList[0].CardList);
            Info.boardInfo = BoardInfo;
            GiveOutCardsToPlayers();
            bool isSomebodyWin = false;

            CentralCard = RoundDeck.Draw();
            BoardInfo.Update(PlayersList, PlayersList[0].CardList, CentralCard);
            Player winner = new Player("winner");

            while (!isSomebodyWin)
            {
                if (currentPlayer == 0)
                {
                    // тут надо написать так, чтобы у карт, которые можно положить было выделение
                    bool markCard = true;
                    while (Info.mark == false)
                    {
                        var listCardsPlayer = PlayersList[0].CardList;
                        for (int i = 0; i < listCardsPlayer.Count(); i++)
                        {
                            if (markCard == true && (listCardsPlayer[i].Color == cardOnBoard.Color || listCardsPlayer[i].Inscription == cardOnBoard.Inscription))
                            {
                                Info.MarkCards.Add(i, true);
                            }
                            if (i == listCardsPlayer.Count() - 1)
                            {
                                markCard = false;
                            }
                        }
                    }
                    // какое-то условие
                    var turn = Turn.MakeTurn(CentralCard, PlayersList[0].CardList[Info.currentCard]);
                    Update(turn, PlayersList[0].CardList[Info.currentCard]);
                    PlayersList[currentPlayer].CardList.RemoveAt(Info.currentCard);
                    Info.mark = false;
                }
                else
                {
                    var bot        = PlayersList[currentPlayer] as Bot;
                    var turnResult = bot.MakeTurn(CentralCard);
                    if (turnResult == null)
                    {
                        bot.CardList.Add(RoundDeck.Draw());
                        var endTurnResult = bot.MakeTurnWithTakeCard(CentralCard);
                        if (endTurnResult != null)
                        {
                            Update(endTurnResult.Item2, endTurnResult.Item1);
                            PlayersList[currentPlayer].CardList.Remove(endTurnResult.Item1);
                        }
                    }
                    else
                    {
                        Update(turnResult.Item2, turnResult.Item1);
                    }
                    if (turnResult != null)
                    {
                        PlayersList[currentPlayer].CardList.Remove(turnResult.Item1);
                    }
                    Info.MarkCards.Clear();
                }
                NextPlayer();
                for (int i = 0; i < 4; i++)
                {
                    if (PlayersList[i].CardList.Count == 0)
                    {
                        winner        = PlayersList[i];
                        isSomebodyWin = true;
                    }
                }
                Thread.Sleep(100);
                BoardInfo.Update(PlayersList, PlayersList[0].CardList, CentralCard);
            }
            int score = 0;

            for (int i = 0; i < 4; i++)
            {
                score += PlayersList[1].CardList.Count * 10;
            }
            return(new Tuple <Player, int>(winner, score));
        }
Example #2
0
        public Tuple <Player, int> Run()
        {
            BoardInfo      = new BoardInfo(PlayersList, PlayersList[0].CardList);
            Info.boardInfo = BoardInfo;
            GiveOutCardsToPlayers();
            bool isSomebodyWin = false;

            CentralCard = RoundDeck.Draw();
            BoardInfo.Update(PlayersList, PlayersList[0].CardList, CentralCard);
            Player winner = new Player("winner");

            while (!isSomebodyWin)
            {
                if (currentPlayer == 0)
                {
                    List <bool> isAvailible     = new List <bool>();
                    var         listCardsPlayer = PlayersList[0].CardList;
                    for (int i = 0; i < listCardsPlayer.Count(); i++)
                    {
                        if (listCardsPlayer[i].Color == CentralCard.Color || listCardsPlayer[i].Inscription == CentralCard.Inscription)
                        {
                            isAvailible.Add(true);
                        }
                        else
                        {
                            isAvailible.Add(false);
                        }
                    }
                    var flag = false;
                    foreach (var bol in isAvailible)
                    {
                        if (bol)
                        {
                            flag = true;
                        }
                    }
                    if (!flag && !wastaking)
                    {
                        PlayersList[currentPlayer].CardList.Add(RoundDeck.Draw());
                        BoardInfo.Update(PlayersList, PlayersList[0].CardList, CentralCard);
                        wastaking = true;
                        continue;
                    }
                    else if (!flag && wastaking)
                    {
                        Thread.Sleep(150);
                        NextPlayer();
                        BoardInfo.Update(PlayersList, PlayersList[0].CardList, CentralCard);
                        continue;
                    }
                    Info.borders      = Translater.Translate(isAvailible);
                    Info.visibleCards = Translater.Translate(PlayersList[0].CardList);
                    Info.enabledCards = Translater.BoolTranslate(PlayersList[0].CardList);
                    while (Info.mark == false)
                    {
                    }
                    if (PlayersList[0].CardList[Info.currentCard].Color != CentralCard.Color &&
                        PlayersList[0].CardList[Info.currentCard].Inscription != CentralCard.Inscription)
                    {
                        Info.mark = false;
                        continue;
                    }
                    var turn = Turn.MakeTurn(CentralCard, PlayersList[0].CardList[Info.currentCard]);
                    Update(turn, PlayersList[0].CardList[Info.currentCard]);
                    PlayersList[currentPlayer].CardList.RemoveAt(Info.currentCard);
                    Info.mark = false;
                    Thread.Sleep(150);
                }
                else
                {
                    var bot        = PlayersList[currentPlayer] as Bot;
                    var turnResult = bot.MakeTurn(CentralCard);
                    if (turnResult == null)
                    {
                        bot.CardList.Add(RoundDeck.Draw());
                        var endTurnResult = bot.MakeTurnWithTakeCard(CentralCard);
                        if (endTurnResult != null)
                        {
                            Update(endTurnResult.Item2, endTurnResult.Item1);
                            PlayersList[currentPlayer].CardList.Remove(endTurnResult.Item1);
                        }
                    }
                    else
                    {
                        Update(turnResult.Item2, turnResult.Item1);
                    }
                    if (turnResult != null)
                    {
                        PlayersList[currentPlayer].CardList.Remove(turnResult.Item1);
                    }
                }
                NextPlayer();
                for (int i = 0; i < 4; i++)
                {
                    if (PlayersList[i].CardList.Count == 0)
                    {
                        winner        = PlayersList[i];
                        isSomebodyWin = true;
                    }
                }
                Thread.Sleep(250);
                BoardInfo.Update(PlayersList, PlayersList[0].CardList, CentralCard);
            }
            int score = 0;

            for (int i = 0; i < 4; i++)
            {
                score += PlayersList[1].CardList.Count * 10;
            }
            RoundDeck = new Deck();
            foreach (var player in PlayersList)
            {
                player.CardList.Clear();
            }
            return(new Tuple <Player, int>(winner, score));
        }