Example #1
0
    /// <summary>
    /// Given the location of a tile with a valid sequence number, check each direction for a valid sequence.
    ///
    /// If there's a valid sequence longer or equal to $minimumSequenceLength then return it.
    ///
    /// Otherwise, return an empty list.
    /// </summary>
    /// <returns>The scoring quads.</returns>
    /// <param name="tiles">Array of tiles with valid sequence numbers.</param>
    /// <param name="locationOfSequenceTile">Location of sequence tile.</param>
    private HashSet <TileController> GetScoringQuads(TileController[,] tiles, Vector2Int locationOfSequenceTile)
    {
        // create iterators for up, down, left, right
        TileControllerEnumerator tilesXDown = new TileControllerEnumerator(tiles, locationOfSequenceTile, -1, 0);
        TileControllerEnumerator tilesXUp   = new TileControllerEnumerator(tiles, locationOfSequenceTile, 1, 0);
        TileControllerEnumerator tilesYDown = new TileControllerEnumerator(tiles, locationOfSequenceTile, 0, -1);
        TileControllerEnumerator tilesYUp   = new TileControllerEnumerator(tiles, locationOfSequenceTile, 0, 1);

        TileControllerEnumerator[] tilesEnumerators =
        {
            tilesXDown,
            tilesXUp,
            tilesYDown,
            tilesYUp
        };

        // for each direction, check to see if there's a Fib seq.
        foreach (TileControllerEnumerator tilesEnumerator in tilesEnumerators)
        {
            HashSet <TileController> potentialScoringQuads = GetValidSequenceQuads(tilesEnumerator);

            //if (potentialScoringQuads.Count > 0 && fibNum >= 5)
            //    Debug.Log("potential " + potentialScoringQuads.Count + ", fibNum: " + fibNum + ", loc " + loc);

            if (potentialScoringQuads.Count >= minimumSequenceLength)
            {
                // add to scoring list
                return(potentialScoringQuads);
            }
        }
        return(new HashSet <TileController>());
    }
Example #2
0
    HashSet <TileController> GetValidSequenceQuads(TileControllerEnumerator tiles)
    {
        List <long> potentialSeq = new List <long>();
        HashSet <TileController> potentialScoringQuads = new HashSet <TileController>(new TileController.TileControllerComparer());

        // get adjacent quads, sequentially
        // (direction specified during Tiles creation)
        foreach (TileController tile in tiles)
        {
            if (tile != null)
            {
                long cellValue = tile.CellValue;

                // is this cell value the n-1th in the sequence?
                if (sequenceChecker.IsNumPreviousSequenceTerm(cellValue, potentialSeq))
                {
                    // We've got another fib for our sequence!
                    // great!
                    potentialSeq.Add(cellValue);
                    potentialScoringQuads.Add(tile);
                }
                else
                {
                    // it's not a fib, nevermind
                    // break and return what we have
                    //Debug.Log("End of sequence because " + fib + " is not a fib");
                    break;
                }
            }
            else
            {
                //Debug.Log("End of sequence origin[" + tiles.Origin + "] because quad is null");
                // it's not a fib, nevermind
                // break and return what we have
                break;
            }
        }

        return(potentialScoringQuads);
    }