Skip to content

Commit 10b1c3b

Browse files
committed
Added a solver method for automatically filling in gaps between known clues.
1 parent 7fa8ace commit 10b1c3b

File tree

3 files changed

+68
-9
lines changed

3 files changed

+68
-9
lines changed

FinModelUtility/Fin/Fin.Picross/src/PicrossSolver.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ private static readonly IReadOnlyList<IPicrossSolverMethod> SOLVER_METHODS_
126126
new FillSmallestUnknownsBetweenEmptiesSolverMethod(),
127127
new GapsAroundFirstClueSolverMethod(),
128128
new GapsAroundKnownCluesSolverMethod(),
129+
new GapsBetweenKnownCluesSolverMethod(),
129130
new GapsBetweenNeighboringCluesSolverMethod(),
130131
new GapsBetweenNeighboringShortCluesSolverMethod(),
131132
new MatchingBiggestOrUniqueLengthSolverMethod(),
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using fin.picross.moves;
2+
3+
namespace fin.picross.solver;
4+
5+
public class GapsBetweenKnownCluesSolverMethod : IPicrossSolverMethod {
6+
public IEnumerable<IPicrossMove1d>
7+
TryToFindMoves(IPicrossLineState lineState) {
8+
var clueStates = lineState.ClueStates;
9+
var cellStates = lineState.CellStates;
10+
var length = cellStates.Count;
11+
12+
var firstClueState = clueStates[0];
13+
if (firstClueState.Solved) {
14+
for (var i = 0; i < firstClueState.StartIndex; ++i) {
15+
if (cellStates[i].Status == PicrossCellStatus.UNKNOWN) {
16+
yield return new PicrossCellMove1d(
17+
PicrossCellMoveType.MARK_EMPTY,
18+
PicrossCellMoveSource.EMPTY_BETWEEN_CLUES,
19+
i);
20+
}
21+
}
22+
}
23+
24+
for (var clueI = 0; clueI < clueStates.Count - 1; ++clueI) {
25+
var currentClueState = clueStates[clueI];
26+
var nextClueState = clueStates[clueI + 1];
27+
28+
if (currentClueState.Solved && nextClueState.Solved) {
29+
for (var i = currentClueState.StartIndex.Value +
30+
currentClueState.Length;
31+
i < nextClueState.StartIndex;
32+
++i) {
33+
if (cellStates[i].Status == PicrossCellStatus.UNKNOWN) {
34+
yield return new PicrossCellMove1d(
35+
PicrossCellMoveType.MARK_EMPTY,
36+
PicrossCellMoveSource.EMPTY_BETWEEN_CLUES,
37+
i);
38+
}
39+
}
40+
}
41+
}
42+
43+
var lastClueState = clueStates[^1];
44+
if (lastClueState.Solved) {
45+
for (var i = lastClueState.StartIndex.Value + lastClueState.Length;
46+
i < length;
47+
++i) {
48+
if (cellStates[i].Status == PicrossCellStatus.UNKNOWN) {
49+
yield return new PicrossCellMove1d(
50+
PicrossCellMoveType.MARK_EMPTY,
51+
PicrossCellMoveSource.EMPTY_BETWEEN_CLUES,
52+
i);
53+
}
54+
}
55+
}
56+
}
57+
}

FinModelUtility/Fin/Fin.Picross/src/solver/PicrossBoardState.cs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@ public enum PicrossCompletionState {
2222
public partial interface IPicrossCellState {
2323
PicrossCellStatus Status { get; set; }
2424
PicrossCellMoveSource MoveSource { get; set; }
25-
IPicrossClue? Clue { get; set; }
25+
IPicrossClue? ColumnClue { get; set; }
26+
IPicrossClue? RowClue { get; set; }
2627
}
2728

2829
public class PicrossCellState : IPicrossCellState {
2930
public PicrossCellStatus Status { get; set; }
3031
public PicrossCellMoveSource MoveSource { get; set; }
31-
public IPicrossClue? Clue { get; set; }
32+
public IPicrossClue? ColumnClue { get; set; }
33+
public IPicrossClue? RowClue { get; set; }
3234
}
3335

3436
public class PicrossBoardState : IReadOnlyGrid<IReadOnlyPicrossCellState> {
@@ -84,16 +86,15 @@ public void ApplyMoves(IReadOnlySet<IPicrossMove> moveSet) {
8486
case PicrossClueMove picrossClueMove: {
8587
var (_, clue, startI) = picrossClueMove;
8688
for (var i = startI; i < startI + clue.Length; ++i) {
87-
int x, y;
8889
if (clue.IsForColumn) {
89-
x = clue.ColumnOrRowIndex;
90-
y = i;
90+
var x = clue.ColumnOrRowIndex;
91+
var y = i;
92+
this.cellStates_[y * width + x].ColumnClue = clue;
9193
} else {
92-
x = i;
93-
y = clue.ColumnOrRowIndex;
94+
var x = i;
95+
var y = clue.ColumnOrRowIndex;
96+
this.cellStates_[y * width + x].RowClue = clue;
9497
}
95-
96-
this.cellStates_[y * width + x].Clue = clue;
9798
}
9899

99100
break;

0 commit comments

Comments
 (0)