public bool IsThereOptionsToPlay(GameUi.ePlayers i_Player, ref List <Point> io_OptionalMoveToPlaye)
        {
            io_OptionalMoveToPlaye = null;
            bool thereIsOption             = false;
            List <eDirections> whereToMove = new List <eDirections>();

            for (int i = 0; i < m_Size; i++)
            {
                for (int j = 0; j < m_Size; j++)
                {
                    if (m_BoardMatrix[i, j] == null && isMoveLeagle(j, i, (Disc.eColors)i_Player, whereToMove))
                    {
                        if (io_OptionalMoveToPlaye == null)
                        {
                            io_OptionalMoveToPlaye = new List <Point>();
                        }

                        thereIsOption = true;
                        io_OptionalMoveToPlaye.Add(new Point(j, i));
                    }
                }
            }

            return(thereIsOption);
        }
Example #2
0
        private int fullBoardCheck(GameBoard i_board, GameUi.ePlayers i_CurrenPlayer)
        {
            int evalue = 0, o_NumOfBlackDiscs = 0, o_NumOfwhiteDiscs = 0;

            i_board.CalcPlayersScore(out o_NumOfBlackDiscs, out o_NumOfwhiteDiscs);
            if (o_NumOfBlackDiscs + o_NumOfwhiteDiscs == i_board.Size * i_board.Size)
            {
                if (o_NumOfBlackDiscs > o_NumOfwhiteDiscs && i_CurrenPlayer == GameUi.ePlayers.FirstPlayer)
                {
                    evalue += 1000000000;
                }
                else if (o_NumOfBlackDiscs > o_NumOfwhiteDiscs && i_CurrenPlayer == GameUi.ePlayers.SecondPlayer)
                {
                    evalue -= 1000000000;
                }
                else if (o_NumOfBlackDiscs < o_NumOfwhiteDiscs && i_CurrenPlayer == GameUi.ePlayers.SecondPlayer)
                {
                    evalue += 1000000000;
                }
                else
                {
                    evalue -= 1000000000;
                }
            }

            return(evalue);
        }
Example #3
0
        private int evaluation(GameBoard i_board, GameUi.ePlayers i_CurrenPlayer)
        {
            int evalue = 0;

            evalue += cornerCheck(i_board, i_CurrenPlayer, 0, 0);
            evalue += cornerCheck(i_board, i_CurrenPlayer, 0, i_board.Size - 1);
            evalue += cornerCheck(i_board, i_CurrenPlayer, i_board.Size - 1, 0);
            evalue += cornerCheck(i_board, i_CurrenPlayer, i_board.Size - 1, i_board.Size - 1);
            evalue += lineCheck(i_board, i_CurrenPlayer);
            evalue += subCheck(i_board, i_CurrenPlayer);
            evalue += fullBoardCheck(i_board, i_CurrenPlayer);

            return(evalue);
        }
Example #4
0
        private int subCheck(GameBoard i_board, GameUi.ePlayers i_CurrenPlayer)
        {
            int NumOfBlackDiscs = 0, NumOfwhiteDiscs = 0, SubOfDiscs = 0, evalue = 0;

            i_board.CalcPlayersScore(out NumOfBlackDiscs, out NumOfwhiteDiscs);
            SubOfDiscs = NumOfBlackDiscs - NumOfwhiteDiscs;

            if (i_CurrenPlayer == GameUi.ePlayers.FirstPlayer)
            {
                evalue += SubOfDiscs;
            }
            else
            {
                evalue -= SubOfDiscs;
            }

            return(evalue);
        }
Example #5
0
        private int cornerCheck(GameBoard i_board, GameUi.ePlayers i_CurrenPlayer, int y, int x)
        {
            int returnevalue = 0;

            if (i_board.BoardMatrix[y, x] != null)
            {
                if (i_board.BoardMatrix[y, x].Color == (Disc.eColors)i_CurrenPlayer)
                {
                    returnevalue += 50;
                }
                else
                {
                    returnevalue -= 50;
                }
            }

            return(returnevalue);
        }
