Exemplo n.º 1
0
        private Node DoAlphaBeta(bool isMin, Board board, int depth, double alpha = 0, double beta = 1)
        {
            Node MinMax = new Node()
            {
                eval = isMin ? 1 : 0
            };

            if (depth == 0)
            {
                return(new Node()
                {
                    move = null, eval = board.Evaluate(color)
                });
            }
            List <Point> playerPieces = board.GetAllPiecesPositions(isMin ? Board.OppositeColor(color) : color);

            foreach (Point piecePos in playerPieces)
            {
                foreach (Point move in board.BoardTab[piecePos.x, piecePos.y].GetValidMoves(board, piecePos))
                {
                    Point[] tempMove = new Point[2] {
                        piecePos, move
                    };

                    board.Execute(tempMove);

                    Node result = DoAlphaBeta(!isMin, board, depth - 1, alpha, beta);

                    board.UndoMove(1);

                    if ((isMin && result.eval <= MinMax.eval) || (!isMin && result.eval >= MinMax.eval))
                    {
                        MinMax.eval = result.eval;
                        MinMax.move = tempMove;
                    }
                    if (isMin)
                    {
                        beta = Math.Min(result.eval, beta);
                    }
                    else
                    {
                        alpha = Math.Max(result.eval, alpha);
                    }
                    if (beta <= alpha)
                    {
                        return(MinMax);
                    }
                }
            }
            return(MinMax);
        }
Exemplo n.º 2
0
        public override Point[] Decide(Board board)
        {
            Point[]      playerChoice = new Point[2];
            List <Point> possibilites = board.GetAllPiecesPositions(color);
            int          choice;
            List <Point> aviableMoves;

            do
            {
                choice       = random.Next() % possibilites.Count;
                aviableMoves = board.BoardTab[possibilites[choice].x, possibilites[choice].y].GetValidMoves(board, possibilites[choice]);
            } while (aviableMoves.Count == 0);

            playerChoice[0] = possibilites[choice];

            choice          = random.Next() % aviableMoves.Count;
            playerChoice[1] = aviableMoves[choice];

            return(playerChoice);
        }