def getNumberOfMovableKings(board, color):
    kingOfColor = 0
    kingOfOpponent = 0
    opponentColor = gamePlay.getOpponentColor(color)
    
    #loop through all kings and find out kings that move without capturing
    for i in range(1,33):
        xy = gamePlay.serialToGrid(i)
        x = xy[0]
        y = xy[1]
        if board[x][y] == color.upper():
            if gamePlay.isCapturePossibleFromPosition(board, x,y) == False:
                kingOfColor += 1
        if board[x][y] == opponentColor.upper():
            if gamePlay.isCapturePossibleFromPosition(board, x,y) == False:
                kingOfOpponent += 1

    scoreMap['movableKings'] =  kingOfColor - kingOfOpponent
def pawnsOnDiagonal(board, color):
    diagonal = [1,6,10,15,19,24,28,5,9,14,18,23,27,32]
    #lowerDiagonal = [5,9,14,18,23,27,32]
    opponentColor = gamePlay.getOpponentColor(color)
    value = 0

    #loop through pieces on diagonals and find out pawns which are at the risk of being captured
    for item in diagonal:
        xy = gamePlay.serialToGrid(item)
        x = xy[0]
        y = xy[1]
        if board[x][y] == color:
            if gamePlay.isCapturePossibleFromPosition(board, x,y):
                value += 1
        elif board[x][y] == opponentColor:
            if gamePlay.isCapturePossibleFromPosition(board, x,y):
                value -= 1
    scoreMap['pawnsOnDiagonal'] = value
Example #3
0
def evaluation3(board, color):
    
    opColor = gamePlay.getOpponentColor(color)
    
    value = 0
    
    # Loop through all board positions
    for piece in range(1, 33):
        # Check if I can capture two
        # Check whether a jump possible to all four directions
        xy = gamePlay.serialToGrid(piece)
        x = xy[0]
        y = xy[1]
        if gamePlay.canMoveToPosition(board, x, y, x-2, y-2) == True:
            if gamePlay.isCapturePossibleFromPosition(board, x-2, y-2):
                if board[x][y].upper() == color.upper():
                    value = value + 1
                elif board[x][y].upper() == opColor.upper():
                    value = value - 1
        if gamePlay.canMoveToPosition(board, x, y, x-2, y+2) == True:
            if gamePlay.isCapturePossibleFromPosition(board, x-2, y+2):
                if board[x][y].upper() == color.upper():
                    value = value + 1
                elif board[x][y].upper() == opColor.upper():
                    value = value - 1
        if gamePlay.canMoveToPosition(board, x, y, x+2, y-2) == True:
            if gamePlay.isCapturePossibleFromPosition(board, x+2, y-2):
                if board[x][y].upper() == color.upper():
                    value = value + 1
                elif board[x][y].upper() == opColor.upper():
                    value = value - 1
        if gamePlay.canMoveToPosition(board, x, y, x+2, y+2) == True:
            if gamePlay.isCapturePossibleFromPosition(board, x+2, y+2):
                if board[x][y].upper() == color.upper():
                    value = value + 1
                elif board[x][y].upper() == opColor.upper():
                    value = value - 1

    # Lets give weightage 10
    # Let us give extra weightage 10 
    return value 
def evaluationAttackFunction(board):
    '''
    number of pieces the board can capture
    '''
    value = 0
    for piece in range(1, 33):
        xy = gamePlay.serialToGrid(piece)
        x = xy[0]
        y = xy[1]
        if isCapturePossibleFromPosition(board, x, y):
            if board[x][y].upper() == currentPlayerColor.upper():  
                value = value+1
            elif board[x][y].upper() == opponentPlayerColor.upper():
                value = value - 1
    return value         
def evaluationAttackFunction(board):
    '''
    number of pieces the board can capture
    '''
    value = 0
    for piece in range(1, 33):
        xy = gamePlay.serialToGrid(piece)
        x = xy[0]
        y = xy[1]
        if isCapturePossibleFromPosition(board, x, y):
            if board[x][y].upper() == currentPlayerColor.upper():
                value = value + 1
            elif board[x][y].upper() == opponentPlayerColor.upper():
                value = value - 1
    return value
Example #6
0
def evaluation(board):
    # Weights are assigned as per the moves forward diagonal vs forward and backward diagonal moves  possible
    #when the piece becomes king more weights are assigned compared to normal piece 
    #print "Considering board"
    global currentPlayerColor    
    global opponentPlayerColor
    value = 0
   
    normalAttack =30
    kingAttack=60
    normalPoint = 1000
    KingPoint = 2000
    currentPiece=0
    opponentPiece=0
    borderPiece=0
    borderList=[(0,1),(0,3),(0,5),(0,7),(1,0),(2,7),(3,7),(4,7),(5,0),(6,7),(7,0),(7,2),(7,4),(7,7)]
    
    for piece in range(1, 33):
        xy = gamePlay.serialToGrid(piece)
        x = xy[0]
        y = xy[1]
        if board[x][y]== board[x][y].upper() and  currentPlayerColor ==  currentPlayerColor.upper():#currentKing
           
            if isCapturePossibleFromPosition(board,x,y):
                #capturePossibleValueCurrent+=1.8
                if (x,y) in borderList:
                    value+=borderPiece+kingAttack+KingPoint
                else:
                    value+=kingAttack+KingPoint                 
            else:    
                #noOfCurrentKings=noOfCurrentKings+1.5
                if (x,y) in borderList:
                    value+=borderPiece+KingPoint
                else:    
                    value+=KingPoint
            currentPiece
        elif  board[x][y]== board[x][y].upper() and  opponentPlayerColor ==  opponentPlayerColor.upper():#opponentKing
            
            if isCapturePossibleFromPosition(board,x,y):
                #capturePossibleValueOpponent-=1.8
                value-=(kingAttack+KingPoint)
            else:        
                #noOfOpponentKings=noOfOpponentKings -1.5
                value-=KingPoint
            opponentPiece+=1
        elif  board[x][y].upper() == currentPlayerColor.upper():#current
            
            if isCapturePossibleFromPosition(board,x,y):
                #capturePossibleValueCurrent+=1.8
                if (x,y) in borderList:
                    value+=borderPiece+normalAttack+normalPoint
                else:
                    value+=normalAttack+normalPoint
            else:    
                #noOfCurrent=noOfCurrent+1.3
                if (x,y) in borderList:
                    value+=borderPiece+normalPoint
                else:    
                    value+=normalPoint
            currentPiece+=1   
        elif board[x][y].upper() == opponentPlayerColor.upper():#opponent
            if isCapturePossibleFromPosition(board,x,y):
                #capturePossibleValueOpponent-=1.8
                value-= (normalAttack+normalPoint)
            else:    
                #noOfOpponent= noOfOpponent-1.3
                value-=normalPoint
            opponentPiece+=1
        #value = (((capturePossibleValueCurrent+capturePossibleValueOpponent))+(1*(noOfCurrentKings+noOfOpponentKings))+ (1*(noOfCurrent+noOfOpponent)))
    if opponentPiece!=0:
        return value
    else:
        return value