Ejemplo n.º 1
0
        public override int GetEfficientDrawCountWithSeenTiles(IList <Tile> tilesInHand, IList <Tile> seenTiles)
        {
            var remainingTiles = AllAvailableTiles.Except(seenTiles);

            var efficientDrawCount     = 0;
            var currentWaitingDistince = WaitingDistanceFinder.GetWaitingDistance(tilesInHand);

            IDictionary <Tile, int> countOfTilesUsedInHand = tilesInHand.GroupBy(x => x)
                                                             .ToDictionary(g => g.Key, g => g.Count());
            IDictionary <Tile, int> countOfRemainingTiles = remainingTiles.GroupBy(x => x)
                                                            .ToDictionary(g => g.Key, g => g.Count());

            foreach (var tile in AllDistinctTiles)
            {
                if (!countOfRemainingTiles.ContainsKey(tile))
                {
                    continue;
                }
                var tilesWithNewTileAdded = new List <Tile>(tilesInHand)
                {
                    tile
                };
                var newWaitingDistance = WaitingDistanceFinder.GetWaitingDistance(tilesWithNewTileAdded);
                if (newWaitingDistance < currentWaitingDistince)
                {
                    efficientDrawCount += countOfRemainingTiles[tile];
                }
            }
            return(efficientDrawCount);
        }
Ejemplo n.º 2
0
        public TileGrouping ChooseGroupToMakeWithDiscardedTile(Tile discardedTile, bool canBeSequence)
        {
            UpdateSeenTiles();
            var potentialHandTiles = new List <Tile>(Hand.UncalledTiles)
            {
                discardedTile
            };
            var groupsInvolvingDiscardedTile = GetAllGroupsThatCanBeMadeWithDiscardedTile(discardedTile, canBeSequence);

            var minimumWaitingDistance = WaitingDistanceFinder.GetWaitingDistance(Hand.UncalledTiles);
            var maximumTileEfficiency  = EfficientDrawsFinder.GetEfficientDrawCountWithSeenTiles(Hand.UncalledTiles,
                                                                                                 SeenTiles);
            TileGrouping idealGroup = null;

            foreach (var group in groupsInvolvingDiscardedTile)
            {
                var remainingTiles = new List <Tile>(potentialHandTiles);
                foreach (var tile in group)
                {
                    remainingTiles.Remove(tile);
                }

                var newWaitingDistance = WaitingDistanceFinder.GetWaitingDistance(remainingTiles);
                var newTileEfficiency  = EfficientDrawsFinder.GetEfficientDrawCountWithSeenTiles(remainingTiles,
                                                                                                 SeenTiles);
                if (newWaitingDistance < minimumWaitingDistance ||
                    (newWaitingDistance == minimumWaitingDistance && newTileEfficiency > maximumTileEfficiency))
                {
                    minimumWaitingDistance = newWaitingDistance;
                    maximumTileEfficiency  = newTileEfficiency;
                    idealGroup             = group;
                }
            }
            return(idealGroup);
        }
Ejemplo n.º 3
0
        public override int ChooseIndexOfTileToDiscard()
        {
            UpdateSeenTiles();
            var indexOfTileToDiscard   = Hand.UncalledTiles.Count - 1;
            var currentWaitingDistance = WaitingDistanceFinder.GetWaitingDistance(Hand.UncalledTiles);
            var bestEfficientDrawCount = 0;

            for (int i = 0; i < Hand.UncalledTiles.Count; i++)
            {
                var remainingTiles = new List <Tile>(Hand.UncalledTiles);
                remainingTiles.RemoveAt(i);
                if (WaitingDistanceFinder.GetWaitingDistance(remainingTiles) > currentWaitingDistance)
                {
                    continue;
                }

                var newEfficientDrawCount = EfficientDrawsFinder.GetEfficientDrawCountWithSeenTiles(remainingTiles,
                                                                                                    SeenTiles);

                if (newEfficientDrawCount > bestEfficientDrawCount)
                {
                    bestEfficientDrawCount = newEfficientDrawCount;
                    indexOfTileToDiscard   = i;
                }
            }
            return(indexOfTileToDiscard);
        }
Ejemplo n.º 4
0
        public override bool IsClaimingDiscardedTileToCompleteGroup(Tile discardedTile, bool canBeSequence)
        {
            UpdateSeenTiles();
            var potentialHandTiles = new List <Tile>(Hand.UncalledTiles)
            {
                discardedTile
            };
            var groupsInvolvingDiscardedTile = GetAllGroupsThatCanBeMadeWithDiscardedTile(discardedTile, canBeSequence);

            var currentWaitingDistance = WaitingDistanceFinder.GetWaitingDistance(Hand.UncalledTiles);
            var currentTileEfficiency  = EfficientDrawsFinder.GetEfficientDrawCountWithSeenTiles(Hand.UncalledTiles,
                                                                                                 SeenTiles);

            foreach (var group in groupsInvolvingDiscardedTile)
            {
                var remainingTiles = new List <Tile>(potentialHandTiles);
                foreach (var tile in group)
                {
                    remainingTiles.Remove(tile);
                }
                var newWaitingDistance = WaitingDistanceFinder.GetWaitingDistance(remainingTiles);
                if (newWaitingDistance < currentWaitingDistance ||
                    (newWaitingDistance == currentWaitingDistance &&
                     EfficientDrawsFinder.GetEfficientDrawCountWithSeenTiles(remainingTiles, SeenTiles)
                     > currentTileEfficiency))
                {
                    return(true);
                }
            }
            return(false);
        }
Ejemplo n.º 5
0
        public int GetEfficientDrawCount(IList <Tile> tiles)
        {
            var efficientDrawCount     = 0;
            var currentWaitingDistince = WaitingDistanceFinder.GetWaitingDistance(tiles);

            IDictionary <Tile, int> countOfTilesUsedInHand = tiles.GroupBy(x => x)
                                                             .ToDictionary(g => g.Key, g => g.Count());

            foreach (var tile in AllDistinctTiles)
            {
                if (countOfTilesUsedInHand.ContainsKey(tile) && countOfTilesUsedInHand[tile] == 4)
                {
                    continue;
                }
                var tilesWithNewTileAdded = new List <Tile>(tiles)
                {
                    tile
                };
                var newWaitingDistance = WaitingDistanceFinder.GetWaitingDistance(tilesWithNewTileAdded);
                if (newWaitingDistance < currentWaitingDistince)
                {
                    efficientDrawCount += countOfTilesUsedInHand.ContainsKey(tile) ? 4 - countOfTilesUsedInHand[tile] : 4;
                }
            }
            return(efficientDrawCount);
        }
Ejemplo n.º 6
0
        public override bool IsClaimingDiscardedTileToCompleteWinningHand(Tile discardedTile)
        {
            //return false;
            var uncalledTilesWithClaimedDiscard = new List <Tile>(Hand.UncalledTiles)
            {
                discardedTile
            };

            return(WaitingDistanceFinder.GetWaitingDistance(uncalledTilesWithClaimedDiscard) == -1);
        }