-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLessons.ts
273 lines (267 loc) · 14.1 KB
/
Lessons.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
import { sudokuStrategy } from "sudokuru";
export interface lessonOfflineMode {
mode: getLessonMode.Offline;
}
export interface lessonOnlineMode {
mode: getLessonMode.Online;
}
export enum getLessonMode {
Offline,
Online,
}
/**
* Functions to handle requesting lessons
*/
export class Lessons {
/**
* Returns a list of all the strategies that have lessons
* @returns string array of strategy names that getSteps can be called with
*/
public static async getStrategies(
args: lessonOfflineMode | lessonOnlineMode
): Promise<string[]> {
if (args.mode === getLessonMode.Online) {
const response: Response = await fetch(
"https://sudokuru.s3.amazonaws.com/Lessons/strategies.json",
{ cache: "no-cache" }
);
const json = await response.json();
return json;
} else {
return [
"SUDOKU_101",
"AMEND_NOTES",
"NAKED_SINGLE",
"SIMPLIFY_NOTES",
"NAKED_SET",
"HIDDEN_SINGLE",
"HIDDEN_SET",
"POINTING_SET",
];
}
}
/**
* Given a strategy string (from getStrategies()) returns a 2d string array of steps for the strategy
* @param strategy - name of the strategy
* @returns 2d string array of steps with first value in each array being text and second being link to s3 image
*/
public static async getSteps(
strategy: string,
args: lessonOfflineMode | lessonOnlineMode
): Promise<string[][]> {
if (args.mode === getLessonMode.Online) {
const response: Response = await fetch(
"https://sudokuru.s3.amazonaws.com/Lessons/" + strategy + ".json",
{ cache: "no-cache" }
);
const json = await response.json();
return json;
} else {
if (strategy === "SUDOKU_101") {
return [
[
"Welcome to Sudokuru! As your Sudoku Guru I will teach you how to solve Sudoku puzzles. Shown above is a Sudoku puzzle. All Sudoku puzzles are made of 81 cells in a 9x9 grid.",
require("../LocalStore/Lessons/SUDOKU_101_STEP_1.png"),
],
[
"Each puzzle can be divided into 9 horizontal rows. Every row needs to have the numbers 1 through 9 exactly once. For example, the 2nd row is highlighted in the puzzle above and is only missing 3, 6, and 7 which will go in the remaining three cells.",
require("../LocalStore/Lessons/SUDOKU_101_STEP_2.png"),
],
[
"Each puzzle can be divided into 9 vertical columns. Every column needs to have the numbers 1 through 9 exactly once. For example, the 1st column is highlighted in the puzzle above and needs 1, 3, and 5-9 still.",
require("../LocalStore/Lessons/SUDOKU_101_STEP_3.png"),
],
[
"Each puzzle can be divided into 9 3x3 boxes as denoted by the bolder grid lines. Every box needs to have the numbers 1 through 9 exactly once. The 4th box (counting left to right, top to bottom) is highlighted above and still needs 1, 2-5, and 7-9.",
require("../LocalStore/Lessons/SUDOKU_101_STEP_4.png"),
],
[
"By making sure each row, column, and box has all nine numbers you can deduce the one valid solution to the puzzle.",
require("../LocalStore/Lessons/SUDOKU_101_STEP_5.png"),
],
];
} else if (strategy === "AMEND_NOTES") {
return [
[
"Notes are the list of remaining possibilities for a cell. To solve a puzzle we will start by filling in notes for each cell for each value that doesn't conflict with an already placed value.",
require("../LocalStore/Lessons/AMEND_NOTES_STEP_1.png"),
],
[
"We will start by adding notes to the cell in the top left. We will add every number between 1 and 9 that hasn't already been placed in the cell's row, column or box.",
require("../LocalStore/Lessons/AMEND_NOTES_STEP_2.png"),
],
[
"The small black numbers in the cell are the numbers that should be added as notes. The small red numbers are the numbers that shouldn't be added because they are already in the row, column, or box as shown in the gold highlighted cells.",
require("../LocalStore/Lessons/AMEND_NOTES_STEP_3.png"),
],
[
"We've now finished entering all of the valid notes to the top left cell.",
require("../LocalStore/Lessons/AMEND_NOTES_STEP_4.png"),
],
[
"You have now learned how to amend notes! If you ever make a mistake in a cell you can always erase the notes from it and amend again.",
require("../LocalStore/Lessons/AMEND_NOTES_STEP_4.png"),
],
];
} else if (strategy === "NAKED_SINGLE") {
return [
[
"To solve a Sudoku puzzle you have to correctly fill in all of the empty cells. You can do this by utilizing the naked single strategy. To use the naked single strategy you first have to find a cell with only one note left.",
require("../LocalStore/Lessons/NAKED_SINGLE_STEP_1.png"),
],
[
"The highlighted cell in the top middle of the above puzzle is an example of a naked single. Since it only has an 8 left as a note you can fill the cell in with the value 8.",
require("../LocalStore/Lessons/NAKED_SINGLE_STEP_2.png"),
],
[
"You have now learned how to use the naked single strategy to solve Sudoku puzzles!",
require("../LocalStore/Lessons/NAKED_SINGLE_STEP_3.png"),
],
];
} else if (strategy === "SIMPLIFY_NOTES") {
return [
[
"Using a placed value, simplify notes lets you to eliminate it from the notes of any cell that shares a row, column, and/or box with the placed value cell.",
require("../LocalStore/Lessons/NAKED_SINGLE_STEP_4.png"),
],
[
"You can remove the red 8 as a note from the cell directly to the left of the highlighted placed 8 because they share a row (and box).",
require("../LocalStore/Lessons/NAKED_SINGLE_STEP_5.png"),
],
[
"You have now learned how to use the simplify notes strategy to solve Sudoku puzzles! Part of what makes simplify notes so effective is that they can have a domino effect. For instance, the cell we just removed an 8 from is now a naked single.",
require("../LocalStore/Lessons/NAKED_SINGLE_STEP_7.png"),
],
];
} else if (strategy === "NAKED_SET") {
return [
[
"If you recall from a previous lesson naked singles are cells with only one possible value, which must be placed there, resulting in its removal from notes of cells sharing the same group.",
require("../LocalStore/Lessons/NAKED_SET_STEP_1.png"),
],
[
"This rule can be extended to naked pairs, triplets, and quadruplets, where x cells have only x remaining combined possibilities, allowing for removal of these possibilities from the notes of cells in shared groups.",
require("../LocalStore/Lessons/NAKED_SET_STEP_1.png"),
],
[
"Above we highlighted in gold a naked pair made up of the numbers 2 and 9. They form a naked pair because they are two cells that can only be filled with a combined two shared numbers.",
require("../LocalStore/Lessons/NAKED_SET_STEP_2.png"),
],
[
"Therefore, one of them will eventually be filled with a 2 while the other will be filled with a 9. This lets you remove both 2 and a 9 from every cell in the column and box the cells share.",
require("../LocalStore/Lessons/NAKED_SET_STEP_2.png"),
],
[
"We've now finished removing all of the notes from applying the naked pair.",
require("../LocalStore/Lessons/NAKED_SET_STEP_3.png"),
],
[
"You've now learned how to use the naked set strategies! While you can't directly place values with naked sets other than singles you can remove lots of notes which lead to placing values like in the case of the 6 naked single revealed in the leftmost column by the naked pair we just applied.",
require("../LocalStore/Lessons/NAKED_SET_STEP_4.png"),
],
];
} else if (strategy === "HIDDEN_SINGLE") {
return [
[
"Hidden singles are when a single note is only left in a single cell in a row, column, or box. When you find a hidden single you can remove all of the notes other than the hidden single itself from the cell.",
require("../LocalStore/Lessons/HIDDEN_SINGLE_STEP_1.png"),
],
[
"In the highlighted column above the number 9 is absent from all of the gold highlighted cells appearing only in one cell. Since only one cell in the column has a nine left you can remove all of the other notes from it as shown highlighted red.",
require("../LocalStore/Lessons/HIDDEN_SINGLE_STEP_2.png"),
],
[
"We've now finished removing all of the excess notes from the hidden single cell.",
require("../LocalStore/Lessons/HIDDEN_SINGLE_STEP_3.png"),
],
[
"You've now learned how to use the hidden single strategy! Hidden singles are particularly useful because they always result in naked singles which can be used to place the value.",
require("../LocalStore/Lessons/HIDDEN_SINGLE_STEP_4.png"),
],
];
} else if (strategy === "HIDDEN_SET") {
return [
[
"If you recall from a previous lesson hidden singles are based on the fact that if a row, column, or box only has a single location to place a value than it must be placed there. This idea can be generalized to any set size.",
require("../LocalStore/Lessons/HIDDEN_SET_STEP_1.png"),
],
[
"For instance, you can have hidden pairs, triplets, and quadruplets. All hidden sets rely on there only being x places that x values can be placed in a given row, column, or box leading to each of them having to be placed in one of them eventually. This results in all other notes being removed from them.",
require("../LocalStore/Lessons/HIDDEN_SET_STEP_1.png"),
],
[
"Above we have highlighted a hidden triplet made up of 1, 5, and 9. They are a hidden triplet because they are three cells containing a combined three numbers that are absent from every other cell in their shared column (other cells are highlighted in gold).",
require("../LocalStore/Lessons/HIDDEN_SET_STEP_2.png"),
],
[
"Therefore, each of them will eventually be filled with one of those three numbers. This lets you remove every other number from their notes as highlighted in red.",
require("../LocalStore/Lessons/HIDDEN_SET_STEP_2.png"),
],
[
"We've now finished removing all of the notes from applying the hidden triplet.",
require("../LocalStore/Lessons/HIDDEN_SET_STEP_3.png"),
],
[
"You've now learned how to use the hidden set strategies! While you can't directly place values with hidden sets you can remove lots of notes which lead to placing values like in the case of the 1 naked single revealed in the column by the hidden triplet we just applied.",
require("../LocalStore/Lessons/HIDDEN_SET_STEP_4.png"),
],
];
} else if (strategy === "POINTING_SET") {
return [
[
"Pointing sets are when all cells containing a specific note in a box share the same row or column. When you find a pointing set you can remove the note from every cell in the shared row or column except those in the box itself.",
require("../LocalStore/Lessons/POINTING_SET_1.png"),
],
[
"The cells highlighted in gold in the above puzzle form a pointing pair since they are the only cells in the highlighted box containing the note 4 and they share a column.",
require("../LocalStore/Lessons/POINTING_SET_2.png"),
],
[
"Since you know one of the gold cells will eventually have a 4 placed in it you can remove the 4 from the notes of the other cells in the column as highlighted in red.",
require("../LocalStore/Lessons/POINTING_SET_3.png"),
],
[
"You've now learned how to use the pointing pair strategy!",
require("../LocalStore/Lessons/POINTING_SET_4.png"),
],
[
"There are also pointing triplets like the one highlighted in gold which contain the only 8's in the box letting you remove all other 8's from the shared row.",
require("../LocalStore/Lessons/POINTING_SET_5.png"),
],
[
"You've now learned how to use pointing sets!",
require("../LocalStore/Lessons/POINTING_SET_6.png"),
],
];
}
}
}
/**
* Returns a tutorial to teach new users the basics of Sudoku via the first few lessons
* @returns 2d string array of steps from the first few lessons with first value in each array being text and second being link to s3 image
*/
public static async getTutorial(): Promise<string[][]> {
const sudoku_101: Response = await fetch(
"https://sudokuru.s3.amazonaws.com/Lessons/SUDOKU_101.json",
{ cache: "no-cache" }
);
const lesson1 = await sudoku_101.json();
const amend_notes: Response = await fetch(
"https://sudokuru.s3.amazonaws.com/Lessons/AMEND_NOTES.json",
{ cache: "no-cache" }
);
const lesson2 = await amend_notes.json();
const naked_single = await fetch(
"https://sudokuru.s3.amazonaws.com/Lessons/NAKED_SINGLE.json",
{ cache: "no-cache" }
);
const lesson3 = await naked_single.json();
const simplify_notes = await fetch(
"https://sudokuru.s3.amazonaws.com/Lessons/SIMPLIFY_NOTES.json",
{ cache: "no-cache" }
);
const lesson4 = await simplify_notes.json();
const tutorial = lesson1.concat(lesson2, lesson3, lesson4);
return tutorial;
}
}