Exemplo n.º 1
0
        public Card playCardSmart(Suit leadSuit, GameState state)
        {
            List<Card> legal = getLegalMoves(leadSuit);

            Card played = AI.getBestMove(legal, state, index);
            Console.WriteLine(hand.Remove(played));
            return played;
        }
Exemplo n.º 2
0
        private static bool playout(GameState state, int pIndex)
        {
            GameState playState = state.getNextState(true, null, true);
            while (!playState.gameOver())
            {
                playState = playState.getNextState(true, null, true);
            }

            int bestScore = state.getBestScore();
            return bestScore == pIndex;
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            GameState state = new GameState();

            for (int i = 0; i < 52; i++)
            {
                state = state.getNextState(true, null, false);
            }

            state.printScores();
            Console.ReadLine();
        }
Exemplo n.º 4
0
        private static int getPlayouts(GameState state, Card card, int pIndex)
        {
            int wins = 0;

            if (state.gameOver()) return 0;
            GameState playState = state.getNextState(true, card, true);
            for (int i = 0; i < NUM_PLAYOUTS; i++)
            {
                if (playout(playState, pIndex))
                    wins++;
            }
            return wins;
        }
Exemplo n.º 5
0
 public static Card getBestMove(List<Card> legal, GameState state, int pIndex)
 {
     Card bestCard = legal[0];
     int maxWins = 0;
     for (int i = 0; i < legal.Count; i++)
     {
         int wins = getPlayouts(state, legal[i], pIndex);
         if(wins > maxWins)
         {
             maxWins = wins;
             bestCard = legal[i];
         }
     }
     return bestCard;
 }
Exemplo n.º 6
0
 public GameState getNextState(bool preserve, Card played, bool playRandom)
 {
     GameState newState = new GameState(players, turnIndex, trick, leadSuit, cardsPlayedInTrick);
     if (preserve)
     {
         if (played == null)
         {
             newState.getNextState(playRandom);
         }
         else
         {
             newState.getNextState(played);
         }
     }
     return newState;
 }