Example #6
0
        private int maxMin(GameBoard i_Board, GameUi.ePlayers i_CurrenPlayer, int i_Depht, int i_MaxDeapth)
        {
            if (i_Depht == i_MaxDeapth)
            {
                return(evaluation(i_Board, i_CurrenPlayer));
            }
            else
            {
                List <Point>    moveOptions     = null;
                List <int>      sonsEvaluations = new List <int>();
                GameUi.ePlayers OtherPlayer;

                if (i_CurrenPlayer == GameUi.ePlayers.FirstPlayer)
                {
                    OtherPlayer = GameUi.ePlayers.SecondPlayer;
                }
                else
                {
                    OtherPlayer = GameUi.ePlayers.FirstPlayer;
                }

                if (i_Board.IsThereOptionsToPlay(i_CurrenPlayer, ref moveOptions))
                {
                    foreach (Point location in moveOptions)
                    {
                        sonsEvaluations.Add(maxMin(i_Board.BoardDuplicatewithNewPoint(i_Board, location, i_CurrenPlayer), OtherPlayer, i_Depht + 1, i_MaxDeapth));
                    }

                    if (i_Depht % 2 == 1)
                    {
                        return(returnMaxInt(sonsEvaluations));
                    }
                    else
                    {
                        return(returnMinInt(sonsEvaluations));
                    }
                }
                else
                {
                    return(0);
                }
            }
        }
        public GameUi.ePlayers[,] CreatePrintingBoard(List <Point> i_OptionsToMove)
        {
            bool didntFoundPossibleMove = true;

            GameUi.ePlayers[,] boardToPrint = new GameUi.ePlayers[m_Size, m_Size];

            for (int i = 0; i < m_Size; i++)
            {
                for (int j = 0; j < m_Size; j++)
                {
                    if (m_BoardMatrix[i, j] != null)
                    {
                        boardToPrint[i, j] = (GameUi.ePlayers)m_BoardMatrix[i, j].Color;
                    }
                    else
                    {
                        if (i_OptionsToMove != null)
                        {
                            foreach (Point CurrentPointInArry in i_OptionsToMove)
                            {
                                if (i == CurrentPointInArry.y && j == CurrentPointInArry.x)
                                {
                                    boardToPrint[i, j]     = GameUi.ePlayers.PossibleMove;
                                    didntFoundPossibleMove = false;
                                }
                            }
                        }

                        if (didntFoundPossibleMove)
                        {
                            boardToPrint[i, j] = GameUi.ePlayers.Empty;
                        }
                    }
                }
            }

            return(boardToPrint);
        }
Example #8
0
        public Point AiTurn(GameBoard i_Board, GameUi.ePlayers i_CurrenPlayer)
        {
            GameUi.ePlayers OtherPlayer;
            Point           returnTurn      = null;
            List <Point>    moveOptions     = null;
            List <int>      sonsEvaluations = new List <int>();

            if (i_CurrenPlayer == GameUi.ePlayers.FirstPlayer)
            {
                OtherPlayer = GameUi.ePlayers.SecondPlayer;
            }
            else
            {
                OtherPlayer = GameUi.ePlayers.FirstPlayer;
            }

            if (i_Board.IsThereOptionsToPlay(i_CurrenPlayer, ref moveOptions))
            {
                foreach (Point location in moveOptions)
                {
                    sonsEvaluations.Add(maxMin(i_Board.BoardDuplicatewithNewPoint(i_Board, location, i_CurrenPlayer), OtherPlayer, 1, 6));
                }
            }

            int maxvalue = returnMaxInt(sonsEvaluations);

            for (int i = 0; i < sonsEvaluations.Count; i++)
            {
                if (sonsEvaluations[i] == maxvalue)
                {
                    returnTurn = moveOptions[i];
                }
            }

            return(returnTurn);
        }
        public GameBoard BoardDuplicatewithNewPoint(GameBoard i_OldGameBoard, Point i_pointToAdd, GameUi.ePlayers i_player)
        {
            GameBoard newBoard = new GameBoard(i_OldGameBoard.Size);

            for (int i = 0; i < i_OldGameBoard.Size; i++)
            {
                for (int j = 0; j < i_OldGameBoard.Size; j++)
                {
                    newBoard.m_BoardMatrix[i, j] = i_OldGameBoard.m_BoardMatrix[i, j];
                }
            }

            newBoard.m_BoardMatrix[i_pointToAdd.y, i_pointToAdd.x] = new Disc((Disc.eColors)i_player, i_pointToAdd);

            return(newBoard);
        }
