def openingStaticEstimate_Improved(boardSt):
    noOfWhite = 0
    noOfBlack = 0
    for i in range(0, len(boardSt)):
        if (boardSt[i] == 'W'):
            noOfWhite = noOfWhite + 1

        elif (boardSt[i] == 'B'):
            noOfBlack = noOfBlack + 1
    mills_count = 0
    staticEstimate = 0
    difference = 0
    difference = noOfWhite - noOfBlack
    for each in range(0, len(boardSt)):
        if (boardSt[each] == 'x'):
            if (BoardLogic.checkMills(each, boardSt, "W") == True):
                mills_count = mills_count + 1
    staticEstimate = mills_count + difference
    return staticEstimate
Ejemplo n.º 2
0
def MiniMaxGameImproved(depth, board, flag):
    out = BoardLogic.output_Class()
    inp = BoardLogic.output_Class()
    boardList = list()
    if (depth == 0):
        noOfWhite = 0
        noOfBlack = 0

        for pos in range(0, len(board)):
            if (board[pos] == 'W'):
                noOfWhite = noOfWhite + 1
            elif (board[pos] == 'B'):
                noOfBlack = noOfBlack + 1

        difference = 0
        mills_count = 0
        staticEstimate = 0
        difference = noOfWhite - noOfBlack

        for each in range(0, len(board)):
            if (board[each] == 'x'):
                if (BoardLogic.checkMills(each, board, 'W') == True):
                    mills_count = mills_count + 1

        staticEstimate = difference + mills_count
        movesList = BoardLogic.generateMovesMidgameEndgameBlack(board)
        movesList_size = len(movesList)

        if (noOfBlack <= 2):
            out.value = 10000
        elif (noOfWhite <= 2):
            out.value = -10000
        elif (movesList_size == 0):
            out.value = 10000
        else:
            out.value = 1000 * (staticEstimate) - movesList_size
        out.count += 1
        return out

    if (flag == 1):
        boardList = BoardLogic.generateMovesMidgameEndgame(board)
        out.value = minimum_Value
    else:
        boardList = BoardLogic.generateMovesMidgameEndgameBlack(board)
        out.value = maximum_Value

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

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