Esempio n. 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
Esempio n. 2
0
def ABGame(depth,board,alpha,beta,flag):
    inp = BoardLogic.output_Class()
    out = BoardLogic.output_Class()
    
    if(depth==0):
        noOfwhite = 0
        noOfBlack = 0
        total_Count_final = 0
        for i in range(0,len(board)):
            if(board[i]=="W"):
                noOfwhite = noOfwhite+1
            if(board[i]=="B"):
                noOfBlack = noOfBlack+1
        total_Count_final = noOfwhite-noOfBlack
        midgame_List = BoardLogic.generateMovesMidgameEndgameBlack(board)
        midgame_listsize = len(midgame_List)
        if(noOfBlack<=2):
            out.value = 10000
        elif(noOfwhite<=2):
            out.value = -10000
        elif(midgame_listsize==0):
            out.value = 10000
        else:
            out.value = 1000*(total_Count_final)-midgame_listsize
        out.count = out.count+1
        out.boardState = board 
        return out
    
    moves_List = list()
    if(flag==1):    
        moves_List = BoardLogic.generateMovesMidgameEndgame(board)
        
    else:
        moves_List = BoardLogic.generateMovesMidgameEndgameBlack(board)
            
    for bPos in moves_List:
        if(flag==1):
            inp = ABGame(depth-1,bPos,alpha,beta,0)
            if(inp.value> alpha):
                alpha = inp.value
                out.boardState = bPos
            out.count = out.count + inp.count
        else:
            inp = ABGame(depth-1,bPos,alpha,beta,1)
            if(inp.value< beta):
                beta = inp.value
                out.boardState = bPos
            out.count = out.count + inp.count
        if(alpha>=beta):
            break
        
    if (flag==1):
        out.value = alpha
    else:
        out.value = beta
    return out
def MiniMaxGame(depth,board,flag):
    out = BoardLogic.output_Class()
    inp = BoardLogic.output_Class()
#    boardList = list()
    if(depth==0):
        noOfWhite = 0
        noOfBlack = 0
        total_Count_final = 0
        for pos in range(0,len(board)):
            if(board[pos]=='W'):
                noOfWhite= noOfWhite+1
            elif(board[pos]=='B'):
                noOfBlack = noOfBlack+1
                
        total_Count_final = noOfWhite-noOfBlack
        midgame_List = BoardLogic.generateMovesMidgameEndgameBlack(board)
        midgame_List_size = len(midgame_List)
        
        if(noOfBlack<=2):
            out.value = 10000
        elif(noOfWhite<=2):
            out.value = -10000
        elif(midgame_List_size==0):
            out.value = 10000
        else:
            out.value = 1000*(total_Count_final) - midgame_List_size
        out.count +=1
        out.boardState = board
        return out
    
    boardList = list()
    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 = MiniMaxGame(depth-1,bPos,0)
            if(inp.value>out.value):
                out.value=inp.value
                out.boardState = bPos
            out.count = out.count + inp.count
            
        else:
            inp = MiniMaxGame(depth-1,bPos,1)
            if(inp.value<out.value):
                out.value=inp.value
                out.boardState = bPos
            out.count = out.count + inp.count         
    return out
Esempio n. 4
0
def MiniMaxGameBlack(depth, gameBoard, flag):
    out = BoardLogic.output_Class()
    inp = BoardLogic.output_Class()
    boardList = list()
    if (depth == 0):
        noOfWhite = 0
        noOfBlack = 0
        for i in range(0, len(gameBoard)):
            if (gameBoard[i] == 'W'):
                noOfWhite += 1
            elif (gameBoard[i] == 'B'):
                noOfBlack += 1

        total_Count_final = noOfBlack - noOfWhite
        moves_List = BoardLogic.generateMovesMidgameEndgame(gameBoard)
        moves_List_size = len(moves_List)
        if (noOfBlack <= 2):
            out.value = 10000
        elif (noOfWhite <= 2):
            out.value = -10000
        elif (moves_List_size == 0):
            out.value = 10000
        else:
            out.value = 1000 * (total_Count_final) - moves_List_size
        out.count += 1
        return out

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

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

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

    return out
Esempio n. 5
0
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
Esempio n. 6
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