PHPWarrior\Position::direction_of PHP Method

direction_of() public method

public direction_of ( $space ) : string
$space
return string
    public function direction_of($space)
    {
        list($space_x, $space_y) = $space->location();
        if (abs($this->x - $space_x) > abs($this->y - $space_y)) {
            return $space_x > $this->x ? 'east' : 'west';
        } else {
            return $space_y > $this->y ? 'south' : 'north';
        }
    }