Ejemplo n.º 1
0
        public int MaxValue(Board i_Board, int i_Alpha, int i_Beta, int i_Depth, Square.eSquareColor i_PrevColor)
        {
            LinkedList <Square> possibleMoves = listOfPossibleMoves(i_Board, i_PrevColor);
            int   value;
            Board board;

            if (cutOffTest(i_Board, i_Depth, possibleMoves))
            {
                value = evalBoard(i_Board, possibleMoves.Count);
            }
            else
            {
                value = int.MinValue + 1;
                Square.eSquareColor color = (i_PrevColor == Square.eSquareColor.Black) ? Square.eSquareColor.White : Square.eSquareColor.Black;
                foreach (Square square in possibleMoves)
                {
                    board = createNewBoard((Board)i_Board.Clone(), square, i_PrevColor);
                    value = max(value, MinValue(board, i_Alpha, i_Beta, i_Depth + 1, color));
                    if (value >= i_Beta)
                    {
                        break;
                    }

                    i_Alpha = max(i_Alpha, value);
                }
            }

            return(value);
        }
Ejemplo n.º 2
0
        public int MinValue(Board i_Board, int i_Alpha, int i_Beta, int i_Depth, Square.eSquareColor i_PrevColor)
        {
            LinkedList <Square> possibleMoves = listOfPossibleMoves(i_Board, i_PrevColor);
            int value;

            if (cutOffTest(i_Board, i_Depth, possibleMoves))
            {
                value = evalBoard(i_Board, possibleMoves.Count);
            }
            else
            {
                value = int.MaxValue;
                Square.eSquareColor color = (i_PrevColor == Square.eSquareColor.Black) ? Square.eSquareColor.White : Square.eSquareColor.Black;
                foreach (Square square in possibleMoves)
                {
                    value = min(value, MaxValue(createNewBoard(i_Board, square, i_PrevColor), i_Alpha, i_Beta, i_Depth + 1, color));
                    if (value <= i_Alpha)
                    {
                        break;
                    }

                    i_Beta = min(i_Beta, value);
                }
            }

            return(value);
        }
Ejemplo n.º 3
0
        private Image getImageByColor(Square.eSquareColor i_PlayerColor, bool i_TransparencyImage)
        {
            Image image = null;

            if (i_TransparencyImage)
            {
                image = Properties.Resources.possibleMoveSquare;
            }
            else
            {
                switch (i_PlayerColor)
                {
                case Square.eSquareColor.White:
                    image = Properties.Resources.whitePlayer;
                    break;

                case Square.eSquareColor.Black:
                    image = Properties.Resources.blackPlayer;
                    break;

                case Square.eSquareColor.Empty:
                    image = Properties.Resources.emptySquare;
                    break;
                }
            }

            return(image);
        }
Ejemplo n.º 4
0
        private Board createNewBoard(Board i_CurrentBoard, Square i_PossibleMove, Square.eSquareColor i_Color)
        {
            bool isValid;

            CheckIfSquareIsValidAndMakeMove(i_PossibleMove, sr_MakeMove, i_CurrentBoard, out isValid);

            return(i_CurrentBoard);
        }
Ejemplo n.º 5
0
        public Board AlphaBetaPruning(Board i_CurrentBoard)
        {
            int alpha = int.MinValue + 1, beta = int.MaxValue, value;
            LinkedList <Square> possibleMoves = new LinkedList <Square>();

            possibleMoves = listOfPossibleMoves(i_CurrentBoard, m_PlayerColor);

            Square.eSquareColor color = (m_PlayerColor == Square.eSquareColor.Black) ? Square.eSquareColor.White : Square.eSquareColor.Black;
            foreach (Square square in possibleMoves)
            {
                value = MinValue(createNewBoard((Board)i_CurrentBoard.Clone(), square, m_PlayerColor), alpha, beta, 1, color);
                if (value > alpha)
                {
                    m_FinalBoard = createNewBoard((Board)i_CurrentBoard.Clone(), square, m_PlayerColor);
                    alpha        = value;
                }
            }

            return(m_FinalBoard);
        }
Ejemplo n.º 6
0
 private LinkedList <Square> listOfPossibleMoves(Board i_GameBoard, Square.eSquareColor i_CurrentMoveColor)
 {
     return(new Player("temp", i_CurrentMoveColor).ListOfPossibleMoves(i_GameBoard));
 }
Ejemplo n.º 7
0
 private int getCurrentValueByColor(Square.eSquareColor i_Color, int i_Value)
 {
     return((i_Color == m_PlayerColor) ? i_Value : -1 * i_Value);
 }
Ejemplo n.º 8
0
 public AiPlayer(string i_NameOfUser, Square.eSquareColor i_PlayerColor)
     : base(i_NameOfUser, i_PlayerColor)
 {
 }
Ejemplo n.º 9
0
 public Player(string i_NameOfUser, Square.eSquareColor i_PlayerColor)
 {
     m_NameOfUser  = i_NameOfUser;
     m_PlayerColor = i_PlayerColor;
 }