Example #10
0
        private int lineCheck(GameBoard i_board, GameUi.ePlayers i_CurrenPlayer)
        {
            int returnevalue = 0;

            for (int i = 2; i < i_board.Size - 2; i++)
            {
                if (i_board.BoardMatrix[0, i] != null)
                {
                    if (i_board.BoardMatrix[0, i].Color == (Disc.eColors)i_CurrenPlayer)
                    {
                        returnevalue += 10;
                    }
                    else
                    {
                        returnevalue -= 10;
                    }
                }
            }

            for (int i = 2; i < i_board.Size - 2; i++)
            {
                if (i_board.BoardMatrix[i_board.Size - 1, i] != null)
                {
                    if (i_board.BoardMatrix[i_board.Size - 1, i].Color == (Disc.eColors)i_CurrenPlayer)
                    {
                        returnevalue += 10;
                    }
                    else
                    {
                        returnevalue -= 10;
                    }
                }
            }

            for (int i = 2; i < i_board.Size - 2; i++)
            {
                if (i_board.BoardMatrix[i, 0] != null)
                {
                    if (i_board.BoardMatrix[i, 0].Color == (Disc.eColors)i_CurrenPlayer)
                    {
                        returnevalue += 10;
                    }
                    else
                    {
                        returnevalue -= 10;
                    }
                }
            }

            for (int i = 2; i < i_board.Size - 2; i++)
            {
                if (i_board.BoardMatrix[i, i_board.Size - 1] != null)
                {
                    if (i_board.BoardMatrix[i, i_board.Size - 1].Color == (Disc.eColors)i_CurrenPlayer)
                    {
                        returnevalue += 10;
                    }
                    else
                    {
                        returnevalue -= 10;
                    }
                }
            }

            return(returnevalue);
        }
