Thinking Functionally - Example: the complicated canSafelyEngageShip(_:friendly:) function #128
Open
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
Labels
No labels