Ejemplo n.º 1
0
        // NOTE - This function does NOT check for out of bounds when advancing the indexes.
        private void advanceToNextSlotInGivenDirection(ref int io_Row, ref int io_Col,
                                                       eBoardScanningDirections i_Direction)
        {
            switch (i_Direction)
            {
            case eBoardScanningDirections.Up:
                io_Row--;
                break;

            case eBoardScanningDirections.TopRight:
                io_Row--;
                io_Col++;
                break;

            case eBoardScanningDirections.BottomLeft:
                io_Row++;
                io_Col--;
                break;

            case eBoardScanningDirections.BottomRight:
                io_Row++;
                io_Col++;
                break;

            case eBoardScanningDirections.Down:
                io_Row++;
                break;

            case eBoardScanningDirections.Left:
                io_Col--;
                break;

            case eBoardScanningDirections.Right:
                io_Col++;
                break;

            case eBoardScanningDirections.TopLeft:
                io_Row--;
                io_Col--;
                break;
            }
        }
Ejemplo n.º 2
0
        // This function will scan the board, STARTING from the given slot(i_Row, i_Col), and TOWARDS the given direction.
        // It will return how many EQUAL SLOTS (to the starting slot) there are in that direction - NOT including the original slot.
        private int SequenceSizeFromSlotToDirection(int i_Row, int i_Col, eBoardScanningDirections i_ScanningDirection)
        {
            const bool v_insideSequence = true;
            bool       isInsideSequence = v_insideSequence;
            int        sequenceSize = 0;
            int        nextRow = i_Row, nextCol = i_Col;

            advanceToNextSlotInGivenDirection(ref nextRow, ref nextCol, i_ScanningDirection);
            while (IsSlotIndexWithinBounds(nextRow, nextCol) && isInsideSequence)
            {
                if (m_GameBoard[i_Row - 1, i_Col - 1] == m_GameBoard[nextRow - 1, nextCol - 1])
                {
                    sequenceSize++;
                    advanceToNextSlotInGivenDirection(ref nextRow, ref nextCol, i_ScanningDirection);
                }
                else
                {
                    isInsideSequence = !v_insideSequence;
                }
            }

            return(sequenceSize);
        }