public GameRepresentation(CommandFactory commandFactory, PlayerGameInfo playerGameInfo) { CommandFactory = commandFactory; PlayerGameInfo = playerGameInfo; PlayActionList = PlayerGameInfo?.ValidActionIdList ?.Select(id => CommandFactory.ConstructAction(id)) .Where(a => a.GetActionType() == ActionType.PlayAction) .Select(a => (PlayAction)a) .ToList(); BetActionList = PlayerGameInfo?.ValidActionIdList ?.Select(id => CommandFactory.ConstructAction(id)) .Where(a => a.GetActionType() == ActionType.BetAction) .Select(a => (BetAction)a) .ToList(); CardCommandDictionary = PlayActionList ?.ToDictionary(a => a.Card, a => CommandFactory.ConstructCommand(a.GetActionId()) as ICommand); BetActionCommandDictionary = BetActionList ?.ToDictionary(a => a, a => CommandFactory.ConstructCommand(a.GetActionId()) as ICommand); HandRepresentation = PlayerGameInfo?.PlayerHand != null ? new HandRepresentation(PlayerGameInfo?.PlayerHand, CardCommandDictionary) : null; BetActionsRepresentation = BetActionList != null ? new BetActionsRepresentation(BetActionList, BetActionCommandDictionary) : null; BoardRepresentation = GameStageInfo != null ? new BoardRepresentation(PlayerGameInfo.GameInfo, PlayerGameInfo.PlayerInfo, GameStageInfo) : null; // Remark: Since we receive relative player information we could also directly determine the player positions. // But this way the ViewModel would also work with "real" player informations. var topPlayer = PlayerGameInfo.GameInfo.PlayerGroupInfo.GetOppositePlayer(PlayerGameInfo.PlayerInfo.PlayerId); var rightPlayer = PlayerGameInfo.GameInfo.PlayerGroupInfo.GetNextPlayer(PlayerGameInfo.PlayerInfo.PlayerId); var leftPlayer = PlayerGameInfo.GameInfo.PlayerGroupInfo.GetPreviousPlayer(PlayerGameInfo.PlayerInfo.PlayerId); var previousBetActionList = PlayerGameInfo?.GameStageInfo?.ExpectedActionType == ActionType.BetAction ? PlayerGameInfo?.GameStageInfo?.CurrentBetActionList : null; var betActionKeyValuePairList = (previousBetActionList != null && previousBetActionList.Any()) ? previousBetActionList ?.Select((a, i) => new KeyValuePair <int, BetAction>(i, a)) ?.ToList() : null; var topBetActionDictionary = betActionKeyValuePairList ?.Where(p => p.Value.PlayerInfo.PlayerId == topPlayer.PlayerId) ?.ToDictionary(p => p.Key, p => p.Value); var rightBetActionDictionary = betActionKeyValuePairList ?.Where(p => p.Value.PlayerInfo.PlayerId == rightPlayer.PlayerId) ?.ToDictionary(p => p.Key, p => p.Value); var leftBetActionDictionary = betActionKeyValuePairList ?.Where(p => p.Value.PlayerInfo.PlayerId == leftPlayer.PlayerId) ?.ToDictionary(p => p.Key, p => p.Value); // TODO var currentPlayerId = GameStageInfo?.CurrentPlayer?.PlayerId; TopPlayerRepresentation = new PlayerRepresentation(topPlayer, topBetActionDictionary, null, 0, currentPlayerId == topPlayer.PlayerId); LeftPlayerRepresentation = new PlayerRepresentation(rightPlayer, leftBetActionDictionary, null, 0, currentPlayerId == leftPlayer.PlayerId); RightPlayerRepresentation = new PlayerRepresentation(leftPlayer, rightBetActionDictionary, null, 0, currentPlayerId == rightPlayer.PlayerId); }
public object Clone() { return(new StickRoundInfo { PlayActionList = PlayActionList ?.Select(p => (PlayAction)p?.Clone())?.ToList(), StickResult = (StickResult)StickResult?.Clone() }); }
public void ProcessPlayAction(PlayAction playAction) { PlayerHandDictionary[CurrentPlayer.PlayerId].Cards.Remove(playAction.Card); PlayActionList.Add(playAction); StickResult = GetStickResult(); if (StickResult == null) { CurrentPlayer = PlayerGroupInfo.GetNextPlayer(CurrentPlayer.PlayerId); } }
private IList <PlayAction> GetValidPlayActions() { if (StickResult != null) { return(new List <PlayAction>()); } var allHandPlayActionList = PlayerHandDictionary[CurrentPlayer.PlayerId].Cards .Select(c => new PlayAction { PlayerInfo = CurrentPlayer, Card = c }) .ToList(); if (!StickSuit.HasValue) { //Case nothing played yet return(allHandPlayActionList); } var cardComparer = GetCardComparer(); var highestPlayedCard = PlayActionList .OrderByDescending(a => a.Card, cardComparer) .Select(a => a.Card) .First(); var canUnderTrump = PlayType.IsTrump() && allHandPlayActionList .All(a => a.Card.CardSuit == PlayType.GetTrumpSuit()) && allHandPlayActionList .All(a => a.Card.CardRank == CardRank.Jack || cardComparer.Compare(a.Card, highestPlayedCard) < 0); var hasSameSuitCardBesidesTrumpJack = allHandPlayActionList .Any(a => a.Card.CardSuit == StickSuit.Value && !(PlayType.IsTrump() && a.Card.CardSuit == PlayType.GetTrumpSuit() && a.Card.CardRank == CardRank.Jack)); var validPlayActions = allHandPlayActionList .Where(a => { var isTrump = PlayType.IsTrump() && a.Card.CardSuit == PlayType.GetTrumpSuit(); var isHigherThenPlayedCard = cardComparer.Compare(a.Card, highestPlayedCard) > 0; //disjoint condition list var isSameSuit = a.Card.CardSuit == StickSuit.Value; var isHigherNonSuitTrumpCard = !isSameSuit && isTrump && isHigherThenPlayedCard; var isLowerNonSuitUnderTrumpCard = !isSameSuit && isTrump && !isHigherThenPlayedCard && canUnderTrump; var isPlayableNonSuitNonTrumpCard = !isSameSuit && !hasSameSuitCardBesidesTrumpJack; var isValid = isSameSuit || isHigherNonSuitTrumpCard || isLowerNonSuitUnderTrumpCard || isPlayableNonSuitNonTrumpCard; return(isValid); }) .ToList(); return(validPlayActions); }
private StickResult GetStickResult() { if (!StickSuit.HasValue || PlayActionList.Count != 4) { return(null); } var winner = PlayActionList .OrderByDescending(a => a.Card, GetCardComparer()) .First() .PlayerInfo; var cardList = PlayActionList .Select(a => a.Card) .ToList(); var stickResult = new StickResult { Winner = winner, StickPile = cardList }; return(stickResult); }