예제 #1
0
        //<summary> return the number of hidden tiles shared by these tiles
        public int NumberOfSharedHiddenTiles(SolverTile tile)
        {
            // if the locations are too far apart they can't share any of the same squares
            if (Math.Abs(tile.x - this.x) > 2 || Math.Abs(tile.y - this.y) > 2)
            {
                return(0);
            }

            int count = 0;

            foreach (SolverTile tile1 in this.GetAdjacentTiles())
            {
                if (!tile1.IsHidden())
                {
                    continue;
                }
                foreach (SolverTile tile2 in tile.GetAdjacentTiles())
                {
                    if (!tile2.IsHidden())
                    {
                        continue;
                    }
                    if (tile1.IsEqual(tile2))    // if they share a tile then return true
                    {
                        count++;
                    }
                }
            }

            // no shared tile found
            return(count);
        }
예제 #2
0
        // returns all the indices adjacent to this index
        public List <SolverTile> GetAdjacentTiles(SolverTile tile)
        {
            // have we already calculated the adjacent tiles
            List <SolverTile> adjTiles = tile.GetAdjacentTiles();

            if (adjTiles != null)
            {
                return(adjTiles);
            }

            adjTiles = new List <SolverTile>();

            int first_row = Math.Max(0, tile.y - 1);
            int last_row  = Math.Min(description.height - 1, tile.y + 1);

            int first_col = Math.Max(0, tile.x - 1);
            int last_col  = Math.Min(description.width - 1, tile.x + 1);

            for (int r = first_row; r <= last_row; r++)
            {
                for (int c = first_col; c <= last_col; c++)
                {
                    if (r != tile.y || c != tile.x)
                    {
                        adjTiles.Add(tiles[c, r]);
                    }
                }
            }

            // remember them for next time
            tile.SetAdjacentTiles(adjTiles);

            return(adjTiles);
        }