コード例 #1
0
ファイル: Engine.cs プロジェクト: CommName/MauMau
        public Engine(int numOfBots)
        {
            deck = new Spil(true);
            if (numOfBots == 0)
            {
                player1 = new PlayerUser(false);
                player2 = new PlayerUser(false);
            }
            else if (numOfBots == 1)
            {
                Random random = new Random();
                if (random.Next() % 2 == 0)
                {
                    player1 = new PlayerUser(false);
                    player2 = new PlayerUser(true);
                }
                else
                {
                    player1 = new PlayerUser(true);
                    player2 = new PlayerUser(false);
                }
            }
            else
            if (numOfBots == 2)
            {
                player1 = new PlayerUser(new _16114.Gilgamesh());
                player2 = new PlayerUser(new _16114.Gilgamesh());
            }
            else
            {
                throw new Exception("Neispravan broj igraca");
            }


            player1.nextPlayer     = player2;
            player1.previousPlayer = player2;
            player2.nextPlayer     = player1;
            player2.previousPlayer = player1;


            topCard    = deck.Karte[0];
            cardsPlaid = new List <Karta>();
            deck.Karte.RemoveAt(0);
            //Da ne pocninje partiju sa kaznenim kartama
            if (topCard.Broj == "7" || (topCard.Broj == "2" && topCard.Boja == Boja.Tref))
            {
                int index = 0;
                while (deck.Karte[index].Broj == "7" || (deck.Karte[index].Broj == "2" && deck.Karte[index].Boja == Boja.Tref))
                {
                    index++;
                }
                Karta pom = topCard;
                topCard           = deck.Karte[index];
                deck.Karte[index] = pom;
            }
            cardsPlaid.Add(topCard);
            suit         = Boja.Unknown;
            penalty      = 0;
            drewCard     = false;
            playerChange = true;

            //Dealibg cards
            player1.SetRuka(deck.Karte.GetRange(0, 6));
            deck.Karte.RemoveRange(0, 6);
            player2.SetRuka(deck.Karte.GetRange(0, 6));
            deck.Karte.RemoveRange(0, 6);
            player1.Bacenekarte(cardsPlaid, Boja.Unknown, 6);
            player2.Bacenekarte(cardsPlaid, Boja.Unknown, 6);
            cardsPlaid.Clear();
            current = player1;
        }
コード例 #2
0
ファイル: Engine.cs プロジェクト: CommName/MauMau
        public bool Game()
        {
            //bug kraj poteza kupio kartu



            bool bacioKartu = false;

            if (playerChange)
            {
                current.Bacenekarte(cardsPlaid, suit, current.previousPlayer.Hand.Count);
                cardsPlaid   = null;
                playerChange = false;
            }
            current.findBestMove();


            //kaznene karte
            if (((int)current.BestMove.Tip & (int)TipPoteza.KupiKazneneKarte) != 0)
            {
                if (penalty == 0)
                {
                    throw new Exception("Nije potrebno kupiti kaznenu kartu");
                }
                //Popraviti ovo da  vrati false
                if (deck.Karte.Count < penalty)
                {
                    return(false);
                }
                current.KupioKarte(kupi(penalty));
                penalty = 0;
            }

            //baci kartu
            if ((((int)current.BestMove.Tip & (int)TipPoteza.BacaKartu) != 0) || ((current.BestMove.Tip & TipPoteza.PromeniBoju) != 0))
            {
                cardsPlaid = new List <Karta>();
                if (current.BestMove.Karte.Count == 0)
                {
                    throw new Exception("Nije selektovana karta");
                }
                for (int i = 0; i < current.BestMove.Karte.Count; i++)
                {
                    if (isValid(current.BestMove.Karte[i]))
                    {
                        bacioKartu = true;
                        drewCard   = false;
                        cardsPlaid.Add(current.BestMove.Karte[i]);
                        topCard = current.BestMove.Karte[i];

                        //7
                        if (topCard.Broj == "7")
                        {
                            penalty += 2;
                        }
                        else if (penalty != 0)
                        {
                            throw new Exception("Nije kupio kaznene karte");
                        }
                        //2 tref
                        if (topCard.Boja == Boja.Tref && topCard.Broj == "2")
                        {
                            penalty = 4;
                        }
                        //J
                        if (topCard.Broj == "J")
                        {
                            if ((current.BestMove.Tip & TipPoteza.PromeniBoju) != TipPoteza.PromeniBoju)
                            {
                                throw new Exception("Pogresan tip za J");
                            }
                            suit = current.BestMove.NovaBoja;
                            if (suit == Boja.Unknown)
                            {
                                throw new Exception("Boja nije setovana");
                            }
                        }
                        else
                        {
                            suit = Boja.Unknown;
                        }
                    }
                    else
                    {
                        throw new Exception("Invalid move");
                    }
                }
                if (topCard.Broj != "A") //A

                {
                    if (topCard.Broj == "8")
                    {
                        //8 skippped
                        current = current.nextPlayer.nextPlayer;
                    }
                    else
                    {
                        current      = current.nextPlayer;
                        playerChange = true;
                    }
                }
            }
            //kupi kartu
            if (!playerChange)
            {
                if (((int)current.BestMove.Tip & (int)TipPoteza.KupiKartu) != 0)
                {
                    if (drewCard)
                    {
                        throw new Exception("Vec je kupljena karta");
                    }
                    drewCard = true;
                    if (deck.Karte.Count > 0)
                    {
                        current.KupioKarte(kupi(1));
                    }
                    else
                    {
                        return(false);
                    }
                }
            }

            //Kraj poteza
            if (!playerChange)
            {
                if (((int)current.BestMove.Tip & (int)TipPoteza.KrajPoteza) != 0)
                {
                    if (drewCard || bacioKartu)
                    {
                        if (!bacioKartu)
                        {
                            current      = current.nextPlayer;
                            playerChange = true;
                            drewCard     = false;
                        }
                    }
                    else
                    {
                        throw new Exception("Ne moze da zavrsi potez");
                    }
                }
            }
            if (gameOver())
            {
                return(false);
            }


            return(true);
        }