def getAllPossibleMovesAtPosition(board, x, y): # Returns a tuple # 1) list of all possible moves of the piece board[x][y] # 2) True/False, whether the moves are capture moves or not moves = [] isCapture = False # Look for jumps l = getAllJumpMovesAtPosition(board, x, y) for m in l: moves.append(m) if len(moves) == 0: # No jump moves available # Look for plain moves serial = gridToSerial(x,y) if gamePlay.canMoveToPosition(board, x, y, x-1, y-1): moves.append([serial,gridToSerial(x-1,y-1)]) if gamePlay.canMoveToPosition(board, x, y, x-1, y+1): moves.append([serial,gridToSerial(x-1,y+1)]) if gamePlay.canMoveToPosition(board, x, y, x+1, y-1): moves.append([serial,gridToSerial(x+1,y-1)]) if gamePlay.canMoveToPosition(board, x, y, x+1, y+1): moves.append([serial,gridToSerial(x+1,y+1)]) else: isCapture = True return moves, isCapture
def getAllPossibleMovesAtPosition(board, x, y): # Returns a tuple # 1) list of all possible moves of the piece board[x][y] # 2) True/False, whether the moves are capture moves or not moves = [] isCapture = False # Look for jumps l = getAllJumpMovesAtPosition(board, x, y) for m in l: moves.append(m) if len(moves) == 0: # No jump moves available # Look for plain moves serial = gridToSerial(x, y) if gamePlay.canMoveToPosition(board, x, y, x - 1, y - 1): moves.append([serial, gridToSerial(x - 1, y - 1)]) if gamePlay.canMoveToPosition(board, x, y, x - 1, y + 1): moves.append([serial, gridToSerial(x - 1, y + 1)]) if gamePlay.canMoveToPosition(board, x, y, x + 1, y - 1): moves.append([serial, gridToSerial(x + 1, y - 1)]) if gamePlay.canMoveToPosition(board, x, y, x + 1, y + 1): moves.append([serial, gridToSerial(x + 1, y + 1)]) else: isCapture = True return moves, isCapture
def evaluation3(board, color): opColor = gamePlay.getOpponentColor(color) value = 0 # Loop through all board positions for piece in range(1, 33): # Check if I can capture two # Check whether a jump possible to all four directions xy = gamePlay.serialToGrid(piece) x = xy[0] y = xy[1] if gamePlay.canMoveToPosition(board, x, y, x-2, y-2) == True: if gamePlay.isCapturePossibleFromPosition(board, x-2, y-2): if board[x][y].upper() == color.upper(): value = value + 1 elif board[x][y].upper() == opColor.upper(): value = value - 1 if gamePlay.canMoveToPosition(board, x, y, x-2, y+2) == True: if gamePlay.isCapturePossibleFromPosition(board, x-2, y+2): if board[x][y].upper() == color.upper(): value = value + 1 elif board[x][y].upper() == opColor.upper(): value = value - 1 if gamePlay.canMoveToPosition(board, x, y, x+2, y-2) == True: if gamePlay.isCapturePossibleFromPosition(board, x+2, y-2): if board[x][y].upper() == color.upper(): value = value + 1 elif board[x][y].upper() == opColor.upper(): value = value - 1 if gamePlay.canMoveToPosition(board, x, y, x+2, y+2) == True: if gamePlay.isCapturePossibleFromPosition(board, x+2, y+2): if board[x][y].upper() == color.upper(): value = value + 1 elif board[x][y].upper() == opColor.upper(): value = value - 1 # Lets give weightage 10 # Let us give extra weightage 10 return value
def getAllJumpMovesAtPosition(board, x, y): # Get all jump moves of position board(x,y) moves = [] serial = gridToSerial(x, y) for i in [-2,2]: for j in [-2,2]: # Check all four directions if gamePlay.canMoveToPosition(board, x, y, x+i, y+j): tempBoard = deepcopy(board) gamePlay.doMovePosition(tempBoard, x, y, x+i, y+j) childJumpMoves = getAllJumpMovesAtPosition(tempBoard, x+i, y+j) if len(childJumpMoves) == 0: moves.append([serial, gridToSerial(x+i, y+j)]) else: for m in childJumpMoves: l = [serial] l.extend(m) moves.append(l) return moves
def getAllJumpMovesAtPosition(board, x, y): # Get all jump moves of position board(x,y) moves = [] serial = gridToSerial(x, y) for i in [-2, 2]: for j in [-2, 2]: # Check all four directions if gamePlay.canMoveToPosition(board, x, y, x + i, y + j): tempBoard = deepcopy(board) gamePlay.doMovePosition(tempBoard, x, y, x + i, y + j) childJumpMoves = getAllJumpMovesAtPosition( tempBoard, x + i, y + j) if len(childJumpMoves) == 0: moves.append([serial, gridToSerial(x + i, y + j)]) else: for m in childJumpMoves: l = [serial] l.extend(m) moves.append(l) return moves