This commit is contained in:
Maciej Caderek
2022-01-28 01:23:28 +01:00
parent 6c401d1459
commit e000a0083a
24 changed files with 648 additions and 360 deletions

View File

@@ -32,7 +32,7 @@ class Game {
this.moves = moves.map((item, i) => ({
...item,
ply: i,
ply: i + 1,
end: moves.length - 1 - i,
}));
@@ -53,25 +53,34 @@ class Game {
}
next() {
const move = this.moves[this.currentPly];
this.currentPly++;
const move = this.moves[this.currentPly - 1];
if (!move) {
return null;
}
this.replay.move(move);
this.currentPly++;
return move;
}
prev() {
const move = this.replay.undo();
const undo = Boolean(this.replay.undo());
if (!move) {
if (undo) {
this.currentPly--;
} else {
return null;
}
this.currentPly--;
const move = this.moves[this.currentPly];
// if (!move) {
// return null;
// }
console.log("Prev!");
return move;
}