-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
LE COURTOIS Sylvain
committed
Aug 14, 2023
1 parent
5a0d965
commit 21c4fbb
Showing
6 changed files
with
85 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
@page "/SudokuView/{PuzzleNumber:int}" | ||
@inject PuzzleHelper puzzleHelper; | ||
@inject HttpClient Http | ||
|
||
<p> | ||
This is a Sudoku solver, and it has really no relation with Advent Of Code ! | ||
</p> | ||
|
||
<svg viewBox="-0.2 -0.2 9.2 9.8" class="img-fluid"> | ||
<defs> | ||
<g id="sudoku-cell"> | ||
<rect x=".1" y=".1" width=".8" height=".8" fill="orange"></rect> | ||
</g> | ||
<g id="sudoku-bad-cell"> | ||
<rect x=".1" y=".1" width=".8" height=".8" fill="red"></rect> | ||
</g> | ||
<pattern id="gridPattern" width="1" height="1" patternUnits="userSpaceOnUse"> | ||
<rect width="1" height="1" fill="white" stroke="black" stroke-width="0.025" /> | ||
</pattern> | ||
<pattern id="gridPattern2" width="3" height="3" patternUnits="userSpaceOnUse"> | ||
<rect width="3" height="3" fill="url(#gridPattern)" stroke="black" stroke-width="0.05" /> | ||
</pattern> | ||
</defs> | ||
<rect x="0" y="0" width="9.0" height="9.0" fill="url(#gridPattern2)"></rect> | ||
@{ | ||
if ( _solver != null && _solver.PuzzleState.Length == 81) | ||
{ | ||
var s = _solver.PuzzleState; | ||
foreach (var y in Enumerable.Range(0, 9)) | ||
foreach (var x in Enumerable.Range(0, 9)) | ||
{ | ||
var c = s[x + y * 9]; | ||
if (c == '.') | ||
{ | ||
c = ' '; | ||
var r = _solver.Entropy(x + y * 9).Length; | ||
if ( r == 0) | ||
{ | ||
<use href="#sudoku-bad-cell" x="@x" y="@y" /> | ||
} | ||
else | ||
{ | ||
var e = (double)(10 - r) / 9; | ||
<use href="#sudoku-cell" x="@x" y="@y" opacity="@(e.ToStringCSS())" /> | ||
<g transform="translate(.75,.76)"> | ||
<text x="@x" y="@y" font-family="Comic Sans" font-size=".3" dominant-baseline="middle" text-anchor="middle">@r</text> | ||
</g> | ||
} | ||
} | ||
<g> | ||
<g transform="translate(.5,.56)"> | ||
<text x="@x" y="@y" font-family="Comic Sans" font-size=".8" dominant-baseline="middle" text-anchor="middle">@c</text> | ||
</g> | ||
</g> | ||
} | ||
} | ||
} | ||
</svg> | ||
|
||
<PuzzleInput PuzzleSolver="_solver" PuzzleNumber="@PuzzleNumber" Changed="@UpdateView" Input="@_input" /> | ||
|
||
@code { | ||
[Parameter] | ||
public int PuzzleNumber { get; set; } | ||
private string? _input { get; set; } | ||
private Sudoku? _solver; | ||
public void UpdateView(int animationDuration) => StateHasChanged(); | ||
|
||
protected override async Task OnInitializedAsync() | ||
{ | ||
var puzzle = puzzleHelper.Puzzles[PuzzleNumber]; | ||
_solver = new Sudoku(); | ||
_input = (await Http.GetStringAsync($"sample-data/{puzzle.Type.Name}.txt")).Replace("\r", ""); | ||
_solver.Setup(_input); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters