Пример #1
0
        /// <summary>
        /// aux function for 4 in a row detection
        /// generating a row of board enums according to direction input
        /// </summary>
        /// <param name="i_GameBoard"></param>
        /// <param name="i_Direction"></param>
        /// <param name="i_CurrentInsertCellCol"></param>
        /// <returns></returns>
        private static Board.eBoardCellTypes[] generateLineOfCellEnumsFromBoardByDirection(Board i_GameBoard, Board.eBoardDirections i_Direction, int i_CurrentInsertCellCol)
        {
            int rowSize = i_GameBoard.RowSize;
            int currentInsertCellRow = i_GameBoard.FirstAvailablePoisitionInCol[i_CurrentInsertCellCol] - 1;
            int startOfLineRow, startOfLineCol, rowDirection, colDirection;

            Board.eBoardCellTypes[] result = new Board.eBoardCellTypes[(sr_LineRadiusToCheck * 2) + 1];

            for (int i = 0; i < result.Length; i++)
            {
                result[i] = Board.eBoardCellTypes.Empty;
            }

            switch (i_Direction)
            {
            case Board.eBoardDirections.Horizontal:
                startOfLineCol = i_CurrentInsertCellCol - 3;
                startOfLineRow = currentInsertCellRow;
                rowDirection   = 0;
                colDirection   = 1;
                break;

            case Board.eBoardDirections.Vertical:
                startOfLineCol = i_CurrentInsertCellCol;
                startOfLineRow = currentInsertCellRow - 3;
                rowDirection   = 1;
                colDirection   = 0;
                break;

            case Board.eBoardDirections.RightCross:
                startOfLineCol = i_CurrentInsertCellCol - 3;
                startOfLineRow = currentInsertCellRow - 3;
                rowDirection   = 1;
                colDirection   = 1;
                break;

            case Board.eBoardDirections.LeftCross:
                startOfLineCol = i_CurrentInsertCellCol - 3;
                startOfLineRow = currentInsertCellRow + 3;
                rowDirection   = -1;
                colDirection   = 1;
                break;

            default:
                startOfLineRow = startOfLineCol = rowDirection = colDirection = 0;
                break;
            }

            for (int i = 0; i < (sr_LineRadiusToCheck * 2) + 1; i++)
            {
                int currentCellToCheckRow = startOfLineRow + (i * rowDirection);
                int currentCellToCheckCol = startOfLineCol + (i * colDirection);
                if (i_GameBoard.CheckIsInsideBoardBoundaries(currentCellToCheckRow, currentCellToCheckCol))
                {
                    result[i] = i_GameBoard.GetCellEnum(rowSize - 1 - currentCellToCheckRow, currentCellToCheckCol);
                }
            }

            return(result);
        }
Пример #2
0
        /// <summary>
        /// this function checks whether the move performed is a winning move
        /// it checks 4 in a row for 4 directions horizontal/vertical/right-cross/left-cross
        /// </summary>
        /// <param name="i_CurrentInsertCellCol">col of move</param>
        /// <param name="i_GameBoard"></param>
        /// <returns></returns>
        private static bool isWinningMove(int i_CurrentInsertCellCol, Board i_GameBoard)
        {
            int currentInsertCellRow = i_GameBoard.FirstAvailablePoisitionInCol[i_CurrentInsertCellCol] - 1;

            Board.eBoardCellTypes currentInsertCellEnum = i_GameBoard.GetCellEnum(i_GameBoard.RowSize - 1 - currentInsertCellRow, i_CurrentInsertCellCol);
            bool result = isFourInLine(generateLineOfCellEnumsFromBoardByDirection(i_GameBoard, Board.eBoardDirections.Horizontal, i_CurrentInsertCellCol), currentInsertCellEnum) ||
                          isFourInLine(generateLineOfCellEnumsFromBoardByDirection(i_GameBoard, Board.eBoardDirections.Vertical, i_CurrentInsertCellCol), currentInsertCellEnum) ||
                          isFourInLine(generateLineOfCellEnumsFromBoardByDirection(i_GameBoard, Board.eBoardDirections.RightCross, i_CurrentInsertCellCol), currentInsertCellEnum) ||
                          isFourInLine(generateLineOfCellEnumsFromBoardByDirection(i_GameBoard, Board.eBoardDirections.LeftCross, i_CurrentInsertCellCol), currentInsertCellEnum);

            return(result);
        }
Пример #3
0
 public void FillMatrixButtonText(int i_CellRow, int i_CellCol, Board.eBoardCellTypes i_TypeToFillCell)
 {
     if (i_TypeToFillCell == Board.eBoardCellTypes.Circle)
     {
         m_BoardMatrix[i_CellRow, i_CellCol].Text = "O";
     }
     else if (i_TypeToFillCell == Board.eBoardCellTypes.X)
     {
         m_BoardMatrix[i_CellRow, i_CellCol].Text = "X";
     }
     else
     {
         m_BoardMatrix[i_CellRow, i_CellCol].Text = string.Empty;
     }
 }
Пример #4
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);
        }
Пример #5
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);
        }
Пример #6
0
 public LogicBoardCell()
 {
     m_CellType = Board.eBoardCellTypes.Empty;
 }