示例#1
0
 def getCovers(self, board, covers):
     count = 0
     for p in covers:
         for m in covers:
             tp = board.board[m.x][m.y]
             count += getValue(tp)
     return count
示例#2
0
 def doAtt(self, maxPr, moves,
           cov):  # Chooses which piece to use to take enemy piece
     mFinal = (maxPr[0].x, maxPr[0].y)
     score = (None, -9999)
     pieces = []
     for p in moves:  #Find out who can attack this piece
         for m in moves[p]:
             if m == mFinal:
                 pieces.append(p)
     for p in pieces:
         sc = getValue(maxPr[0])  # Initialize on piece value
         sc -= getValue(p)  # Prefer using pieces with low value
         sc -= len(cov.get(
             p, []))  # Prefer using pieces that do not defend others
         if sc > score[1]:
             score = (p, sc)
     res = (score[0], mFinal, score[1] + 10
            )  # Add value to show the benefit of a good offense!
     # print("Best offensive move: "+str(res))
     return res
示例#3
0
 def getThreats(self, board):
     opMoves, _ = board.get_moves(
         (self.pl + 1) % 2)  # Get potential moves by opponent
     count = 0
     for p in opMoves:
         for m in opMoves[p]:
             if board.board[m[0]][m[1]] != None and board.board[m[0]][m[
                     1]].pl == self.pl:  # If enemy piece can move to take friendly piece
                 tp = board.board[m[0]][m[1]]
                 count += getValue(tp)
     return count
示例#4
0
	def get_threats(self, player, board, op_moves, pl_covers):
		count = 0
		score = 0
		for p in op_moves:
			for m in op_moves[p]:
				piece = board.board[m[0]][m[1]]
				if piece is not None and piece.pl == player:
					# If enemy piece can move to take friendly piece
					count += 1  # Without piece values
					add_score = 1 if piece in pl_covers else 0  # If it protects some piece, give it additional value
					score += getValue(piece) + add_score
		return count, score
示例#5
0
 def getPriority(self, piece, board=None):
     if board == None:
         board = self.board
     threats = 0  # Count threats to this piece
     covers = 0  # Count how many friendlies protect this piece
     _, cov = board.get_moves(piece.pl)
     opMoves, _ = board.get_moves((piece.pl + 1) % 2)
     for p in opMoves:
         for m in opMoves[p]:
             if m[0] == piece.x and m[
                     1] == piece.y:  # If enemy piece threatens this piece
                 threats += 1
     for p in cov:
         for cp in cov[p]:
             if cp == piece:  # If friendly piece covers this piece
                 covers += 1
     return (threats - covers) * getValue(
         piece)  # returns threat level weighed by piece value