예제 #1
0
 def quiescence1(self, player, state, alpha, beta, depth):
     best = self.evolution(state, player) * player
     if(best >= beta):
         return best
     if(self.b.playercolor == "white"):
         if(player > 0):
             pawn_move = -1
         else:
             pawn_move = 1
     else:
         if(player < 0):
             pawn_move = 1                        
         else:
             pawn_move = -1
     for i in range(8):
         for j in range(8):
             if(state[i][j] * player > 0):
                 f = PieceMap.getCaptureFun(state[i][j])
                 moves = []
                 if(abs(state[i][j]) == 6):
                     moves = f([i,j],state,pawn_move)
                 elif(abs(state[i][j] != 0)):
                     moves = f([i,j],state)
                 if(depth <= 0 and len(moves) <= 0):
                     continue
                 for move in moves:
                     t = state[move[0]][move[1]]
                     state[move[0]][move[1]] = state[i][j]
                     temp = -self.quiescence1(-player, [[x for x in y] for y in state], -beta, max(alpha, best), depth-1)
                     state[move[0]][move[1]] = t
                     best = max(temp, best)
                     if(best >= beta):
                         return best
     return best
예제 #2
0
 def capture_successor(self, colour, board): 
     allmoves = []
     if(self.playercolor == "white"):
         if(colour > 0):
             pawn_move = -1
         else:
             pawn_move = 1
     else:
         if(colour < 0):
             pawn_move = 1                        
         else:
             pawn_move = -1
             
     if(colour > 0): 
         for i in range(8):
             for j in range(8):
                 if(board[i][j] > 0):
                     start = board[i][j]
                     #f = PieceMap.getFun(board[i][j])
                     f = PieceMap.getCaptureFun(board[i][j])
                     if(abs(board[i][j]) == 6):
                         moves = f([i,j],board,pawn_move)
                     else:
                         moves = f([i,j],board)
                     '''
                     if(len(moves) <= 0):
                         f = PieceMap.getFun(board[i][j])
                         if(abs(board[i][j]) == 6):
                             moves = f([i,j],board,pawn_move)
                         else:
                             moves = f([i,j],board)
                     '''        
                     for move in moves:
                         end = board[move[0]][move[1]]
                         board[i][j] = 0
                         board[move[0]][move[1]] = start
                         if(not self.ischeck(board, colour)):
                             allmoves.append([[_i for _i in _j] for _j in board])
                         board[i][j] = start
                         board[move[0]][move[1]] = end
     elif(colour < 0):
         for i in range(8):
             for j in range(8):
                 if(board[i][j] < 0):
                     start = board[i][j]
                     f = PieceMap.getFun(board[i][j])
                     #f = PieceMap.getCaptureFun(board[i][j])
                     if(abs(board[i][j]) == 6):
                         moves = f([i,j],board,pawn_move)
                     else:
                         moves = f([i,j],board)
                     '''
                     if(len(moves) <= 0):
                         f = PieceMap.getFun(board[i][j])
                         if(abs(board[i][j]) == 6):
                             moves = f([i,j],board,pawn_move)
                         else:
                             moves = f([i,j],board) 
                     '''
                     for move in moves:
                         end = board[move[0]][move[1]]
                         board[i][j] = 0
                         board[move[0]][move[1]] = start
                         if(not self.ischeck(board, colour)):
                             allmoves.append([[_i for _i in _j] for _j in board])
                         board[i][j] = start
                         board[move[0]][move[1]] = end
                         
     return allmoves