Exemplo n.º 1
0
def randomOffenseOneWithTwicePlus( gameBoard, playerTurn ):
    move,isBlockOrWin= randomOffenseWithTwicePlus(gameBoard,playerTurn)
    if isBlockOrWin == 2 or isBlockOrWin:
        return move, isBlockOrWin
    
    #consider all my possible moves
    validMoves= aif.getValidMoves( gameBoard )
    bestMove= move
    bestNumPlayerIDs= -1
    for (x,y) in validMoves:
        #simulate this move, and assume opponent plays 'best' possible move.
        #the best move from me is the one leaving the state with a higher
        #sequence of my playerID as a valid win AFTER opponent's 'best' move
        tempBoard= py.copy(gameBoard)
        tempBoard[x,y]= playerTurn
        opponentTurn= aif.getOpponent(playerTurn)
        oppMove, _= randomOffenseWithTwicePlus(tempBoard, opponentTurn)
        tempBoard[oppMove]= opponentTurn
        #get new valid moves and new uselessSlotFilter values. Compare with
        #best seen thus far 
        newValidMoves= aif.getValidMoves( tempBoard )
        filterWorked, newValidMoves= aif.uselessSlotFilter( tempBoard, newValidMoves, playerTurn )
        if filterWorked:
            for (_,_,value) in newValidMoves:
                if value > 1 and value > bestNumPlayerIDs and aif.isSafeToPlayPlus( (x,y), playerTurn, gameBoard ):
                    bestMove= (x,y)
                    bestNumPlayerIDs= value
    return bestMove, 0
Exemplo n.º 2
0
def randomOffense(gameBoard, playerTurn):
    move,isRandom= randomMovePlusPlus( gameBoard, playerTurn )
    if not isRandom:
        #print "RandomOffense --- blocking"
        return move, not isRandom
        
    validMoves= aif.getValidMoves( gameBoard )
    filterWorked, validMoves= aif.uselessSlotFilter( gameBoard, validMoves, playerTurn )
    if filterWorked:
        #choose move with higher number
        move= (-1,-1)
        bestVal= -1
        for (x,y,value) in validMoves:
            if value > bestVal:
                move= (x,y)
                bestVal= value
        return move, not isRandom
    return move, not isRandom
Exemplo n.º 3
0
def randomOffenseWithTwicePlus(gameBoard, playerTurn):
    move,isBlockOrWin= lookAheadTwicePlus(gameBoard,playerTurn)
    if isBlockOrWin == 2 or isBlockOrWin:
        return move, isBlockOrWin
        
    '''isSingleLineTrap, blockingMove= aif.blockSingleLineTrap(gameBoard, playerTurn)
    if isSingleLineTrap:
        return blockingMove, isSingleLineTrap'''
        
    validMoves= aif.getValidMoves( gameBoard )
    filterWorked, validMoves= aif.uselessSlotFilter( gameBoard, validMoves, playerTurn )
    if filterWorked:
        #choose move with higher number
        bestVal= -1
        for (x,y,value) in validMoves:
            if value > 1 and value > bestVal and aif.isSafeToPlayPlus( (x,y), playerTurn, gameBoard ):
                move= (x,y)
                bestVal= value
        return move, 0
    return move, 0