- for island in islands do
- let mutable stop = island.Shore.IsEmpty
-
- // 'true' if 'p' is owned or adjacent to 'island'.
- let ownedOrAdjacent (p: Point) : bool =
- ownership.[p.Y, p.X] = island ||
- (p.Y > 0 && ownership.[p.Y - 1, p.X] = island) ||
- (p.Y < h - 1 && ownership.[p.Y + 1, p.X] = island) ||
- (p.X > 0 && ownership.[p.Y, p.X - 1] = island) ||
- (p.X < w - 1 && ownership.[p.Y, p.X + 1] = island)
-
- while not stop && island.Surface < area do
- let level, next = island.Shore.Max
- let other = ownership.[next.Y, next.X]
- if other = island // During merging, some points on the shore may be owned by the island itself -> ignored.
- then
- island.Shore.RemoveNext ()
- else
- if other <> null
- then // We touching another island.
- if island.Surface + other.Surface >= area
- then
- stop <- true
- else // We can merge 'other' into 'surface'.
- island.Surface <- island.Surface + other.Surface
- island.Level <- if comparer.Compare(island.Level, other.Level) > 0 then island.Level else other.Level
- for l, p in other.Shore do
- let mutable currentY = p.Y + 1
- while currentY < h && ownership.[currentY, p.X] = other do
- ownership.[currentY, p.X] <- island
- currentY <- currentY + 1
- island.Shore.Add l p
- other.Shore.Clear()
-
- elif comparer.Compare(level, island.Level) > 0
+ for area, obj in areas do
+ for island in islands do
+ let mutable stop = island.Shore.IsEmpty
+
+ // 'true' if 'p' is owned or adjacent to 'island'.
+ let inline ownedOrAdjacent (p: Point) : bool =
+ ownership.[p.Y, p.X] = island ||
+ (p.Y > 0 && ownership.[p.Y - 1, p.X] = island) ||
+ (p.Y < h - 1 && ownership.[p.Y + 1, p.X] = island) ||
+ (p.X > 0 && ownership.[p.Y, p.X - 1] = island) ||
+ (p.X < w - 1 && ownership.[p.Y, p.X + 1] = island)
+
+ while not stop && island.Surface < area do
+ let level, next = island.Shore.Max
+ let other = ownership.[next.Y, next.X]
+ if other = island // During merging, some points on the shore may be owned by the island itself -> ignored.