Esempio n. 1
0
        /// <summary>
        /// this function checks whether there is a winning four a line
        /// </summary>
        /// <param name="i_LineOfEnums">generated for 4 directions to check 4 in a line streak</param>
        /// <param name="i_CurrCellEnum">type of cell according to player</param>
        /// <returns></returns>
        private static bool isFourInLine(BoardEnumAndIndex[] i_LineOfEnums, Board.eBoardCellTypes i_CurrCellEnum)
        {
            bool fourInLineFound     = false;
            int  streakOfSameElement = 0;
            bool streakInProgress    = false;
            int  streakBeginning     = 0;

            for (int i = 0; i < (sr_LineRadiusToCheck * 2) + 1; i++)
            {
                if (!streakInProgress)
                {
                    streakBeginning = i;
                }

                if (i_CurrCellEnum.Equals(i_LineOfEnums[i].CellType))
                {
                    if (!streakInProgress)
                    {
                        streakInProgress = true;
                    }

                    streakOfSameElement++;
                    if (streakOfSameElement == sr_WinningStreakSize)
                    {
                        fourInLineFound = true;
                        for (int j = 0; j < 4; j++)
                        {
                            m_FourInARowIndexes[j] = i_LineOfEnums[j + streakBeginning];
                        }

                        break;
                    }
                }
                else
                {
                    streakInProgress    = false;
                    streakOfSameElement = 0;
                }
            }

            return(fourInLineFound);
        }
Esempio n. 2
0
        /// <summary>
        /// this function checks whether there is a winning four a line
        /// </summary>
        /// <param name="i_LineOfEnums">generated for 4 directions to check 4 in a line streak</param>
        /// <param name="i_CurrCellEnum">type of cell according to player</param>
        /// <returns></returns>
        private static bool isFourInLine(Board.eBoardCellTypes[] i_LineOfEnums, Board.eBoardCellTypes i_CurrCellEnum)
        {
            bool fourInLineFound     = false;
            int  streakOfSameElement = 0;

            for (int i = 0; i < (sr_LineRadiusToCheck * 2) + 1; i++)
            {
                if (i_CurrCellEnum.Equals(i_LineOfEnums[i]))
                {
                    streakOfSameElement++;
                    if (streakOfSameElement == sr_WinningStreakSize)
                    {
                        fourInLineFound = true;
                        break;
                    }
                }
                else
                {
                    streakOfSameElement = 0;
                }
            }

            return(fourInLineFound);
        }