Example #1
0
        public BoggleHandler(BoggleGrid bg)
        {
            _enWordsDic = new EnWordsSample();

            // init Dictionary
            InitDictionary(bg);
        }
Example #2
0
        // build relationship. create dictionary: key points-> adjacent points (max 8)
        private void LinkAroundPoints(int i, int j, BoggleGrid bg, BogglePoint keyPoint)
        {
            Stack<BogglePoint> valuePoints = new Stack<BogglePoint>();

            for (int newI = i - 1; newI <= i + 1; newI++)
            {
                if (newI < 0 || newI >= bg.RowLength)
                {
                    continue;
                }

                for (int newJ = j - 1; newJ <= j + 1; newJ++)
                {
                    if (newJ < 0 || newJ >= bg.ColLength)
                    {
                        continue;
                    }

                    if (newI == i && newJ == j)
                    {
                        continue;
                    }

                    // add to dic
                    var v = _allPoints.FirstOrDefault(f=>f.Coordinate == newI + "," + newJ);
                    valuePoints.Push(v);
                }
            }
            _pointDictionary.Add(keyPoint, valuePoints);
        }
Example #3
0
        private void InitDictionary(BoggleGrid bg)
        {
            // create 16 points
            for (int i = 0; i < bg.RowLength; i++)
                for (int j = 0; j < bg.ColLength; j++)
                {
                    BogglePoint bp = new BogglePoint() { Letter = bg.Grid[i, j], Coordinate = i + "," + j };
                    _allPoints.Push(bp);
                }

            // link key point with surround points. build relationship
            for (int i = 0; i < bg.RowLength; i++)
                for (int j = 0; j < bg.ColLength; j++)
                {
                    // link 8 points around
                    string coor = i + "," + j;
                    BogglePoint bp = _allPoints.FirstOrDefault(f=>f.Coordinate == coor);
                    LinkAroundPoints(i, j, bg, bp);
                }
        }