Beispiel #1
0
def calculate(board, search_depth, ori_color):
    total_num = gameplay.score(board)[0] + gameplay.score(board)[1]
    npp, vp, fpp, spp = value(board, ori_color, search_depth, total_num)
    cp = corner_point(board, ori_color)
    nc = near_corner(board, ori_color)
    mpp = mobility(board, ori_color)
    #total_num>=20 start calculating stable_point
    if total_num < 20:
        #npp:num_point cp:corner_point nc:near_corner mpp:mobility_point fpp:frontier_point vp:value_point spp:stablity_point
        return 20 * npp + 12000 * cp + 3000 * nc + 50 * mpp + 30 * fpp + 60 * vp
    else:
        # return 10*npp+25*801.724*cp+382.026*12.5*nc+78.922*mpp+74.396*fpp+100*vp
        # print 'npp:',20*npp,'cp:',12000*cp,'nc:', 3000*nc,'mpp:', 30*mpp,'fpp:', 30*fpp,'vp:', 50*vp,'sp:', 20*spp
        return 20 * npp + 12000 * cp + 3000 * nc + 30 * mpp + 30 * fpp + 50 * vp + 20 * spp
Beispiel #2
0
def calculate(board,search_depth,ori_color):
    total_num=gameplay.score(board)[0]+gameplay.score(board)[1]
    npp,vp,fpp,spp=value(board,ori_color,search_depth,total_num)
    cp=corner_point(board,ori_color)
    nc=near_corner(board,ori_color)
    mpp=mobility(board,ori_color)
    #total_num>=20 start calculating stable_point
    if total_num<20:
#npp:num_point cp:corner_point nc:near_corner mpp:mobility_point fpp:frontier_point vp:value_point spp:stablity_point
        return 20*npp+12000*cp+3000*nc+50*mpp+30*fpp+60*vp
    else:
        # return 10*npp+25*801.724*cp+382.026*12.5*nc+78.922*mpp+74.396*fpp+100*vp
        # print 'npp:',20*npp,'cp:',12000*cp,'nc:', 3000*nc,'mpp:', 30*mpp,'fpp:', 30*fpp,'vp:', 50*vp,'sp:', 20*spp
        return 20*npp+12000*cp+3000*nc+30*mpp+30*fpp+50*vp+20*spp
Beispiel #3
0
def value(board):
    evalvalue = 0
    baseValue = [[99, -8, 8, 6, 6, 8, -8, 99], [-8, -24, -4, -3, -3, -4, -24, -8], [8, -4, 7, 4, 4, 7, -4, 8], [6, -3, 4, 0, 0, 4, -3, 6], [6, -3, 4, 0, 0, 4, -3, 6], [8, -4, 7, 4, 4, 7, -4, 8],[-8, -24, -4, -3, -3, -4, -24, -8], [99, -8, 8, 6, 6, 8, -8, 99]]

    if board[0][0] == 'B':
        baseValue[0][1] = baseValue[1][0] = 40
    elif board[0][0] == 'W' :
        baseValue[0][1] = baseValue[1][0] = -40
    if board[0][7] == 'B':
        baseValue[0][6] = baseValue[1][7] = 40
    elif board[0][7] == 'W':
        baseValue[0][6] = baseValue[1][7] = -40
    if board[7][0] == 'B':
        baseValue[7][1] = baseValue[6][0] = 40
    elif board[7][0] == 'W' :
        baseValue[7][1] = baseValue[6][0] = -40
    if board[7][7] == 'B':
        baseValue[7][6] = baseValue[6][7] = 40
    elif board[7][7] == 'W':
        baseValue[7][6] = baseValue[6][7] = -40

    blackNum = gameplay.score(board)[0]
    whiteNum = gameplay.score(board)[1]
    if (blackNum != 0) & (whiteNum != 0):
        flipValueB = blackNum / whiteNum
        flipValueW = whiteNum / blackNum
    elif blackNum == 0:
        flipValueW = 100
    elif whiteNum == 0:
        flipValueB = 100

    for i in range(8):
        for j in range(8):
            if board[i][j] == 'B':
                evalvalue = evalvalue + baseValue[i][j] * flipValueB
            elif board[i][j] == 'W':
                evalvalue = evalvalue - baseValue[i][j] * flipValueW

    return evalvalue
Beispiel #4
0
def utility(state, color):
    answer = 0
    if gameplay.score(state)[0] == gameplay.score(state)[1]:
        answer = 0
    elif gameplay.score(state)[0] < gameplay.score(state)[1] and color == "W":
        answer = INF
    elif gameplay.score(state)[0] > gameplay.score(state)[1] and color == "B":
        answer = INF
    else:
        answer = -INF
    return answer
Beispiel #5
0
def utility(state, color):
    answer = 0
    if gameplay.score(state)[0] == gameplay.score(state)[1]:
        answer = 0
    elif gameplay.score(state)[0] < gameplay.score(state)[1] and color == "W":
        answer = INF
    elif gameplay.score(state)[0] > gameplay.score(state)[1] and color == "B":
        answer = INF
    else:
        answer = -INF
    return answer
Beispiel #6
0
def nextMove(board, color, time, reversed = False):
    global depth
    global otime
    
    moves = []
    for i in range(8):
        for j in range(8):
            if gameplay.valid(board, color, (i,j)):
                moves.append((i,j))
    if len(moves) == 0:
        return "pass"
    score = gameplay.score(board)
    num = score[0] + score[1]
    
    
    if len(moves) > 9:
        depth = 5

    if len (moves) < 7:
        depth = 6

    if time < 40 and num < ident_strategy:
        depth = 3    
    
    if depth > 6:
        depth = 6
    if num >= ident_strategy:
        d = 8*8-num
        strategy = 1
    else:
        d = depth
        strategy = 0
    best = None
    for move in moves:
        newBoard = deepcopy(board)
        gameplay.doMove(newBoard,color,move)
        moveVal = alphaBeta(newBoard, gameplay.opponent(color), reversed, d, strategy)
        if best == None or betterThan(moveVal, best, color, reversed):
            bestMove = move
            best = moveVal
    otime = time
    return bestMove
Beispiel #7
0
def nextMove(board, color, time, reversed=False):
    global depth
    global otime

    moves = []
    for i in range(8):
        for j in range(8):
            if gameplay.valid(board, color, (i, j)):
                moves.append((i, j))
    if len(moves) == 0:
        return "pass"
    score = gameplay.score(board)
    num = score[0] + score[1]

    if len(moves) > 9:
        depth = 5

    if len(moves) < 7:
        depth = 6

    if time < 40 and num < ident_strategy:
        depth = 3

    if depth > 6:
        depth = 6
    if num >= ident_strategy:
        d = 8 * 8 - num
        strategy = 1
    else:
        d = depth
        strategy = 0
    best = None
    for move in moves:
        newBoard = deepcopy(board)
        gameplay.doMove(newBoard, color, move)
        moveVal = alphaBeta(newBoard, gameplay.opponent(color), reversed, d,
                            strategy)
        if best == None or betterThan(moveVal, best, color, reversed):
            bestMove = move
            best = moveVal
    otime = time
    return bestMove
 def end_value(self):
     s = god.score(self.board)
     if (self.color == 'W') != (self.reversed):
         return s[1] - s[0]
     else:
         return s[0] - s[1]
Beispiel #9
0
def evalue(board):
    score = gameplay.score(board)
    return score[0] - score[1]
Beispiel #10
0
def evalue(board):
    score = gameplay.score(board)
    return score[0] - score[1]