Exemple #1
0
def randomMovePlus2(gameBoard, playerTurn):
    move= None
    sequentialCells= glf.getSequentialCells(gameBoard,3)
    if playerTurn == 1:
        possibleWins= sequentialCells[1]
        possibleLosses= sequentialCells[2]
    elif playerTurn == 2:
        possibleWins= sequentialCells[2]
        possibleLosses= sequentialCells[1]
    
    #try to win
    for pos, direction in possibleWins:
        move= aif.blockOpponent(gameBoard, pos, direction)
        if move:
            #print "WOOOOOOOONNN, playing: ", move
            break
            
    if not move:
        #print "TRY TO BLOCK OPPONENT"
        for pos, direction in possibleLosses:
            move= aif.blockOpponent(gameBoard, pos, direction)
            if move:
                #print "BLOCKING OPPONENT, playing: " , move
                break

    if not move:
        #print "COULD NOT BLOCK OR WIN, playing random"
        return randomMove(gameBoard)
    else:
        return move
Exemple #2
0
def evalB2( gameBoard, playerTurn ):
    opponentTurn= getOpponent( playerTurn )
    
    #get whether board contains win or loss (or both)
    allWins= glf.getSequentialCells( gameBoard, 4 )
    wins= len( allWins[playerTurn] )
    losses= len( allWins[opponentTurn] )
    
    #get results of scoreBoard
    myScores, yourScores, candidateSlots= scoreBoard( gameBoard, playerTurn )
    times= 2
    tempPt= 0.0
    tempOt= 0.0
    for score in sorted(candidateSlots.keys(), reverse=True):
        if times == 0:
            break
        nextBests= candidateSlots[score]
        for x,y,player in nextBests:
            if player == playerTurn:
                #update partial score
                tempPt+= score
            else:
                tempOt+= score
        times-=1
    
    #get the number of offensive plays
    offPlays= 0.0
    validMoves= getValidMoves( gameBoard )
    filterWorked, validMoves= uselessSlotFilter( gameBoard, validMoves, playerTurn )
    if filterWorked:
        offPlays= len(validMoves)
        
    #get the number of win/lose opportunities
    sequentialCells= glf.getSequentialCellsPlus( gameBoard, 4 )
    winOpportunities= sequentialCells[playerTurn]
    loseOpportunities= sequentialCells[opponentTurn]
    numWins= len(winOpportunities)
    numLosses= len(loseOpportunities)

    #calculate linear combination
    #value= wins * 10000 + losses * (-10000) + tempPt * 0.3 + tempOt * (-0.1) + offPlays * 0.4 + numWins * 0.3 +  numLosses * (-0.3)
    value= wins * 10000 + losses * (-10000)  + offPlays * 0.4 + numWins * 0.6 + tempPt * 0.1 + numLosses * (-0.1) +  + tempOt * (-0.1)
    #print "value is ", value
    return value