Beispiel #1
0
def MiniMaxBlack(depth, gameBoard, flag):
    out = BoardLogic.output_Class()
    inp = BoardLogic.output_Class()
    boardList = list()
    if (depth == 0):
        total_Count_final = staticEstimateOpeningBlack(gameBoard)
        out = BoardLogic.output_Class(total_Count_final, out.count + 1,
                                      gameBoard)
        return out

    if (flag == 1):
        boardList = BoardLogic.gen_MoveOpening_Black(gameBoard)
        out.value = minimum_Value

    else:
        boardList = BoardLogic.gen_Move_Opening(gameBoard)
        out.value = maximum_Value

    for bpos in boardList:
        if (flag == 1):
            inp = MiniMaxBlack(depth - 1, bpos, 0)
            if (inp.value > out.value):
                out.value = inp.value
                out.boardState = bpos
            out.count = out.count + inp.count

        else:
            inp = MiniMaxBlack(depth - 1, bpos, 1)
            if (inp.value < out.value):
                out.value = inp.value
                out.boardState = bpos
            out.count = out.count + inp.count

    return out
def ABOpening(depth, board, alpha, beta, flag):
    inp = BoardLogic.output_Class()
    out = BoardLogic.output_Class()
    boardPositionList = list()
    total_Count_final = 0
    if (depth == 0):
        total_Count_final = openingStaticEstimate(board)
        out.value = total_Count_final
        out.count = out.count + 1
        return out

    if (flag == 1):
        boardPositionList = BoardLogic.gen_Move_Opening(board)

    else:
        boardPositionList = BoardLogic.gen_MoveOpening_Black(board)

    for bposition in boardPositionList:
        if (flag == 1):
            inp = ABOpening(depth - 1, bposition, alpha, beta, 0)
            if (inp.value > alpha):
                alpha = inp.value
                out.boardState = bposition
            out.count = out.count + inp.count
        else:
            inp = ABOpening(depth - 1, bposition, alpha, beta, 1)
            if (inp.value < beta):
                beta = inp.value
                out.boardState = bposition
            out.count = out.count + inp.count
        if (alpha >= beta):
            break
    if (flag == 1):
        out.value = alpha
    else:
        out.value = beta
    return out