Allow returning to the safe trainer start
This commit is contained in:
1 parent
ba25b64190
commit
ba074df4ec
10 files changed
+102
-48
No files matched your search
@@ -85,7 +85,7 @@ export class Training {
|
||||
}
|
||||
#valid(id) { return Number.isInteger(id) && id >= 0 && id < ROWS * COLS; }
|
||||
#finished() { return this.#status === 'won' || this.#status === 'lost'; }
|
||||
#transition(id) { return id === START || id === this.#field.exit; }
|
||||
#transition(id) { return id === this.#field.exit; }
|
||||
#available(id) { return !this.#transition(id) && distance(this.#position, id) === 1; }
|
||||
#guard(id) {
|
||||
if (this.#finished()) return {code: 'finished'};
|
||||
@@ -108,8 +108,9 @@ export class Training {
|
||||
this.#history.push({type: 'fall', id});
|
||||
return {code: 'fall', id, hint: null};
|
||||
}
|
||||
const code = this.#opened.has(id) ? 'revisited' : 'opened';
|
||||
this.#opened.add(id); this.#position = id;
|
||||
const code = id === START || this.#opened.has(id) ? 'revisited' : 'opened';
|
||||
if (id !== START) this.#opened.add(id);
|
||||
this.#position = id;
|
||||
const value = this.#field.values[id];
|
||||
this.#history.push({type: code, id, value});
|
||||
this.#win();
|
||||
@@ -121,7 +122,7 @@ export class Training {
|
||||
mark(id) {
|
||||
const rejected = this.#guard(id);
|
||||
if (rejected) return rejected;
|
||||
if (this.#opened.has(id)) return {code: 'opened'};
|
||||
if (id === START || this.#opened.has(id)) return {code: 'opened'};
|
||||
const marked = !this.#marks.has(id);
|
||||
if (marked) this.#marks.add(id); else this.#marks.delete(id);
|
||||
this.#history.push({type: marked ? 'marked' : 'unmarked', id});
|
||||
@@ -131,6 +132,7 @@ export class Training {
|
||||
rate(id, rating) {
|
||||
const rejected = this.#guard(id);
|
||||
if (rejected) return rejected;
|
||||
if (id === START) return {code: 'opened'};
|
||||
if (rating !== null && (!Number.isInteger(rating) || rating < 0 || rating > 7)) return {code: 'invalid-level'};
|
||||
if ((this.#ratings.get(id) ?? null) === rating) return {code: 'unchanged'};
|
||||
if (rating === null) this.#ratings.delete(id); else this.#ratings.set(id, rating);
|
||||
|
||||
Reference in new issue
Block a user