Example #11
0
        internal static void PrintBoard(int i_MatrixSize, GameUi.ePlayers[,] i_Board, string i_Player1Name, string i_Player2Name, GameUi.ePlayers i_PlayerTurn, int i_Player1Score, int i_Player2Score)
        {
            System.Console.Clear();
            string gameBoardOutput = string.Empty;
            string playerTurnsName;
            int    i = 0;
            int    j = 0;

            if (i_PlayerTurn == GameUi.ePlayers.FirstPlayer)
            {
                playerTurnsName = "Its: " + i_Player1Name + " Turn put  " + (char)i_PlayerTurn;
            }
            else if (i_PlayerTurn == GameUi.ePlayers.SecondPlayer)
            {
                playerTurnsName = "Its: " + i_Player2Name + " Turn put  " + (char)i_PlayerTurn;
            }
            else
            {
                string gameOver = string.Format(@"    
   __ _  __ _ _ __ ___   ___    _____   _____ _ __ 
  / _` |/ _` | '_ ` _ \ / _ \  / _ \ \ / / _ \ '__|
 | (_| | (_| | | | | | |  __/ | (_) \ V /  __/ |   
  \__, |\__,_|_| |_| |_|\___|  \___/ \_/ \___|_|   
   __/ |                                           
  |___/                                            ");
                if (i_Player1Score > i_Player2Score)
                {
                    playerTurnsName = gameOver + i_Player1Name + " Wins";
                }
                else if (i_Player1Score < i_Player2Score)
                {
                    playerTurnsName = gameOver + i_Player2Name + " Wins";
                }
                else
                {
                    playerTurnsName = gameOver + "Its A Tie";
                }
            }

            if (i_MatrixSize == 6)
            {
                gameBoardOutput = string.Format(@"
            A   B   C   D   E   F  
          =========================
        1 | {0} | {1} | {2} | {3} | {4} | {5} |
          =========================
        2 | {6} | {7} | {8} | {9} | {10} | {11} |
          =========================
        3 | {12} | {13} | {14} | {15} | {16} | {17} |   {36}:{37}
          =========================
        4 | {18} | {19} | {20} | {21} | {22} | {23} |   {38}:{39}
          =========================
        5 | {24} | {25} | {26} | {27} | {28} | {29} |
          =========================
        6 | {30} | {31} | {32} | {33} | {34} | {35} |
          =========================
          {40}",
                                                (char)i_Board[i, j++ % 6], (char)i_Board[i, j++ % 6], (char)i_Board[i, j++ % 6], (char)i_Board[i, j++ % 6], (char)i_Board[i, j++ % 6], (char)i_Board[i++, j++ % 6],
                                                (char)i_Board[i, j++ % 6], (char)i_Board[i, j++ % 6], (char)i_Board[i, j++ % 6], (char)i_Board[i, j++ % 6], (char)i_Board[i, j++ % 6], (char)i_Board[i++, j++ % 6],
                                                (char)i_Board[i, j++ % 6], (char)i_Board[i, j++ % 6], (char)i_Board[i, j++ % 6], (char)i_Board[i, j++ % 6], (char)i_Board[i, j++ % 6], (char)i_Board[i++, j++ % 6],
                                                (char)i_Board[i, j++ % 6], (char)i_Board[i, j++ % 6], (char)i_Board[i, j++ % 6], (char)i_Board[i, j++ % 6], (char)i_Board[i, j++ % 6], (char)i_Board[i++, j++ % 6],
                                                (char)i_Board[i, j++ % 6], (char)i_Board[i, j++ % 6], (char)i_Board[i, j++ % 6], (char)i_Board[i, j++ % 6], (char)i_Board[i, j++ % 6], (char)i_Board[i++, j++ % 6],
                                                (char)i_Board[i, j++ % 6], (char)i_Board[i, j++ % 6], (char)i_Board[i, j++ % 6], (char)i_Board[i, j++ % 6], (char)i_Board[i, j++ % 6], (char)i_Board[i++, j++ % 6],
                                                i_Player1Name, i_Player1Score.ToString(), i_Player2Name, i_Player2Score.ToString(), playerTurnsName);
            }
            else
            {
                gameBoardOutput = string.Format(@"
            A   B   C   D   E   F   G   H   
          =================================
        1 | {0} | {1} | {2} | {3} | {4} | {5} | {6} | {7} |
          =================================
        2 | {8} | {9} | {10} | {11} | {12} | {13} | {14} | {15} |
          =================================
        3 | {16} | {17} | {18} | {19} | {20} | {21} | {22} | {23} |
          =================================
        4 | {24} | {25} | {26} | {27} | {28} | {29} | {30} | {31} |  {64}:{65}
          =================================
        5 | {32} | {33} | {34} | {35} | {36} | {37} | {38} | {39} |  {66}:{67}
          =================================
        6 | {40} | {41} | {42} | {43} | {44} | {45} | {46} | {47} |  
          =================================
        7 | {48} | {49} | {50} | {51} | {52} | {53} | {54} | {55} |
          =================================
        8 | {56} | {57} | {58} | {59} | {60} | {61} | {62} | {63} |
          =================================
          {68}",
                                                (char)i_Board[i, j++ % 8], (char)i_Board[i, j++ % 8], (char)i_Board[i, j++ % 8], (char)i_Board[i, j++ % 8], (char)i_Board[i, j++ % 8], (char)i_Board[i, j++ % 8], (char)i_Board[i, j++ % 8], (char)i_Board[i++, j++ % 8],
                                                (char)i_Board[i, j++ % 8], (char)i_Board[i, j++ % 8], (char)i_Board[i, j++ % 8], (char)i_Board[i, j++ % 8], (char)i_Board[i, j++ % 8], (char)i_Board[i, j++ % 8], (char)i_Board[i, j++ % 8], (char)i_Board[i++, j++ % 8],
                                                (char)i_Board[i, j++ % 8], (char)i_Board[i, j++ % 8], (char)i_Board[i, j++ % 8], (char)i_Board[i, j++ % 8], (char)i_Board[i, j++ % 8], (char)i_Board[i, j++ % 8], (char)i_Board[i, j++ % 8], (char)i_Board[i++, j++ % 8],
                                                (char)i_Board[i, j++ % 8], (char)i_Board[i, j++ % 8], (char)i_Board[i, j++ % 8], (char)i_Board[i, j++ % 8], (char)i_Board[i, j++ % 8], (char)i_Board[i, j++ % 8], (char)i_Board[i, j++ % 8], (char)i_Board[i++, j++ % 8],
                                                (char)i_Board[i, j++ % 8], (char)i_Board[i, j++ % 8], (char)i_Board[i, j++ % 8], (char)i_Board[i, j++ % 8], (char)i_Board[i, j++ % 8], (char)i_Board[i, j++ % 8], (char)i_Board[i, j++ % 8], (char)i_Board[i++, j++ % 8],
                                                (char)i_Board[i, j++ % 8], (char)i_Board[i, j++ % 8], (char)i_Board[i, j++ % 8], (char)i_Board[i, j++ % 8], (char)i_Board[i, j++ % 8], (char)i_Board[i, j++ % 8], (char)i_Board[i, j++ % 8], (char)i_Board[i++, j++ % 8],
                                                (char)i_Board[i, j++ % 8], (char)i_Board[i, j++ % 8], (char)i_Board[i, j++ % 8], (char)i_Board[i, j++ % 8], (char)i_Board[i, j++ % 8], (char)i_Board[i, j++ % 8], (char)i_Board[i, j++ % 8], (char)i_Board[i++, j++ % 8],
                                                (char)i_Board[i, j++ % 8], (char)i_Board[i, j++ % 8], (char)i_Board[i, j++ % 8], (char)i_Board[i, j++ % 8], (char)i_Board[i, j++ % 8], (char)i_Board[i, j++ % 8], (char)i_Board[i, j++ % 8], (char)i_Board[i++, j++ % 8],
                                                i_Player1Name, i_Player1Score.ToString(), i_Player2Name, i_Player2Score.ToString(), playerTurnsName);
            }

            System.Console.Write(m_Head);
            System.Console.ForegroundColor = ConsoleColor.White;
            System.Console.WriteLine(gameBoardOutput);
        }
Example #12
0
        public void StartGame()
        {
            bool restartGame = true;

            while (restartGame)
            {
                GameUi gameUi = new GameUi();
                gameUi.LaunchMenu();
                GameBoard       gameBoard = new GameBoard((int)gameUi.MatrixSize);
                Point           userCordInput;
                GameUi.ePlayers currentPlayer = GameUi.ePlayers.FirstPlayer;
                bool            continueGame = true;
                int             gameItrator = 0;
                int             thereNoOptionsForXPlayers = 0;
                List <Point>    moveOptions = null;
                bool            isLastTurnWasOk = true;
                int             player1Score = 0, player2Score = 0;
                while (continueGame)
                {
                    if (gameBoard.IsThereOptionsToPlay(currentPlayer, ref moveOptions))
                    {
                        if ((gameUi.GameMode == GameUi.eGameMode.PVc && currentPlayer == GameUi.ePlayers.SecondPlayer) || gameUi.GameMode == GameUi.eGameMode.CVc)
                        {
                            userCordInput = m_PcAi.AiTurn(gameBoard, currentPlayer);
                        }
                        else
                        {
                            gameBoard.CalcPlayersScore(out player1Score, out player2Score);
                            userCordInput = gameUi.NextTurn(gameBoard.CreatePrintingBoard(moveOptions), currentPlayer, isLastTurnWasOk, player1Score, player2Score);
                        }

                        if (gameBoard.TryAddDiscToLocation(userCordInput.x, userCordInput.y, (Disc.eColors)currentPlayer))
                        {
                            gameItrator++;
                            isLastTurnWasOk = true;
                        }
                        else
                        {
                            isLastTurnWasOk = false;
                        }

                        thereNoOptionsForXPlayers = 0;
                    }
                    else
                    {
                        thereNoOptionsForXPlayers++;
                        gameItrator++;
                    }

                    if (gameItrator % 2 == 0)
                    {
                        currentPlayer = GameUi.ePlayers.FirstPlayer;
                    }
                    else
                    {
                        currentPlayer = GameUi.ePlayers.SecondPlayer;
                    }

                    continueGame = thereNoOptionsForXPlayers < 2;
                }

                gameBoard.CalcPlayersScore(out player1Score, out player2Score);
                gameUi.GameOver(gameBoard.CreatePrintingBoard(moveOptions), player1Score, player2Score, ref restartGame);
            }
        }