Skip to content

Commit

Permalink
Visualizator: add additional info
Browse files Browse the repository at this point in the history
  • Loading branch information
gsomix committed Jul 8, 2023
1 parent 6469f14 commit aa7a1d3
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 16 deletions.
3 changes: 2 additions & 1 deletion Icfpc2023.Visualizer/ViewModels/FieldViewModel.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

open Icfpc2023

type FieldViewModel(problemId: int, problem: Problem, solution: Solution) =
type FieldViewModel(problemId: int, problem: Problem, solution: Solution, score: double) =
member val ProblemId = problemId
member val Problem = problem
member val Solution = solution
member val Score = score

member val Scale = 0.1 with get, set
15 changes: 10 additions & 5 deletions Icfpc2023.Visualizer/ViewModels/MainWindowViewModel.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,35 @@ type MainWindowViewModel() =
static member LoadProblem(problemId: int): FieldViewModel =
let problem = Program.readProblem problemId
let solution = Program.readSolution problemId
FieldViewModel(problemId, problem, solution)
let score = Program.readScoreOrCompute problemId problem
FieldViewModel(problemId, problem, solution, score)

member val Field =
MainWindowViewModel.LoadProblem(1)
with get, set

member this.CurrentProblemId = string this.Field.ProblemId
member this.ProblemId = string this.Field.ProblemId

member this.MusiciansCount = string this.Field.Problem.Musicians.Length

member this.Score = string this.Field.Score

member private this.LoadProblemById(problemId: int) =
this.Field <- MainWindowViewModel.LoadProblem(problemId)
this.RaisePropertyChanged(nameof this.CurrentProblemId)
this.RaisePropertyChanged(nameof this.ProblemId)
this.RaisePropertyChanged(nameof this.Field)

member this.LoadPrev(): unit =
try
let oldProblem = this.CurrentProblemId |> int
let oldProblem = this.ProblemId |> int
let newProblem = oldProblem - 1
this.LoadProblemById newProblem
with
| ex -> eprintfn $"Error: {ex.Message}"

member this.LoadNext(): unit =
try
let oldProblem = this.CurrentProblemId |> int
let oldProblem = this.ProblemId |> int
let newProblem = oldProblem + 1
this.LoadProblemById newProblem
with
Expand Down
15 changes: 14 additions & 1 deletion Icfpc2023.Visualizer/Views/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,20 @@

<Grid RowDefinitions="Auto,*">
<StackPanel Orientation="Horizontal">
<Label Content="{Binding CurrentProblemId}"/>
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal">
<Label Content="Problem Id:"/>
<Label Content="{Binding ProblemId}"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<Label Content="Musicians count:"/>
<Label Content="{Binding MusiciansCount}"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<Label Content="Score:"/>
<Label Content="{Binding Score}"/>
</StackPanel>
</StackPanel>
<Button Content="← Prev" Command="{Binding LoadPrev}" />
<Button Content="Next →" Command="{Binding LoadNext}" />
</StackPanel>
Expand Down
18 changes: 9 additions & 9 deletions Icfpc2023/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ let solvers = Map [
"dummy", DummySolver.Solve
]

let writeSolutionScore i score =
let writeScore i score =
let solutionScoreFile = Path.Combine(solutionsDir, $"{i}.score.json")
let solutionScoreText = JsonDefs.WriteSolutionScoreToJson score
File.WriteAllText(solutionScoreFile, solutionScoreText)
Expand All @@ -51,18 +51,18 @@ let writeSolution i solution score =
let solutionText = JsonDefs.WriteSolutionToJson solution
File.WriteAllText(solutionFile, solutionText)

writeSolutionScore i score
writeScore i score

let getExistingScore i problem =
let readScoreOrCompute i problem =
let solutionScoreFile = Path.Combine(solutionsDir, $"{i}.score.json")
try
JsonDefs.ReadSolutionScoreFromFile solutionScoreFile
with
| :? System.IO.FileNotFoundException ->
let oldSolution = readSolution i
let score = Scoring.CalculateScore problem oldSolution
writeSolutionScore i score
score
| :? FileNotFoundException ->
let oldSolution = readSolution i
let score = Scoring.CalculateScore problem oldSolution
writeScore i score
score

[<EntryPoint>]
let main(args: string[]): int =
Expand Down Expand Up @@ -100,7 +100,7 @@ let main(args: string[]): int =
let problem = readProblem num

let oldSolution = readSolution num
let oldScore = getExistingScore num problem
let oldScore = readScoreOrCompute num problem

let solver = solvers[solverStr]
let newSolution = solver problem
Expand Down

0 comments on commit aa7a1d3

Please sign in to comment.