private SheepCard GetLeadMove(ITrick trick) { if (trick.IHand.Picker == this || IamPartner(trick)) { return(Cards .Where(c => trick.IsLegalAddition(c, this)) .OrderBy(c => CardUtil.GetSuit(c) == Suit.TRUMP ? 1 : 2) .FirstOrDefault()); } else { if (trick.IHand.IGame.PartnerMethodEnum == PartnerMethod.CalledAce && trick.IHand.PartnerCardEnum.HasValue) { var partnerCardSuit = CardUtil.GetSuit(trick.IHand.PartnerCardEnum.Value); return(Cards .OrderBy(c => CardUtil.GetSuit(c) == partnerCardSuit ? 1 : 2) .FirstOrDefault()); } else { return(Cards .OrderBy(c => CardUtil.GetSuit(c) != Suit.TRUMP ? 1 : 2) .FirstOrDefault()); } } }
public SheepCard GiveAwayPoints(IPlayer thisPlayer, ITrick trick) { return(thisPlayer.Cards .Where(c => trick.IsLegalAddition(c, thisPlayer)) .OrderByDescending(c => CardUtil.GetPoints(c)) .First()); }
private SheepCard GetLaterMove(ITrick trick) { if (_gameStateAnalyzer.AllOpponentsHavePlayed(this, trick) == true) { if (_gameStateAnalyzer.MySideWinning(this, trick)) { return(_playCreator.GiveAwayPoints(this, trick)); } else { if (_gameStateAnalyzer.ICanWinTrick(this, trick)) { return(_playCreator.PlayWeakestWin(this, trick)); } else { return(_playCreator.GiveAwayLeastPower(this, trick)); } } } else { if (_gameStateAnalyzer.MySideWinning(this, trick)) { if (_gameStateAnalyzer.UnplayedCardsBeatPlayedCards(this, trick)) { if (_gameStateAnalyzer.UnplayedCardsBeatMyCards(this, trick)) { return(_playCreator.GiveAwayLeastPower(this, trick)); } else { return(_playCreator.PlayStrongestWin(this, trick)); } } else { return(_playCreator.GiveAwayPoints(this, trick)); } } else { if (_gameStateAnalyzer.ICanWinTrick(this, trick)) { if (_gameStateAnalyzer.UnplayedCardsBeatMyCards(this, trick)) { return(_playCreator.GiveAwayLeastPower(this, trick)); } else { return(_playCreator.PlayStrongestWin(this, trick)); } } else { return(_playCreator.GiveAwayLeastPower(this, trick)); } } } }
public SheepCard PlayWeakestWin(IPlayer thisPlayer, ITrick trick) { var legalCards = thisPlayer.Cards.Where(c => trick.IsLegalAddition(c, thisPlayer)); var winnableCards = GameStateUtils.GetCardsThatCouldWin(trick, legalCards); return(winnableCards.OrderByDescending(c => CardUtil.GetRank(c)).First()); }
public SheepCard PlayStrongestLoosingCard(IPlayer thisPlayer, ITrick trick) { var legalCards = thisPlayer.Cards.Where(c => trick.IsLegalAddition(c, thisPlayer)); var winnableCards = GameStateUtils.GetCardsThatCouldWin(trick, legalCards); return(legalCards.Except(winnableCards).OrderBy(c => CardUtil.GetRank(c)).First()); }
public void AddTrick(ITrick trick) { if (trick is Trick) { Tricks.Add((Trick)trick); } }
public void SetTrick(ITrick trick) { _trick = trick; _playedIndex = 0; _offset = -400; if (!IsTrickSet) { Table.PlayedCards = new AndroidCard[trick.Count()]; IsTrickSet = true; } var score = trick.TrickValue(); var winner = trick.TheWinnerPlayer(); _roundStats[0].Text = "Trick Score: " + score.ToString(); _roundStats[1].Text = "Round Winner: " + winner.Name; foreach (var cardPlayerPair in _trick) { var card = cardPlayerPair.Item2; if (card == null) { continue; } var cardtexture = Table.GameContent.TextureDict[card]; var trickCard = new AndroidCard(cardtexture, card) { Position = new Vector2((Table.ScreenWidth / 2 + _offset), Table.ScreenHeight / 4.0f) }; _offset += 150; trickCard.State = StateType.Playing; trickCard.IsTrick = true; Table.PlayedCards[_playedIndex++] = trickCard; } }
public IPlayer GetStartingPlayer(IHand hand, ITrick currentTrick) { var index = hand.ITricks.IndexOf(currentTrick); return((index == 0) ? hand.StartingPlayer : hand.ITricks[index - 1].Winner().Player); }
public bool HaveHighPointsBeenPlayed(ITrick trick) { var totalPoints = trick.CardsByPlayer.Sum(cp => CardUtil.GetPoints(cp.Value)); return(trick.IHand.IGame.PlayerCount == 3 ? totalPoints >= 10 : totalPoints >= 12); }
public bool CanILoose(IPlayer thisPlayer, ITrick trick) { var legalCards = thisPlayer.Cards.Where(c => trick.IsLegalAddition(c, thisPlayer)).ToList(); var winnableCards = GameStateUtils.GetCardsThatCouldWin(trick, legalCards).ToList(); var looseableCards = legalCards.Except(winnableCards); return(looseableCards.Any()); }
public bool EarlyInTrick(ITrick trick) { if (trick.IHand.IGame.PlayerCount == 3) { return(trick.CardsByPlayer.Count < 2); } else { return(trick.CardsByPlayer.Count < 3); } }
public static KeyValuePair <IPlayer, SheepCard> GetWinningPlay(ITrick trick) { var startSuit = CardUtil.GetSuit(trick.CardsByPlayer.First().Value); var winningPlay = trick.CardsByPlayer .OrderBy(cp => CardUtil.GetSuit(cp.Value) == Suit.TRUMP ? 1 : 2) .ThenBy(cp => CardUtil.GetSuit(cp.Value) == startSuit ? 1 : 2) .ThenBy(cp => CardUtil.GetRank(cp.Value)) .First(); return(winningPlay); }
public bool UnplayedCardsBeatMyCards(IPlayer thisPlayer, ITrick trick) { var playableCards = thisPlayer.Cards.Where(c => trick.IsLegalAddition(c, thisPlayer)); var unrevealedCards = GetUnrevealedCards(thisPlayer, trick); var startSuit = CardUtil.GetSuit(trick.CardsByPlayer.First().Value); var strongestUnrevealedCard = GetStrongestCard(unrevealedCards, startSuit); var strongestOfMyCards = GetStrongestCard(playableCards, startSuit); var strongestCard = GetStrongestCard(new List <SheepCard>() { strongestUnrevealedCard, strongestOfMyCards }, startSuit); return(strongestCard == strongestUnrevealedCard); }
public SheepCard PlaySecondStrongestLoosingCard(IPlayer thisPlayer, ITrick trick) { var legalCards = thisPlayer.Cards.Where(c => trick.IsLegalAddition(c, thisPlayer)); var winnableCards = GameStateUtils.GetCardsThatCouldWin(trick, legalCards); var cards = legalCards.Except(winnableCards).OrderBy(c => CardUtil.GetRank(c)).ToList(); if (cards.Count == 1) { return(cards.Single()); } else { return(cards[1]); } }
public bool MySideWinning(IPlayer thisPlayer, ITrick trick) { var winningPlay = GameStateUtils.GetWinningPlay(trick); if (trick.IHand.Picker == thisPlayer) { return(winningPlay.Key == trick.IHand.PresumedParnter); } if (PlayerKnowsSelfToBePartner(thisPlayer, trick)) { return(winningPlay.Key == trick.IHand.Picker); } return(winningPlay.Key != trick.IHand.Picker && winningPlay.Key != trick.IHand.PresumedParnter && !(trick.IHand.PartnerCardEnum.HasValue && trick.IHand.PresumedParnter == null)); }
public int QueueRankInTrick(ITrick trick) { if (trick.StartingPlayer == null) { throw new NullReferenceException(); } var indexOfMe = trick.Players.IndexOf(this); var indexOfStartingPlayer = trick.Players.IndexOf(trick.StartingPlayer); var rank = indexOfMe - indexOfStartingPlayer; if (rank < 0) { rank += trick.IHand.IGame.PlayerCount; } return(rank + 1); }
private SheepCard PlayLeasterMove(ITrick trick) { if (_leasterStateAnalyzer.CanIWin(this, trick)) { if (_leasterStateAnalyzer.CanILoose(this, trick)) { if (_leasterStateAnalyzer.EarlyInTrick(trick)) { return(_playCreator.PlaySecondStrongestLoosingCard(this, trick)); } else { if (_leasterStateAnalyzer.HaveIAlreadyWon(this, trick)) { return(_playCreator.PlayStrongestLoosingCard(this, trick)); } else { if (_leasterStateAnalyzer.HaveHighPointsBeenPlayed(trick)) { return(_playCreator.PlaySecondStrongestLoosingCard(this, trick)); } else { return(_playCreator.PlayStrongestWin(this, trick)); } } } } else { return(_playCreator.PlayStrongestWin(this, trick)); } } else { if (_leasterStateAnalyzer.HaveIAlreadyWon(this, trick)) { return(_playCreator.PlayStrongestLoosingCard(this, trick)); } else { return(_playCreator.PlaySecondStrongestLoosingCard(this, trick)); } } }
public bool?AllOpponentsHavePlayed(IPlayer thisPlayer, ITrick trick) { if (trick.CardsByPlayer.Count == trick.IHand.IGame.PlayerCount - 1) { return(true); } var playerIsPartner = PlayerKnowsSelfToBePartner(thisPlayer, trick); var playerIsOffense = trick.IHand.Picker == thisPlayer || playerIsPartner; if (playerIsOffense) { var opponentCount = trick.IHand.PartnerCardEnum.HasValue ? trick.IHand.IGame.PlayerCount - 2 : trick.IHand.IGame.PlayerCount - 1; var opponentsWithTurns = playerIsPartner ? trick.CardsByPlayer.Keys.Count(p => trick.IHand.Picker != p && thisPlayer != p) : trick.CardsByPlayer.Keys.Count(p => trick.IHand.Picker != p && trick.IHand.PresumedParnter != p); if (opponentsWithTurns < opponentCount) { return(false); } if (!playerIsPartner && trick.IHand.PartnerCardEnum.HasValue && trick.IHand.PresumedParnter == null) { return(null); } return(true); } else { if (!trick.CardsByPlayer.ContainsKey(trick.IHand.Picker)) { return(false); } if (trick.IHand.PresumedParnter != null && !trick.CardsByPlayer.ContainsKey(trick.IHand.PresumedParnter)) { return(false); } if (trick.IHand.PartnerCardEnum.HasValue && trick.IHand.PresumedParnter == null) { return(null); } return(true); } }
public override SheepCard GetMove(ITrick trick) { if (Cards.Count == 1) { return(Cards.Single()); } if (trick.IHand.Leasters) { return(PlayLeasterMove(trick)); } if (trick.StartingPlayer == this) { return(GetLeadMove(trick)); } else { return(GetLaterMove(trick)); } }
public void SetTrick(ITrick trick) { _trick = trick; _playedIndex = 0; _offset = -400; if (!IsTrickSet) { Table.PlayedCards = new AndroidCard[trick.Count()]; IsTrickSet = true; } if (!LeaderboardSet) { SetScoreboard(); LeaderboardSet = true; } foreach (var cardPlayerPair in _trick) { var card = cardPlayerPair.Item2; if (card == null) { continue; } var cardtexture = Table.GameContent.TextureDict[card]; var trickCard = new AndroidCard(cardtexture, card) { Position = new Vector2((Table.ScreenWidth / 2 + _offset), Table.ScreenHeight / 4.0f) }; _offset += 150; trickCard.State = StateType.Playing; trickCard.IsTrick = true; var player = cardPlayerPair.Item1; _leaderboardpanel[_playedIndex].PlayerName = player.Name; _leaderboardpanel[_playedIndex].Text = "Card Played: "; _leaderboardpanel[_playedIndex].Card = trickCard; Table.PlayedCards[_playedIndex++] = trickCard; } }
public void Trick_AddToHand() { var firstPlayer = new Mock <IPlayer>().Object; var startingPlayerCalcMock = new Mock <IStartingPlayerCalculator>(); startingPlayerCalcMock.Setup(m => m.GetStartingPlayer(It.IsAny <IHand>(), It.IsAny <ITrick>())).Returns(firstPlayer); var mockHand = new Mock <IHand>(); var trickList = new List <ITrick>(); mockHand.Setup(m => m.ITricks).Returns(trickList); ITrick passedTrick = null; var trickMock = new Mock <ITrick>(); mockHand.Setup(m => m.AddTrick(It.IsAny <ITrick>())).Callback((ITrick givenTrick) => { trickList.Add(givenTrick); passedTrick = givenTrick; }); var trick = new Trick(mockHand.Object, startingPlayerCalcMock.Object); Assert.AreSame(trick, passedTrick, "When a trick is instantiated, it should be added to a given hand."); }
public static IEnumerable <SheepCard> GetCardsThatCouldWin(ITrick trick, IEnumerable <SheepCard> comparisonCards) { if (!trick.CardsByPlayer.Any()) { return(comparisonCards); } var startSuit = CardUtil.GetSuit(trick.CardsByPlayer.First().Value); var winningCard = GameStateUtils.GetWinningPlay(trick).Value; var winningCardRank = CardUtil.GetRank(winningCard); if (CardUtil.GetSuit(winningCard) == Suit.TRUMP) { return(comparisonCards.Where(c => CardUtil.GetRank(c) < winningCardRank)); } else { return(comparisonCards.Where(c => CardUtil.GetSuit(c) == Suit.TRUMP || CardUtil.GetSuit(c) == startSuit && CardUtil.GetRank(c) < winningCardRank )); } }
public TrickBLL(ITrick iTrick) { _iTrick = iTrick; }
public void TrickStart(ITrick trick) { }
private static IEnumerable <SheepCard> GetUnrevealedCards(IPlayer thisPlayer, ITrick trick) { var revealedAndPlayersOwnCards = trick.IHand.ITricks.SelectMany(t => t.CardsByPlayer.Values).Union(thisPlayer.Cards); var allCards = Enum.GetValues(typeof(SheepCard)).OfType <SheepCard>(); var unrevealedCards = allCards.Except(revealedAndPlayersOwnCards); return(unrevealedCards); }
public void CardPlayed(Cards.Card card, int playerID, ITrick trick) { }
public Card GetCard(ITrick trick) { return (Card)HC.Hand.Where(c => HC.IsLegalCard(c)).First(); }
public abstract SheepCard GetMove(ITrick trick);
public void TrickEnd(ITrick trick) { }
private string Prompt(PromptType promptType, Dictionary<PromptData, object> data) { string prompt = ""; ITrick trick = null; IPlayer player = null; IPlayer picker = null; switch (promptType) { case PromptType.CardsDealt: PlayerGraphicsDict = new Dictionary<IPlayer, AndroidPlayer>(); var blinddata = (IBlind)data[PromptData.Blind]; foreach (var addPlayer in _table.Players) { AndroidPlayer hostGraphics = new AndroidPlayer(addPlayer); PlayerGraphicsDict.Add(addPlayer, hostGraphics); } var blindLoc = 250; var blindIndex = 0; foreach (var addBlind in blinddata) { var cardtexture = GameContent.TextureDict[addBlind]; var cardGraphics = new AndroidCard(cardtexture, addBlind) { IsBlind = true, Position = new Vector2(blindLoc, ScreenHeight / 4.0f) }; BlindList[blindIndex] = cardGraphics; blindIndex++; blindLoc += 500; } foreach (var playerPair in PlayerGraphicsDict) { var playerGraphicsHand = playerPair; var playerHand = playerPair.Key.Hand; var screen = ScreenWidth / 2 - 500; foreach (var card in playerHand) { var cardtexture = GameContent.TextureDict[card]; var cardGraphics = new AndroidCard(cardtexture, card) { Position = new Vector2(screen, ScreenHeight - 200) }; playerGraphicsHand.Value.AddCardToHand(cardGraphics); screen += 150; } } ChangeState(new AndroidPreGameState(this, _graphics.GraphicsDevice, GameContent)); State = StateType.PreGame; break; case PromptType.Pick: ChangeState(_blindState); State = StateType.Blind; prompt = _blindState.PickingPrompt(); _blindState.Prompt = ""; break; case PromptType.BotPlayCard: break; case PromptType.PlayCard: State = StateType.Playing; picker = (IPlayer)data[PromptData.Picker]; player = (IPlayer)data[PromptData.Player]; trick = (ITrick)data[PromptData.Trick]; ChangeState(_playingState); _playingState.SetTrick(trick); _playingState.SetPicker(picker); var cards = (List<ICard>)data[PromptData.Cards]; PlayableCards = new List<AndroidCard>(); PlayerGraphicsDict.TryGetValue(player, out var playergraphics); foreach (var card in cards) { if (playergraphics == null) continue; foreach (var cardgraphics in playergraphics.PlayableCards) { if (!card.Equals(cardgraphics.Card)) continue; PlayableCards.Add(cardgraphics); cardgraphics.IsPlayable = true; break; } } prompt = _playingState.PickingPrompt(); if (prompt != "") { _playingState.IsTrickSet = false; _playingState.LeaderboardSet = false; } break; case PromptType.PickBlind: State = StateType.Picking; player = (IPlayer)data[PromptData.Player]; var blind = (IBlind)data[PromptData.Blind]; _pickingState.AssignBlind(blind); _pickingState.AssignPlayer(player); ChangeState(_pickingState); prompt = _pickingState.PickingPrompt(); _pickingState.Prompt = ""; break; case PromptType.RoundOver: trick = ((IRound)data[PromptData.Round]).Trick; ChangeState(_roundOverState); State = StateType.RoundOver; _roundOverState.SetTrick(trick); prompt = _roundOverState.PickingPrompt(); if (prompt != "") { _roundOverState = new AndroidRoundOverState(this, _graphics.GraphicsDevice, GameContent); } break; case PromptType.GameOver: ChangeState(_gameOverState); State = StateType.GameOver; var game = (IGame)data[PromptData.Game]; _gameOverState.SetGame(game); _gameOverState.SetSharedSheepTable(_table); _gameOverState.SetScoreSheet(_table.ScrSheet); prompt = _gameOverState.PickingPrompt(); break; case PromptType.TableOver: ChangeState(_tableOverstate); State = StateType.TableOver; _tableOverstate.SetSharedSheepTable(_table); _tableOverstate.SetScoreSheet(_table.ScrSheet); prompt = _tableOverstate.PickingPrompt(); if (prompt == "done") this.Exit(); else if (prompt == "playAgain") { _titleState = new AndroidTitleScreen(this, _graphics.GraphicsDevice, GameContent); ChangeState(_titleState); } break; case PromptType.CallUp: prompt = "Would you like to call up? (yes/no): "; break; case PromptType.CalledUp: prompt = string.Format("\nPicker called up to {0}\n", _table.Games.Last().PartnerCard); break; default: return ""; } return prompt; }
private static bool PlayerKnowsSelfToBePartner(IPlayer thisPlayer, ITrick trick) { return(trick.IHand.Partner == thisPlayer || trick.IHand.PartnerCardEnum.HasValue && thisPlayer.Cards.Contains(trick.IHand.PartnerCardEnum.Value)); }
public bool HaveTwoPowerCards(IPlayer thisPlayer, ITrick trick) { return(CountQueensJacks(thisPlayer) >= 2); }
public bool UnplayedCardsBeatPlayedCards(IPlayer thisPlayer, ITrick trick) { var unrevealedCards = GetUnrevealedCards(thisPlayer, trick); return(GameStateUtils.GetCardsThatCouldWin(trick, unrevealedCards).Any()); }
public bool ICanWinTrick(IPlayer thisPlayer, ITrick trick) { var playableCards = thisPlayer.Cards.Where(c => trick.IsLegalAddition(c, thisPlayer)); return(GameStateUtils.GetCardsThatCouldWin(trick, playableCards).Any()); }