Skip to content

Commit

Permalink
Add AllDifferent constraint to the UI.
Browse files Browse the repository at this point in the history
  • Loading branch information
sigh committed Sep 14, 2024
1 parent 71900d3 commit 9ad7bdf
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 1 deletion.
5 changes: 5 additions & 0 deletions data/collections.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,11 @@ const EXAMPLES = [
input: '.Cage~3~R1C1~R1C2.Cage~15~R1C3~R1C4~R1C5.Cage~17~R2C3~R2C4.Cage~22~R1C6~R2C5~R2C6~R3C5.Cage~4~R1C7~R2C7.Cage~16~R1C8~R2C8.Cage~15~R1C9~R2C9~R3C9~R4C9.Cage~8~R3C6~R4C6~R5C6.Cage~6~R4C1~R5C1.Cage~6~R6C3~R7C2~R7C3.Cage~27~R6C1~R7C1~R8C1~R9C1.Cage~8~R8C2~R9C2.Cage~16~R8C3~R9C3.Cage~10~R7C5~R8C4~R8C5~R9C4.Cage~12~R5C9~R6C9.Cage~6~R6C7~R6C8.Cage~20~R6C6~R7C6~R7C7.Cage~15~R8C6~R8C7.Cage~14~R7C8~R7C9~R8C8~R8C9.Cage~13~R9C5~R9C6~R9C7.Cage~17~R9C8~R9C9.Cage~0~R5C4~R5C3~R5C2~R6C2.Cage~0~R3C7~R3C8~R4C8.',
solution: '215647398368952174794381652586274931142593867973816425821739546659428713437165289',
},
{
name: 'Killer sudoku, with alldiff',
input: '.Cage~3~R1C1~R1C2.Cage~15~R1C3~R1C4~R1C5.Cage~17~R2C3~R2C4.Cage~22~R1C6~R2C5~R2C6~R3C5.Cage~4~R1C7~R2C7.Cage~16~R1C8~R2C8.Cage~15~R1C9~R2C9~R3C9~R4C9.Cage~8~R3C6~R4C6~R5C6.Cage~6~R4C1~R5C1.Cage~6~R6C3~R7C2~R7C3.Cage~27~R6C1~R7C1~R8C1~R9C1.Cage~8~R8C2~R9C2.Cage~16~R8C3~R9C3.Cage~10~R7C5~R8C4~R8C5~R9C4.Cage~12~R5C9~R6C9.Cage~6~R6C7~R6C8.Cage~20~R6C6~R7C6~R7C7.Cage~15~R8C6~R8C7.Cage~14~R7C8~R7C9~R8C8~R8C9.Cage~13~R9C5~R9C6~R9C7.Cage~17~R9C8~R9C9.AllDifferent~R5C4~R5C3~R5C2~R6C2.Cage~0~R3C7~R3C8~R4C8.',
solution: '215647398368952174794381652586274931142593867973816425821739546659428713437165289',
},
{
name: 'Killer sudoku, with 0 cage, hard',
src: 'http://forum.enjoysudoku.com/fast-web-based-solver-for-sudoku-variants-t39332.html#p312474',
Expand Down
2 changes: 1 addition & 1 deletion js/constraint_displays.js
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ ConstraintDisplays.ShadedRegion = class ShadedRegion extends BaseConstraintDispl

drawItem(constraint, options) {
const cells = constraint.cells;
const label = constraint[options.labelField];
const label = constraint[options?.labelField];

const region = this._drawRegion(cells, label, options?.pattern);

Expand Down
1 change: 1 addition & 0 deletions js/debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ const runSolveTests = async (onFailure) => {
'Killer sudoku, with overlap',
'Killer sudoku, with gaps',
'Killer sudoku, with 0 cage',
'Killer sudoku, with alldiff',
'Sudoku X',
'Anti-knight Anti-king',
'Anti-knight, Anti-consecutive',
Expand Down
5 changes: 5 additions & 0 deletions js/render_page.js
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,11 @@ ConstraintCollector.MultiCell = class MultiCell extends ConstraintCollector {
If value is must be contained at least as many times as is
repeated in the list.`,
},
AllDifferent: {
displayClass: ConstraintDisplays.ShadedRegion,
text: 'All Different',
description: `Values must be unique.`,
},
CountingCircles: {
panelText: (constraint) => `Counting Circles (${constraint.cells.length})`,
displayClass: ConstraintDisplays.CountingCircles,
Expand Down
2 changes: 2 additions & 0 deletions js/sudoku_builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -1131,6 +1131,8 @@ class SudokuConstraint {
}

static AllDifferent = class AllDifferent extends SudokuConstraintBase {
static COLLECTOR_CLASS = 'MultiCell';

constructor(...cells) {
super(arguments);
this.cells = cells;
Expand Down

0 comments on commit 9ad7bdf

Please sign in to comment.