private PlayedCards GetStartingCards() { var cardsToPlay = new PlayedCards(this); // try to play hands with the most number of cards first. if (Hand.HasMatchingCards(PokerHands.Quadruple)) { IEnumerable <Card> lowestMatchingCards = GetLowestMatchingCards(PokerHands.Quadruple); cardsToPlay.Type = PokerHands.Quadruple; cardsToPlay.AddCards(lowestMatchingCards); } else if (Hand.HasMatchingCards(PokerHands.Triple)) { IEnumerable <Card> lowestMatchingCards = GetLowestMatchingCards(PokerHands.Triple); cardsToPlay.Type = PokerHands.Triple; cardsToPlay.AddCards(lowestMatchingCards); } else if (Hand.HasMatchingCards(PokerHands.Double)) { IEnumerable <Card> lowestMatchingCards = GetLowestMatchingCards(PokerHands.Double); cardsToPlay.Type = PokerHands.Double; cardsToPlay.AddCards(lowestMatchingCards); } else { // we get to start off the hand Card lowestCard = GetLowestCard(); cardsToPlay.Type = PokerHands.Single; cardsToPlay.AddCard(lowestCard); } return(cardsToPlay); }
//private void giveCardsToReplayPlayer(Player player, int amountOfCards) //{ // List<Card> cards = getCardsFromDeck(amountOfCards); // player.Hand.AddRange(cards); // //foreach (var item in cards) // //{ // // moves.Add(new Move(player.UserName, player.Game.GameID, item, moveType)); // //} // foreach (Player selfPlayer in Players) // { // if (selfPlayer == player) // { // player.IGameCallback.AssignCards(cards); // selfPlayer.IGameCallback.NotifyPlayersNumberOfCardsTaken(amountOfCards, player.UserName); // } // } // If player picks cards, uno is reset because they have more then one card. //CurrentPlayer.UnoSaid = false; //} public void StartGame() { List <string> playersUserNames = Players.Select(x => x.UserName).ToList(); foreach (Player player in Players) { // TODO Make sure this value is 7, I keep changing it to test UNO player.IGameCallback.InitializeGame(playersUserNames); } foreach (Player player in Players) { giveCardsToPlayer(player, 7, Move.Types.Assigned); } do { PlayedCards.Push(Deck.Pop()); }while (PlayedCards.Peek().Type != CardType.normal); foreach (Player player in Players) { player.IGameCallback.CardPlayed(PlayedCards.Peek(), "FirstAtStart"); player.IGameCallback.TurnChanged(CurrentPlayer.UserName); } }
public HashSet <Coordinate> GetValidPlayableSpaces() { if (ValidPlayableSpacesCache != null && ValidPlayableSpacesCache.Count > 0) { return(ValidPlayableSpacesCache); } // For every played card, add every neighboring coordinate to a HashSet (no duplicates) HashSet <Coordinate> neighborsOfHappyCoordinates = new HashSet <Coordinate>(GetHappyCoordinates().SelectMany(coordinate => coordinate.GetNeighbors())); HashSet <Coordinate> neighborsOfNotHappyCoordinates = new HashSet <Coordinate>(GetNotHappyCoordinates().SelectMany(coordinate => coordinate.GetNeighbors())); HashSet <Coordinate> finalCut = new HashSet <Coordinate>(); // For each considered Coordinate, if all the following is true, consider that spot valid: // - there are no cards on that spot // - there are no happy cards neighboring that spot foreach (Coordinate consideredCoordinate in neighborsOfNotHappyCoordinates) { if (PlayedCards.ContainsKey(consideredCoordinate)) { continue; } if (neighborsOfHappyCoordinates.Contains(consideredCoordinate)) { continue; } finalCut.Add(consideredCoordinate); } ValidPlayableSpacesCache = finalCut; return(finalCut); }
public void RemoveCards(PlayedCards playedCards) { foreach (var card in playedCards) { Hand.RemoveCard(card); } }
public bool ShouldCoordinateBeIncompletable(Coordinate forCoordinate) { if (!PlayedCards.ContainsKey(forCoordinate)) { Debug.LogError($"Asked if coordinate {forCoordinate.ToString()} should be incompleteable, but that coordinate isn't in this play field."); return(false); } int requiredNeighbors = PlayedCards[forCoordinate].FaceValue; int occuppiedNeighbors = OccuppiedNeighborsAtCoordinate(forCoordinate); if (requiredNeighbors == occuppiedNeighbors) { return(false); // Presumably already happy } HashSet <Coordinate> validSpaces = GetValidPlayableSpaces(); int playableSpotNeighbors = forCoordinate.GetNeighbors().Count(neighbor => validSpaces.Contains(neighbor)); if (occuppiedNeighbors + playableSpotNeighbors < requiredNeighbors) { return(true); } return(false); }
public void EndRound() { gameInstance.GetGameTableRefrence().DealCards(); PlayedCards.ResetPlayedCards(); gameInstance.GetGameTableRefrence().UpdatePlayerDeckValues(); gameInstance.RoundEnded(firstPlayer); }
/// <summary> /// Plays a card from the given player's hand. /// </summary> /// <param name="player">The player playing the card. Player's hand must con</param> /// <param name="card"></param> /// <returns></returns> public bool PlayCard(HanabiPlayer player, int cardIndex) { var card = Players[player.ID].Hand[cardIndex]; Players[GetPlayerID(player)].Hand.RemoveAt(cardIndex); DrawCard(player); if (IsPlayable(card)) { Players[player.ID].Action(this, card, true, true); PlayedCards.Add(card); if (card.Number == highestCard && HintsRemaining < 8) { HintsRemaining++; } if (Score == 25) { Ended = true; } return(true); } else { Players[player.ID].Action(this, card, true, false); BombsUsed++; if (BombsUsed >= 4) { Ended = true; } return(false); } }
public void GetNewHypotheticalPlacementEffects(PlayingCard forCard, Coordinate onCoordinate, out HashSet <PlayingCard> newHypotheticalIncompleteableCards, out HashSet <PlayingCard> newHypotheticalHappyCards) { newHypotheticalIncompleteableCards = new HashSet <PlayingCard>(); newHypotheticalHappyCards = new HashSet <PlayingCard>(); PlayFieldData hypotheticalPlayField = CurrentPlayField.CloneData(); hypotheticalPlayField.SetCard(forCard.RepresentingCard, onCoordinate); IEnumerable <Coordinate> newHypotheticalIncompleteableCoordinates = hypotheticalPlayField.GetIncompleteableCoordinates().Except(CurrentPlayField.GetIncompleteableCoordinates()); IEnumerable <Coordinate> newHypotheticalHappyCoordinates = hypotheticalPlayField.GetHappyCoordinates().Except(CurrentPlayField.GetHappyCoordinates()); newHypotheticalIncompleteableCards = new HashSet <PlayingCard>(PlayedCards.Where(card => newHypotheticalIncompleteableCoordinates.Contains(card.OnCoordinate))); newHypotheticalHappyCards = new HashSet <PlayingCard>(PlayedCards.Where(card => newHypotheticalHappyCoordinates.Contains(card.OnCoordinate))); if (newHypotheticalIncompleteableCoordinates.Contains(onCoordinate)) { newHypotheticalIncompleteableCards.Add(forCard); } if (newHypotheticalHappyCoordinates.Contains(onCoordinate)) { newHypotheticalHappyCards.Add(forCard); } }
public void PlayCard(PlayingCard toPlay, Coordinate onCoordinate) { toPlay.SetCoordinate(onCoordinate); toPlay.transform.SetParent(transform, true); PlayedCards.Add(toPlay); CurrentPlayField.SetCard(toPlay.RepresentingCard, onCoordinate); }
public void SeedInitialCard(CardData forCard) { PlayingCard newCard = GeneratePlayingCard(forCard); newCard.SetCoordinate(new Coordinate(0, 0), DegreesOfSpeed.Instantly); PlayedCards.Add(newCard); CurrentPlayField.SetCard(forCard, new Coordinate(0, 0)); }
public AI(List <int> C, List <int> D, List <int> H, List <int> S) { this.AI_hand = new Hand(C, D, H, S); this.CardsHistory = new AI.PlayedCards(); this.Points = Count_Points(); this.Find_Color(); this.Grandpa_hand = null; }
public string PlayCard(int cardIndex) { var card = Hand[cardIndex]; PlayedCards.Add(WebUtility.HtmlEncode(Hand[cardIndex])); Hand.RemoveAt(cardIndex); return(card); }
/// <summary> /// Initializes a new deck and shuffles /// </summary> //public Deck(int numberOfDecks = 1) //{ // show = new Display(); // Initialize(numberOfDecks); //} public Deck(List <ICard> customDeck, IDisplay disp) { RemainingCards.Clear(); PlayedCards.Clear(); RemainingCards = customDeck; show = disp; usingCustomDeck = true; NumberOfDecks = 1; }
private void refillDeck() { Card lastCard = PlayedCards.Pop(); PlayedCards = shuffle(PlayedCards); this.Deck = this.PlayedCards; this.PlayedCards = new Stack <Card>(); PlayedCards.Push(lastCard); }
public void RemoveCard(Coordinate atCoordinate) { PlayedCards.Remove(atCoordinate); ValidPlayableSpacesCache = null; HappyCoordinatesCache = new HashSet <Coordinate>(); NotHappyCoordinatesCache = new HashSet <Coordinate>(PlayedCards.Keys); HappyCoordinatesAreDirty = true; }
public bool IsPlayable(HanabiCard card) { if (PlayedCards.Count(c => c.Color == card.Color && c.Number == card.Number) >= 1) { return(false); } else if (PlayedCards.Count(c => c.Color == card.Color && c.Number == (card.Number - 1)) >= 1) { return(true); } return(card.Number == 1); }
private bool isValidCard(Player player, Card cardtoplay) { Card tableCard = PlayedCards.Peek(); // Only current player may play a card if (CurrentPlayer != player) { Debug.WriteLine($"{player.UserName} tried to play a card, but it was not their turn"); return(false); } if (!player.HasCard(cardtoplay)) { Debug.WriteLine($"{player.UserName} tried to play a card, but it was not in their hand"); return(false); } // If there is a card draw queue, only 'attack' cards may be played if (cardPickQueue != 0) { if (cardtoplay.Type == CardType.draw4Wild || cardtoplay.Type == CardType.draw2) { return(true); } else { Debug.WriteLine($"{player.UserName} tried to play a card, but it was not an attack card. Picking queue: {cardPickQueue}"); return(false); } } // Wild cards can be played on any color if (cardtoplay.Type == CardType.draw4Wild || cardtoplay.Type == CardType.wild) { return(true); } // Any matching color can be played, or matching numbers for normal cards else if (cardtoplay.Color == tableCard.Color || (cardtoplay.Type == CardType.normal && cardtoplay.Number == tableCard.Number)) { return(true); } // Any matching types can also be played else if (cardtoplay.Type == tableCard.Type && cardtoplay.Type != CardType.normal) { return(true); } Debug.WriteLine($"{player.UserName} tried to play a card, but it was not a valid card for unknown reasons"); return(false); }
public bool TryPlayCard(Player playerWhoPerformedAction, Card card) { if (isValidCard(playerWhoPerformedAction, card)) { if (PreviousPlayer != null) { if (PreviousPlayer.Hand.Count == 1 && !PreviousPlayer.UnoSaid) { MakePreviousPlayerUnoSafe(); } } cardAction(card); moves.Add(new Move(playerWhoPerformedAction.UserName, playerWhoPerformedAction.Game.GameID, card, Move.Types.Play)); PlayedCards.Push(card); playerWhoPerformedAction.Remove(card); // Tell other users a card was played foreach (Player p in Players) { if (p.UserName != playerWhoPerformedAction.UserName) //Prevent deadlock { p.IGameCallback.CardPlayed(card, playerWhoPerformedAction.UserName); } } // Check end game condition if (playerWhoPerformedAction.Hand.Count() == 0) { gameHasEnded = true; //game.End(); foreach (Player player in Players) { if (player.UserName != playerWhoPerformedAction.UserName) //Prevent deadlock { player.IGameCallback.EndOfTheGame(playerWhoPerformedAction.UserName); } } } EndTurn(); return(true); } return(false); }
public HashSet <PlayingCard> GetNewlyNotCompleteableCards() { HashSet <PlayingCard> newCards = new HashSet <PlayingCard>(); HashSet <Coordinate> incompleteableCoordinates = CurrentPlayField.GetIncompleteableCoordinates(); foreach (PlayingCard currentCard in PlayedCards.Where(card => incompleteableCoordinates.Contains(card.OnCoordinate))) { if (!currentCard.CannotBeCompleted) { newCards.Add(currentCard); } } return(newCards); }
public HashSet <PlayingCard> GetNewlyHappyCards() { HashSet <PlayingCard> newCards = new HashSet <PlayingCard>(); HashSet <Coordinate> happyCoordinates = CurrentPlayField.GetHappyCoordinates(); foreach (PlayingCard currentCard in PlayedCards.Where(card => happyCoordinates.Contains(card.OnCoordinate))) { if (!currentCard.IsHappy) { newCards.Add(currentCard); } } return(newCards); }
public void SetCard(CardData forCard, Coordinate onCoordinate) { ValidPlayableSpacesCache = null; NotHappyCoordinatesCache.Add(onCoordinate); HappyCoordinatesAreDirty = true; if (PlayedCards.ContainsKey(onCoordinate)) { PlayedCards[onCoordinate] = forCard; } else { PlayedCards.Add(onCoordinate, forCard); } }
public Rect GetDimensions() { if (PlayedCards.Count == 0) { return(new Rect()); } Coordinate leftMost = PlayedCards.Select(x => x.OnCoordinate).OrderBy(x => x.X).First(); Coordinate rightMost = PlayedCards.Select(x => x.OnCoordinate).OrderByDescending(x => x.X).First(); Coordinate bottomMost = PlayedCards.Select(x => x.OnCoordinate).OrderBy(x => x.Y).First(); Coordinate topMost = PlayedCards.Select(x => x.OnCoordinate).OrderByDescending(x => x.Y).First(); return(new Rect(leftMost.WorldspaceCoordinate.x, bottomMost.WorldspaceCoordinate.y, rightMost.WorldspaceCoordinate.x - leftMost.WorldspaceCoordinate.x, topMost.WorldspaceCoordinate.y - bottomMost.WorldspaceCoordinate.y)); }
public override PlayedCards PlayTurn(PlayedCards currentMove) { PlayedCards cardsToPlay; // Are we playing the first turn of this sequence? if (currentMove == null || currentMove[0] == null) { cardsToPlay = GetStartingCards(); } else { cardsToPlay = GetCardsBetterThan(currentMove); } return(cardsToPlay); }
public void Reset() { foreach (Card c in PlayedCards) { c.PeggingRound = 0; c.CanBePlayed = true; c.WasPlayed = false; Count = 0; } TurnPlayer.Alert = ""; PrevTurnPlayer.Alert = ""; SwapPlayers(); PlayedCards.Clear(); PeggingRound = 1; }
public override PlayedCards PlayTurn(PlayedCards currentMove) { var cardsToPlay = new PlayedCards(this); // display the cards to the player DisplayCardList(); bool valid = false; do { var stillBuildingHand = true; do { int selectedCardIndex = GetUserSelectedCardIndex(); if (selectedCardIndex >= 0) { Card selectedCard = Hand[selectedCardIndex]; cardsToPlay.AddCard(selectedCard); valid = true; } if (!ContinueBuildingHandPrompt()) { stillBuildingHand = false; } } while (stillBuildingHand); try { // validate the move cardsToPlay.Validate(currentMove); } catch (Exception ex) { cardsToPlay.Clear(); Console.WriteLine("Invalid move: " + ex.Message); valid = false; } } while (valid == false); // play the cards); return(cardsToPlay); }
public bool ShouldCoordinateBeHappy(Coordinate forCoordinate) { if (!PlayedCards.ContainsKey(forCoordinate)) { Debug.LogError($"Asked if coordinate {forCoordinate.ToString()} should be happy, but that coordinate isn't in this play field."); return(false); } int neighbors = OccuppiedNeighborsAtCoordinate(forCoordinate); if (PlayedCards[forCoordinate].FaceValue == neighbors) { return(true); } return(false); }
/// <summary> /// Returns a map of predicted card ids based on given cards. /// </summary> /// <param name="playedCards">the cards the prediction is performed with</param> /// <returns>the map of card ids and there probability</returns> private List <Dictionary <string, double> > getOccurenceMaps(PlayedCards playedCards) { var occurMaps = new List <Dictionary <string, double> >(); foreach (Card card in playedCards.Cards) { var occurMap = new Dictionary <string, double>(); var occurList = _map.GetOccurrencesList(card.Id).ToList(); occurList.ForEach(o => { string cardId = o.cardId; double numOcc = o.numOcc; occurMap.Add(cardId, numOcc); }); occurMaps.Add(occurMap); } return(occurMaps); }
public void ExecuteTurn(ICardPool pool) { Hand.DiscardTo(DiscardPile); PlayedCards.DiscardTo(DiscardPile); FillHand(); while (Hand.Any()) { var card = Hand[0]; Hand.RemoveAt(0); card.Play(this, null, pool); PlayedCards.Add(card); } var availableFunds = PlayedCards.Select(c => c.EType).Concat(new [] { Element.Free }).GroupBy(e => e).ToDictionary(g => g.Key, g => g.Count()); DiscardPile.AddRange(pool.BuyAll(availableFunds)); Console.WriteLine("Own {0} Cards:{1}", Collection.Count(), string.Join(", ", Collection.OrderBy(c => c.CardId).Select(c => c.ToString()))); }
/// <summary> /// TODO: API /// </summary> /// <param name="simulationGame">the game the prediction is performed on</param> /// <param name="opponent">the controller of the opponent</param> /// <returns></returns> private List <Prediction> GetPredictionMap(POGame simulationGame, Controller opponent) { PlayedCards playedCards = UpdateTasks(opponent); var predictionMap = new List <Prediction>(); if (!(playedCards.CardEntries?.Any() ?? false)) { return(predictionMap); } Dictionary <CardClass, double> predictedDeckClasses = predictDeckClasses(opponent, _oppBoardCards); if (_lastPredictionCards == null) { _lastPredictionCards = PredictCards(_predictionParameters.CardCount, playedCards, _oppBoardCards, predictedDeckClasses); } var combinedPredictedCards = new PredictedCards(_lastPredictionCards .SelectMany(p => p.CardEntries) .ToList()); List <Deck> predictedDecks = predictDecks(combinedPredictedCards, _oppBoardCards); var predictedDecksCopy = new List <Deck>(); foreach (Deck deck in predictedDecks) { Deck predictedDeckCopy = CopyDeck(deck); // remove already drawn cards from deck _oppBoardCards.Cards.ForEach(c => { if (predictedDeckCopy.Cards.Contains(c)) { predictedDeckCopy.Remove(c); } }); predictedDecksCopy.Add(predictedDeckCopy); } int handZoneCount = opponent.HandZone.Count; CreatePrediction(handZoneCount, combinedPredictedCards, predictedDecksCopy, ref predictionMap); return(predictionMap); }
/// <summary> /// Gets the lowest hand we have of the specified type /// </summary> /// <param name="type">The type of hand to match</param> /// <returns></returns> private PlayedCards GetMatchingCards(PlayedCards currentMove, PokerHands type) { IList <IGrouping <int, Card> > matchingCards = Hand.GetMatchingCards(type).ToList(); PlayedCards cardsToPlay = null; // Do we have any pairs? if (matchingCards.Any()) { if (currentMove == null) { // Play the lowest pair on a new sequence IList <Card> lowestPair = matchingCards.First().ToList(); cardsToPlay = new PlayedCards(this, lowestPair); } else { int currentPairValue = currentMove[0].GameValue; IGrouping <int, Card> lowestPair = matchingCards.FirstOrDefault(c => c.First().GameValue > currentPairValue); if (lowestPair != null) { cardsToPlay = new PlayedCards(this, lowestPair); } else { // we do not have a better pair than the current move } } } if (cardsToPlay != null) { cardsToPlay.Type = type; } return(cardsToPlay); }