Exemplo n.º 1
0
 private void initializeGameLogic()
 {
     m_OtheloGameLogic = new OtheloGameLogic(m_BoardSize, m_Player1Name, m_Player2Name, m_IsAgainstComputer, m_Turn, (eDifficulty)m_Difficulty);
     m_OtheloGameLogic.ValidMovesCoordinateChange += sendToFormOthloGameBoardTheCurrentValidMovesCoordinate;
     m_OtheloGameLogic.PieceAddedOnBoard          += pieceAddedOnBoard;
     m_OtheloGameLogic.CellsChangedTeam           += cellsChangedTeam;
 }
Exemplo n.º 2
0
        private int calculateScoreOfBoard(int[,] i_scoreBoard, OtheloGameLogic i_BoardPosition)
        {
            int score = 0;

            for (byte row = 0; row < i_BoardPosition.GamePanel.Size; row++)
            {
                for (byte column = 0; column < i_BoardPosition.GamePanel.Size; column++)
                {
                    if (i_BoardPosition.GamePanel[new Coordinates(row, column)] != null)
                    {
                        if (i_BoardPosition.GamePanel[new Coordinates(row, column)].Team == Player.eTeam.White)
                        {
                            score += i_scoreBoard[row, column];
                            score += 500;
                        }
                        else if (i_BoardPosition.GamePanel[new Coordinates(row, column)].Team == Player.eTeam.Black)
                        {
                            score += i_scoreBoard[row, column];
                            score -= 500;
                        }
                    }
                }
            }

            return(score);
        }
Exemplo n.º 3
0
        public Node minimax(OtheloGameLogic i_BoardPiecesPosition, int i_Depth, bool i_MaximizingPlayer)
        {
            if (i_Depth == 0 || (!i_BoardPiecesPosition.GetCurrentPlayerTurn().IsHaveValidMove&& !i_BoardPiecesPosition.GetOpposingPlayer().IsHaveValidMove))
            {
                return(boardPositionAIScore(i_BoardPiecesPosition));
            }

            if (i_MaximizingPlayer)
            {
                int  maxEval    = int.MinValue;
                Node resMaxEval = new Node();
                resMaxEval.ScoreResult         = maxEval;
                resMaxEval.BoardPiecesPosition = i_BoardPiecesPosition;

                foreach (Coordinates child in i_BoardPiecesPosition.ValidCoordinatesToAddPieces())
                {
                    i_BoardPiecesPosition.SetInputPieceAndFlipAllTheInfluencedPieces(child, true);
                    Node eval = minimax(i_BoardPiecesPosition, i_Depth - 1, false);

                    if (maxEval < eval.ScoreResult)
                    {
                        resMaxEval.ScoreResult         = eval.ScoreResult;
                        resMaxEval.BoardPiecesPosition = i_BoardPiecesPosition;
                    }
                }
                return(resMaxEval);
            }
            else
            {
                int  minEval    = int.MaxValue;
                Node resMinEval = new Node();
                resMinEval.ScoreResult         = minEval;
                resMinEval.BoardPiecesPosition = i_BoardPiecesPosition;

                foreach (Coordinates child in i_BoardPiecesPosition.ValidCoordinatesToAddPieces())
                {
                    i_BoardPiecesPosition.SetInputPieceAndFlipAllTheInfluencedPieces(child, true);
                    Node eval = minimax(i_BoardPiecesPosition, i_Depth - 1, true);

                    if (minEval > eval.ScoreResult)
                    {
                        resMinEval.ScoreResult         = eval.ScoreResult;
                        resMinEval.BoardPiecesPosition = i_BoardPiecesPosition;
                    }
                }
                return(resMinEval);
            }
        }
Exemplo n.º 4
0
        private Node boardPositionAIScore(OtheloGameLogic i_BoardPosition)
        {
            int ScoreOfCurrentBoard = 0;

            switch (i_BoardPosition.GamePanel.Size)
            {
            case (byte)eBoardSize.Small:
            {
                int[,] scoreBoard = new int[(byte)eBoardSize.Small, (byte)eBoardSize.Small]
                {
                    { 0, 0, 0, 0, 0, 0 },
                    { 0, 0, 0, 0, 0, 0 },
                    { 0, 0, 0, 0, 0, 0 },
                    { 0, 0, 0, 0, 0, 0 },
                    { 0, 0, 0, 0, 0, 0 },
                    { 0, 0, 0, 0, 0, -10000000 }
                };
                ScoreOfCurrentBoard = calculateScoreOfBoard(scoreBoard, i_BoardPosition);

                break;
            }
                //case (byte)eBoardSize.Medium:
                //    {
                //        break;
                //    }
                //case (byte)eBoardSize.Large:
                //    {
                //        break;
                //    }
            }

            Node result = new Node();

            result.ScoreResult         = ScoreOfCurrentBoard;
            result.BoardPiecesPosition = i_BoardPosition;
            return(result);
        }