Esempio n. 1
0
        public Finesse(GameState gs, Guid infoTile, Guid targetTile, TileValueList infoValues, TileValueList targetValues, int turn, int givingPlayer)
        {
            InfoTileId           = infoTile;
            TargetTileId         = targetTile;
            PossibleInfoValues   = infoValues;
            PossibleTargetValues = targetValues;
            TurnGiven            = turn;
            GivingPlayer         = givingPlayer;
            TargetedPlayer       = gs.WhoHas(targetTile);

            int turnDifference = ((TargetedPlayer < GivingPlayer) ? TargetedPlayer + gs.NumPlayers : TargetedPlayer) - GivingPlayer;

            TurnTargetShouldAct = TurnGiven + turnDifference;
        }
Esempio n. 2
0
        /// <summary>
        /// A player took an action!
        /// </summary>
        public void RecordPlayerTurn(Turn turn, int turnNumber)
        {
            // Increase the age of info
            foreach (var tile in m_infoLookup.Values)
            {
                tile.AgeInfo();
            }

            switch (turn.Action.ActionType)
            {
            case PlayerAction.PlayerActionType.Info:
            {
                List <Guid> tiles = new List <Guid>();
                // Go through the tiles included in the give and record what we now know about them
                foreach (Guid g in turn.TargetedTiles)
                {
                    var lookup = Lookup(g);

                    if (turn.Action.InfoType == PlayerAction.PlayerActionInfoType.Suit)
                    {
                        lookup.MustBe((Suit)turn.Action.Info, "Given Info");
                        lookup.GotInfo();
                    }
                    else if (turn.Action.InfoType == PlayerAction.PlayerActionInfoType.Number)
                    {
                        lookup.MustBe(turn.Action.Info, "Given Info");
                        lookup.GotInfo();
                    }

                    // If the targeted tile might be playable at all, remember it
                    if (lookup.IsPossiblyPlayable(m_lastGameState))
                    {
                        tiles.Add(g);
                    }
                }


                if (m_allowFinesses)
                {
                    if (turn.Action.TargetPlayer == PlayerIndex)
                    {
                        // Info was given to you, double check if it might be a finesse
                        var finesseTargets = GetPossibleFinesseTargets();

                        // Ignore any finesse targets that are in the hand of the person giving the info, they can't see those
                        finesseTargets = finesseTargets.Where(t => m_lastGameState.WhoHas(t.UniqueId) != turn.Action.ActingPlayer);

                        // If there are possible finesses
                        if (finesseTargets.Any())
                        {
                            // Possible values our info could have if they're finessing each target
                            var infoValueList = finesseTargets.Select(t => new TileValue(t.Suit, t.Number + 1)).ToList();

                            foreach (var infoTarget in turn.TargetedTiles)
                            {
                                foreach (var finesseTarget in finesseTargets)
                                {
                                    var targetValueList = new TileValueList();
                                    targetValueList.Add(new TileValue(finesseTarget.Suit, finesseTarget.Number));

                                    var finesse = new Finesse(m_lastGameState, infoTarget, finesseTarget.UniqueId, infoValueList, targetValueList, turnNumber, turn.Action.ActingPlayer);
                                    m_activeFinesses.Add(finesse);
                                }
                            }
                        }
                    }
                    else
                    {
                        // Info was given to someone else, see if you're being finessed

                        var actualTiles = turn.TargetedTiles.Select(g => m_lastGameState.AllHands().First(t => t.UniqueId == g));

                        // If this info give is all unplayable tiles, it's gotta be a finesse
                        if (!actualTiles.Any(t => m_lastGameState.IsPlayable(t)))
                        {
                            var finesseTargets = GetPossibleFinesseTargets();
                            var missingTargets = new List <Tile>();

                            foreach (var target in turn.TargetedTiles)
                            {
                                // Find this info tile
                                var infoTile = m_lastGameState.AllHands().Where(t => t.UniqueId == target).First();
                                // See if the finesse targets list contains a corresponding tile
                                var finesseTarget = finesseTargets.Where(t => t.Suit == infoTile.Suit && t.Number == infoTile.Number - 1).FirstOrDefault();

                                var infoValues = new TileValueList();
                                infoValues.Add(new TileValue(infoTile.Suit, infoTile.Number));

                                if (finesseTarget != null)
                                {
                                    var targetValues = new TileValueList();
                                    targetValues.Add(new TileValue(finesseTarget.Suit, finesseTarget.Number));
                                    var finesse = new Finesse(m_lastGameState, infoTile.UniqueId, finesseTarget.UniqueId, infoValues, targetValues, turnNumber, turn.Action.ActingPlayer);
                                    m_activeFinesses.Add(finesse);
                                }
                                else
                                {
                                    // We must have the target!
                                    var myNewest     = m_lastGameState.YourHand.Last();
                                    var targetValues = new TileValueList();
                                    targetValues.Add(new TileValue(infoTile.Suit, infoTile.Number - 1));
                                    var finesse = new Finesse(m_lastGameState, infoTile.UniqueId, myNewest, infoValues, targetValues, turnNumber, turn.Action.ActingPlayer);
                                    m_activeFinesses.Add(finesse);
                                }
                            }
                        }
                    }
                }

                if (tiles.Any())
                {
                    // Modify our strength value for all targeted tiles that could possibly be playable
                    ModifyPlayStrength(turn.Action.TargetPlayer, tiles);
                }

                // Now go through all other tiles in that hand and mark the negative info we got
                foreach (Guid g in TilesInHand(turn.Action.TargetPlayer).Except(turn.TargetedTiles))
                {
                    var lookup = Lookup(g);

                    if (turn.Action.InfoType == PlayerAction.PlayerActionInfoType.Suit)
                    {
                        lookup.CannotBe((Suit)turn.Action.Info, "Negative info");
                    }
                    else if (turn.Action.InfoType == PlayerAction.PlayerActionInfoType.Number)
                    {
                        lookup.CannotBe(turn.Action.Info, "Negative info");
                    }
                }
            }
            break;
            }
        }