Skip to content

Commit

Permalink
Final spatial index improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
ForNeVeR committed Jul 9, 2023
1 parent b2befcd commit e0b598c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Icfpc2023.Tests/Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ let ``Scoring yields the expected score for the sample problem from the spec`` (
PointD(1_100.0, 100.0)
PointD(1_100.0, 150.0)
|]
Volumes = [||]
Volumes = [|1.0; 1.0; 1.0|]
}

Assert.Equal(5343.0, Scoring.CalculateScore problem solution)
Expand Down
32 changes: 15 additions & 17 deletions Icfpc2023/Scoring.fs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type private Musician = {
}

type SectoredIndex(problem: Problem) =
let sectorSize = 50.0
let sectorSize = 100.0
let sectors =
let w = int <| ceil(problem.StageWidth / sectorSize)
let h = int <| ceil(problem.StageHeight / sectorSize)
Expand All @@ -28,22 +28,22 @@ type SectoredIndex(problem: Problem) =
seq {
for x in 0..w - 1 do
for y in 0..h - 1 do
let square = {
BottomLeft = PointD(float x * sectorSize, float y * sectorSize)
Width = sectorSize
Height = sectorSize
}
if stadium'.RectangularPartIntersectsWith square then
yield struct(x, y)
if sectors[x, y].Count > 0 then
let square = {
BottomLeft = PointD(float x * sectorSize, float y * sectorSize)
Width = sectorSize
Height = sectorSize
}
if stadium'.RectangularPartIntersectsWith square then
yield struct(x, y)
}

member _.Add(point: PointD): unit =
let sector = sectors[int ((point.X - problem.StageBottomLeft.X) / sectorSize), int ((point.Y- problem.StageBottomLeft.Y) / sectorSize)]
sector.Add point

member _.GetPointsIn(s: Stadium): PointD seq =
let squares = getSectorSquares s |> Seq.toArray

let squares = getSectorSquares s
squares
|> Seq.collect(fun (struct(x, y)) -> sectors[x, y])
|> Seq.filter(s.Contains)
Expand All @@ -58,14 +58,12 @@ let private AnyOtherMusicianBlocksSound(index: SectoredIndex,
let musician = musician.Location
let attendee = PointD(attendee.X, attendee.Y)
let blockZone = { Center1 = musician; Center2 = attendee; Radius = 5.0 }
let candidates = index.GetPointsIn blockZone |> Seq.toArray // TODO REMOVE TOARRAY

let blocking =
candidates
|> Seq.filter(fun p -> p <> musician)
|> Seq.toArray
let candidates = index.GetPointsIn blockZone

blocking.Length > 0
candidates
|> Seq.filter(fun p -> p <> musician)
|> Seq.tryHead
|> Option.isSome

let private AnyPillarBlocksSound (pillars: Pillar[]) (musician: Musician) (attendee: Attendee): bool =
let musician = PointD(musician.Location.X, musician.Location.Y)
Expand Down

0 comments on commit e0b598c

Please sign in to comment.