MapLocation 类

MapLocation 类定义了地图上位置的基本概念,并提供了一系列操作方法。通过这些方法可以实现位置的平移、方向判断与距离计算等功能。

构造方法:core.api.MapLocation(x: int, y: int)

方法

def add(self, dir: Direction) -> MapLocation

返回当前位置按照给定方向移动一格后的新位置。
参数:

返回:

def direction_to(self, loc: MapLocation) -> Direction

计算从当前点指向目标点的粗略方向。
参数:

返回:

def distance_to(self, loc: MapLocation) -> int

计算当前位置与目标位置之间的平方距离,适用于无需精确欧几里得距离时的比较。
参数:

返回:

def is_adjacent_to(self, loc: MapLocation) -> bool

判断目标位置是否与当前位置相邻(包括对角线相邻)。
参数:

返回:

def subtract(self, dir: Direction) -> MapLocation

返回当前位置按照给定方向的反方向移动一格后的新位置。
参数:

返回:

def translate(self, dx: int, dy: int) -> MapLocation

返回当前位置经过横向偏移 dx 和纵向偏移 dy 后的新位置。
参数:

返回:

def equals(self, loc: MapLocation) -> bool

判断目标位置与当前位置是否完全相同(坐标相同)。也可以直接使用 == 运算符。 参数:

返回: