コード例 #1
0
        private Card TryToNotWinTrick(PlayState playState, Card highCard, bool last)
        {
            if ((playState.Trick.Contains(new Card(Suit.Spades, FaceValue.Ace, true)) ||
                 playState.Trick.Contains(new Card(Suit.Spades, FaceValue.King, true))) &&
                AIHand.Contains(Suit.Spades, FaceValue.Queen) && playState.Lead.CardSuit == Suit.Spades)
            {
                return(new Card(Suit.Spades, FaceValue.Queen, true));
            }
            Card ret = null;

            foreach (Card c in AIHand.Cards)
            {
                if (c.CardSuit == playState.Lead.CardSuit)
                {
                    if (c.CardRank <= highCard.CardRank)
                    {
                        if (!(c.CardSuit == Suit.Spades && c.CardValue == FaceValue.Queen))
                        {
                            ret = c;
                        }
                    }
                }
            }

            if (ret == null)
            {
                if (playState.Lead.CardSuit == Suit.Spades)
                {
                    if (AIHand.Contains(Suit.Spades, FaceValue.King) && AIHand.Contains(Suit.Spades, FaceValue.Queen))
                    {
                        ret = new Card(Suit.Spades, FaceValue.King, true);
                    }
                    else if (AIHand.Contains(Suit.Spades, FaceValue.Ace) && AIHand.Contains(Suit.Spades, FaceValue.Queen))
                    {
                        ret = new Card(Suit.Spades, FaceValue.Ace, true);
                    }
                    else if (last == true)
                    {
                        ret = GetHighestCardOfSuit(playState, playState.Lead.CardSuit);
                    }
                    else
                    {
                        ret = GetLowestCardOfSuit(playState.Lead.CardSuit);
                    }
                }
                else
                {
                    if (last == true)
                    {
                        ret = GetHighestCardOfSuit(playState, playState.Lead.CardSuit);
                    }
                    else
                    {
                        ret = GetLowestCardOfSuit(playState.Lead.CardSuit);
                    }
                }
            }

            if (ret.CardSuit != playState.Lead.CardSuit)
            {
                throw new InvalidOperationException("AI - NOT FOLLOWING SUIT");
            }
            return(ret);
        }
コード例 #2
0
        /* Constructor */
        internal Engine()
        {
            options = new Options();
            InitializeComponent();
            deck            = new Deck(true);
            userHand        = new Hand();
            passing         = new int[3];
            computerPlayers = new AI[3];
            tricks          = new Tricks[4];
            playState       = new PlayState();
            userTricks      = new Tricks();
            userScore       = new List <int>();
            for (int i = 0; i < 3; i++)
            {
                computerPlayers[i] = new AI();
            }

            for (int i = 0; i < 3; i++)
            {
                passing[i] = -1;
            }

            for (int i = 0; i < 3; i++)
            {
                tricks[i] = new Tricks();
            }

            gEngine = new GraphicsEngine(surfaceControl1);

            options.LoadNames();

            computerPlayers[0].Name = options.comp1;
            computerPlayers[1].Name = options.comp2;
            computerPlayers[2].Name = options.comp3;

            playState.UserName = "******";

            UnmanagedMemoryStream lGlass = Properties.Resources.glass;

            byte[] bGlass = new byte[lGlass.Capacity];
            lGlass.Read(bGlass, 0, (int)lGlass.Capacity);
            glass = new Sound(bGlass);

            UnmanagedMemoryStream lBawong = Properties.Resources.bawong;

            byte[] bBawong = new byte[lBawong.Capacity];
            lBawong.Read(bBawong, 0, (int)lBawong.Capacity);
            bawong = new Sound(bBawong);

            bawong.Volume = 20;
            glass.Volume  = 20;

            userScore.Add(0);
            for (int i = 0; i < 3; i++)
            {
                computerPlayers[i].CreateNewScore(0);
            }

            sb.SetScores(userScore.AsReadOnly(), computerPlayers[0].Score, computerPlayers[1].Score, computerPlayers[2].Score,
                         playState.UserName, computerPlayers[0].Name, computerPlayers[1].Name, computerPlayers[2].Name, false);

            SdlDotNet.Core.Events.TargetFps        = 500;
            SdlDotNet.Core.Events.Quit            += new EventHandler <QuitEventArgs>(ApplicationQuit);
            SdlDotNet.Core.Events.MouseButtonDown += new EventHandler <MouseButtonEventArgs>(MouseButtonDownEvent);
            SdlDotNet.Core.Events.MouseButtonUp   += new EventHandler <MouseButtonEventArgs>(MouseButtonUpEvent);
            SdlDotNet.Core.Events.Tick            += new EventHandler <TickEventArgs>(TickEvent);
        }