public GameData(int opponents, int numDecks) { _opponentsHand = new CrazyEightsHand[opponents]; for (int i = 0; i < opponents; i++) { _opponentsHand[i] = new CrazyEightsHand(); } deckManager = new CrazyEightDeckManager(numDecks); }
private static MoveInfo GetCardChoice(CrazyEightDeckManager deckManager, CrazyEightsHand hand, CardSuit wildSuit) { // super simple rules here // 1. Check top card of table // 2. Check for Crazy 8 // 3. Find number of rank matches // 4. Find number of suit matches // 5. if( have crazy eight ) then // play crazy eight // else if( rank matches > suit matches ) then // play matching rank // else if( suit matches > rank matches ) then // play matching suit // else // play random matching suit or rank MoveInfo info = new MoveInfo(); info.DrawCard = false; info.WildCardUsed = false; info.SelectedCard = null; Card topCard = deckManager.Table[deckManager.Table.Count - 1]; CardSuit matchSuit = wildSuit == CardSuit.None ? topCard.Suit : wildSuit; Card eightCard = hand.FindEight(); Card duece = hand.FindRank(CardRank.Two); // rules change if top card is an eight if (topCard.Rank == CardRank.Eight) { // if we can match rank, do so // that will force a play of an eight if (eightCard != null) { info.SelectedCard = eightCard; } else if (hand.GetSuitCount(matchSuit) > 0) { // get matching suit (order by rank) info.SelectedCard = hand.Cards.Where(c => c.Suit == matchSuit).OrderBy(c1 => c1.Rank).FirstOrDefault(); } else { info.DrawCard = true; } } else if (topCard.Rank == CardRank.Two && duece != null) { // play the duece on a draw two info.SelectedCard = duece; } else { // get suit count, without eights var suitCount = hand.Cards.Count(c => c.Suit == matchSuit && c.Rank != CardRank.Eight); var rankCount = hand.Cards.Count(c => c.Rank == topCard.Rank); // no eight, free to play as you wish if (suitCount > rankCount) { // get matching suit (order by rank) info.SelectedCard = hand.Cards .Where(c => c.Suit == matchSuit && c.Rank != CardRank.Eight) .OrderBy(c1 => c1.Rank) .FirstOrDefault(); } else if (rankCount > 0) { // get matching rank info.SelectedCard = hand.Cards .Where(c => c.Rank == topCard.Rank) .FirstOrDefault(); } else { // no matches above // see if we have an eight if (hand.Cards.Count(c => c.Rank == CardRank.Eight) > 0) { // get first eight info.SelectedCard = hand.Cards.Where(c => c.Rank == CardRank.Eight).FirstOrDefault(); } else { info.DrawCard = true; } } } if (info.SelectedCard != null) { if (info.SelectedCard.Rank == CardRank.Eight) { info.WildCardUsed = true; info.OverrideSuit = SelectOverrideSuit(hand); } } return info; }
private void OpponentTurn(CrazyEightDeckManager deckManager, Card[] opponentHands, CardSuit suitOverride ) { AIManager.MoveInfo info; //SetPrompt(); //_prompt = string.Format(Properties.Resources.Text_OpponentTurn, _playerNames[_currentPlayer - 1]); // move into UI //ClearMouseButtons(); //ClearSelectedCard(); //_deckSelected = false; //Invalidate(); // wait - simulate thinking //Thread.Sleep(WAIT_LENGTH); // send table to ai, with current hand // to evaluate next move, which will be added // to the table by the ai //if (_wildCard) // info = AIManager.EvaluateMove(_data.DeckManager, _data.OpponentsHands[_currentPlayer - 1], _suitOverride); //else // info = AIManager.EvaluateMove(_data.DeckManager, _data.OpponentsHands[_currentPlayer - 1], CardSuit.None); //if (info.DrawCard) //{ // if (DrawCard(_currentPlayer)) // { // _currentPlayer = NextPlayer(); // SetPrompt(); // //// player has to pass // //if (_currentPlayer == 0) // //{ // // // wrap around to player // // _prompt = Properties.Resources.Caption_YourTurn; // //} // } //} //else //{ // PlayCard(info.SelectedCard, _data.OpponentsHands[_currentPlayer - 1]); // _wildCard = false; // // check if this guy won // if (_data.OpponentsHands[_currentPlayer - 1].Cards.Count == 0) // { // EndHand(); // } // else // { // _currentPlayer = NextPlayer(); // SetPrompt(); // //if (_currentPlayer == 0) // //{ // // _prompt = Properties.Resources.Caption_YourTurn; // // if (info.WildCardUsed) // // { // // ShowWildcardDialog(info.OverrideSuit); // // } // //} // } // if (info.WildCardUsed) // { // _wildCard = true; // _suitOverride = info.OverrideSuit; // if (_currentPlayer == 0) // { // ShowWildcardDialog(info.OverrideSuit); // } // } //} }
internal static MoveInfo EvaluateMove(CrazyEightDeckManager deckManager, CrazyEightsHand hand, CardSuit wildSuit) { return GetCardChoice(deckManager, hand, wildSuit); }