Skip to content

Thinking Functionally - Example: the complicated canSafelyEngageShip(_:friendly:) function #128

Open
@Ribbonlan

Description

extension Ship {
func canSafelyEngageShip(target: Ship, friendly: Ship) -> Bool {
let rangeRegion = difference(circle(firingRange),
minus: circle(unsafeRange))
let firingRegion = shift(rangeRegion, offset: position)
let friendlyRegion = shift(circle(unsafeRange),
offset: friendly.position)
let resultRegion = difference(firingRegion, minus: friendlyRegion)
return resultRegion(target.position)
}
}

This line: let friendlyRegion = shift(circle(unsafeRange), offset: friendly.position)
should be: let friendlyRegion = shift(circle(friendly.unsafeRange), offset: friendly.position)
friendlyRegion should be represented the friendly ship's unsafe region

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions