Esempio n. 1
0
        public static void CheckCourseOfMove(eDirection i_CurrentDirection, Player i_PlayerInMove, NodeForGame i_CurrentNodeToCheck, List <NodeForGame> io_OptionForCoursesList, bool i_IsCheckOnly)
        {
            List <NodeForGame> optionNodesToChange = new List <NodeForGame>(2);
            bool noOppositeSymbolInRoute           = true;
            char opponentSymbol = 'X';

            if (i_PlayerInMove.m_PlayerSymbol == 'X')
            {
                opponentSymbol = 'O';
            }

            int i_Line   = i_CurrentNodeToCheck.LineNumber;
            int j_Column = i_CurrentNodeToCheck.ColumnNumber;

            if (GetNextNodeInRoute(ref i_Line, ref j_Column, i_CurrentDirection, m_MainBoard.BoardSize))
            {
                CheckingForOppositesymbol(m_MainBoard, opponentSymbol, i_IsCheckOnly, ref optionNodesToChange, ref noOppositeSymbolInRoute, i_CurrentDirection, ref i_Line, ref j_Column);
            }

            if (m_MainBoard.BoardMatrix[i_Line, j_Column] == '\0' && (!noOppositeSymbolInRoute) && i_IsCheckOnly)
            {
                NodeForGame newValidOption = new NodeForGame(i_Line, j_Column);
                io_OptionForCoursesList.Add(newValidOption);
            }

            if (m_MainBoard.BoardMatrix[i_Line, j_Column] == i_PlayerInMove.m_PlayerSymbol && (!noOppositeSymbolInRoute) && (!i_IsCheckOnly))
            {
                AddNewSmallListToBigList(io_OptionForCoursesList, optionNodesToChange, io_OptionForCoursesList.Count);
            }
        }
Esempio n. 2
0
        public static bool CheckMoveValidation(string i_StrinputFromUserDuringTheGame, bool i_IsPlayerOneTurn)
        {
            bool               isValidMove       = false;
            NodeForGame        nodeOfTheUserMove = StringOfMoveToNodeForGame(i_StrinputFromUserDuringTheGame);
            List <NodeForGame> newValidMovesList = MakeValidMovesList(i_IsPlayerOneTurn);

            for (int i = 0; i < newValidMovesList.Count; i++)
            {
                if (newValidMovesList[i].LineNumber == nodeOfTheUserMove.LineNumber && newValidMovesList[i].ColumnNumber == nodeOfTheUserMove.ColumnNumber)
                {
                    isValidMove = true;
                }
            }
            return(isValidMove);
        }
Esempio n. 3
0
        public static string GetMoveFromComputer()
        {
            bool isPlayerOneTurn = false;

            char[]             computerMoveString         = new char[2];
            List <NodeForGame> listOfValidMoveForComputer = MakeValidMovesList(isPlayerOneTurn);
            Random             computerTurn = new Random();
            int         moveIndex           = computerTurn.Next(listOfValidMoveForComputer.Count);
            NodeForGame chosenNode          = listOfValidMoveForComputer[moveIndex];

            computerMoveString[0] = (char)(chosenNode.ColumnNumber + 'A');
            computerMoveString[1] = (char)(chosenNode.LineNumber + '0' + 1);
            string toReturn = new string(computerMoveString);

            return(toReturn);
        }
Esempio n. 4
0
        public static NodeForGame StringOfMoveToNodeForGame(string i_StringOfMove)
        {
            int lineForBoard;
            int columnForBoard;

            if (i_StringOfMove.Length == 2)
            {
                lineForBoard = i_StringOfMove[1] - '0' - 1;
            }
            else
            {
                lineForBoard = i_StringOfMove[2] - '0' - 1 + 10;
            }
            columnForBoard = (i_StringOfMove[0] - 'A');
            NodeForGame theNewNodeToReturn = new NodeForGame(lineForBoard, columnForBoard);

            return(theNewNodeToReturn);
        }
Esempio n. 5
0
        public static void ChangeBoardAccordingToMove(string i_MoveFromUserToPlay, bool i_IsPlayerOneTurn)
        {
            Player currentPlayer;

            if (i_IsPlayerOneTurn)
            {
                currentPlayer = m_Player1;
            }
            else
            {
                currentPlayer = m_Player2;
            }
            List <NodeForGame> NodeToChangeList     = new List <NodeForGame>(2);
            NodeForGame        TheValidMoveFromUser = StringOfMoveToNodeForGame(i_MoveFromUserToPlay);

            NodeToChangeList.Add(TheValidMoveFromUser);
            CheckEightDirectionForMove(NodeToChangeList, currentPlayer, TheValidMoveFromUser, false);
            ChangBoardMatrix(NodeToChangeList, currentPlayer.m_PlayerSymbol);
        }
Esempio n. 6
0
 public static void CheckingForOppositesymbol(Board i_MainBoard, char i_OpponentSymbol, bool i_IsCheckOnly, ref List <NodeForGame> io_OptionNodesToChange, ref bool io_NoOppositeSymbolInRoute, eDirection i_CurrentDirection, ref int io_Line, ref int io_Column)
 {
     while (i_MainBoard.BoardMatrix[io_Line, io_Column] == i_OpponentSymbol)
     {
         if (!i_IsCheckOnly)
         {
             NodeForGame newNodeForOptionalChange = new NodeForGame(io_Line, io_Column);
             io_OptionNodesToChange.Add(newNodeForOptionalChange);
         }
         io_NoOppositeSymbolInRoute = false;
         if (GetNextNodeInRoute(ref io_Line, ref io_Column, i_CurrentDirection, i_MainBoard.BoardSize))
         {
             continue;
         }
         else
         {
             break;
         }
     }
 }
Esempio n. 7
0
        public static List <NodeForGame> MakeValidMovesList(bool i_IsPlayerOneTurn)
        {
            Player             playerInMove  = m_Player2;
            List <NodeForGame> validMoveList = new List <NodeForGame>(2);

            if (i_IsPlayerOneTurn)
            {
                playerInMove = m_Player1;
            }
            for (int i = 0; i < m_MainBoard.BoardSize; i++)
            {
                for (int j = 0; j < m_MainBoard.BoardSize; j++)
                {
                    if (m_MainBoard.BoardMatrix[i, j] == playerInMove.m_PlayerSymbol)
                    {
                        NodeForGame currentNodeToCheck = new NodeForGame(i, j);
                        CheckEightDirectionForMove(validMoveList, playerInMove, currentNodeToCheck, true);
                    }
                }
            }
            return(validMoveList);
        }
Esempio n. 8
0
 public static void CheckEightDirectionForMove(List <NodeForGame> io_OptionForMoveList, Player i_PlayerinMove, NodeForGame i_CurrentNodeToCheck, bool i_IsCheckOnly)
 {
     for (eDirection i = eDirection.Up; i <= eDirection.UpLeft; i++)
     {
         CheckCourseOfMove(i, i_PlayerinMove, i_CurrentNodeToCheck, io_OptionForMoveList, i_IsCheckOnly);
     }
 }