Comparing version 1.4.1 to 1.5.0
@@ -103,3 +103,4 @@ "use strict"; | ||
wallMatrix: createNewWallMatrix(), | ||
history: [], | ||
pastMoves: [], | ||
futureMoves: [], | ||
playerPositions: { 1: { x: 'e', y: 1 }, 2: { x: 'e', y: 9 } }, | ||
@@ -106,0 +107,0 @@ playerWallCounts: { 1: 10, 2: 10 }, |
@@ -5,4 +5,4 @@ "use strict"; | ||
var getTurn = function (game) { | ||
return ((game.history.length % 2) + 1); | ||
return ((game.pastMoves.length % 2) + 1); | ||
}; | ||
exports.getTurn = getTurn; |
@@ -10,3 +10,3 @@ export { createNewGame } from './createNewGame'; | ||
export { getTurn } from './getTurn'; | ||
export { undoLastMove } from './undoLastMove'; | ||
export { undo } from './undo'; | ||
/** | ||
@@ -20,1 +20,15 @@ * Deprecated. This function has been renamed to getUnicodeRepresentation. | ||
export declare const isValidMove: (game: import("./types").Game, move: import("./types").Move) => boolean; | ||
/** | ||
* Deprecated. This function has been renamed to undo. | ||
*/ | ||
export declare const undoLastMove: (game: import("./types").Game) => { | ||
futureMoves: import("./types").Move[]; | ||
board: import("./types").Board; | ||
pieceMatrix: import("./types").PlayerMatrix; | ||
wallMatrix: import("./types").WallMatrix; | ||
pastMoves: import("./types").Move[]; | ||
playerPositions: Record<import("./types").Player, import("./types").PiecePosition & { | ||
previousPosition?: import("./types").PiecePosition | undefined; | ||
}>; | ||
playerWallCounts: Record<import("./types").Player, 2 | 1 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3>; | ||
}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isValidMove = exports.getAsciiRepresentation = exports.undoLastMove = exports.getTurn = exports.getValidMoveArray = exports.getWinner = exports.isGameOver = exports.makeMove = exports.getUnicodeRepresentation = exports.isMoveValid = exports.createGameFromMoves = exports.createNewGame = void 0; | ||
exports.undoLastMove = exports.isValidMove = exports.getAsciiRepresentation = exports.undo = exports.getTurn = exports.getValidMoveArray = exports.getWinner = exports.isGameOver = exports.makeMove = exports.getUnicodeRepresentation = exports.isMoveValid = exports.createGameFromMoves = exports.createNewGame = void 0; | ||
var createNewGame_1 = require("./createNewGame"); | ||
@@ -22,6 +22,7 @@ Object.defineProperty(exports, "createNewGame", { enumerable: true, get: function () { return createNewGame_1.createNewGame; } }); | ||
Object.defineProperty(exports, "getTurn", { enumerable: true, get: function () { return getTurn_1.getTurn; } }); | ||
var undoLastMove_1 = require("./undoLastMove"); | ||
Object.defineProperty(exports, "undoLastMove", { enumerable: true, get: function () { return undoLastMove_1.undoLastMove; } }); | ||
var undo_1 = require("./undo"); | ||
Object.defineProperty(exports, "undo", { enumerable: true, get: function () { return undo_1.undo; } }); | ||
var getUnicodeRepresentation_2 = require("./getUnicodeRepresentation"); | ||
var isMoveValid_2 = require("./isMoveValid"); | ||
var undo_2 = require("./undo"); | ||
/** | ||
@@ -35,1 +36,5 @@ * Deprecated. This function has been renamed to getUnicodeRepresentation. | ||
exports.isValidMove = isMoveValid_2.isMoveValid; | ||
/** | ||
* Deprecated. This function has been renamed to undo. | ||
*/ | ||
exports.undoLastMove = undo_2.undo; |
@@ -38,3 +38,4 @@ export declare type HorizontalPiecePosition = 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | 'g' | 'h' | 'i'; | ||
wallMatrix: WallMatrix; | ||
history: Move[]; | ||
pastMoves: Move[]; | ||
futureMoves: Move[]; | ||
playerPositions: Record<Player, PiecePosition & { | ||
@@ -41,0 +42,0 @@ previousPosition?: PiecePosition; |
@@ -18,1 +18,5 @@ import { QuoridorNode } from './aStar'; | ||
export declare const getValidWallMoveArray: (game: Game) => import("./types").WallPosition[]; | ||
export declare const butlast: <T>(array: T[]) => T[]; | ||
export declare const first: <T>(array: T[]) => T; | ||
export declare const last: <T>(array: T[]) => T; | ||
export declare const rest: <T>(array: T[]) => T[]; |
@@ -19,3 +19,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getValidWallMoveArray = exports.getValidPawnMoveArray = exports.shortestPath = exports.isValidNormalMove = exports.unvalidatedMove = exports.getOppositePlayer = exports.isWallPosition = exports.doesWallMoveOverlapExistingWall = exports.moveObjectToMove = exports.getWallOrientation = exports.getVerticalCoordinate = exports.getHorizontalCoordinate = void 0; | ||
exports.rest = exports.last = exports.first = exports.butlast = exports.getValidWallMoveArray = exports.getValidPawnMoveArray = exports.shortestPath = exports.isValidNormalMove = exports.unvalidatedMove = exports.getOppositePlayer = exports.isWallPosition = exports.doesWallMoveOverlapExistingWall = exports.moveObjectToMove = exports.getWallOrientation = exports.getVerticalCoordinate = exports.getHorizontalCoordinate = void 0; | ||
var aStar_1 = require("./aStar"); | ||
@@ -248,3 +248,3 @@ var getTurn_1 = require("./getTurn"); | ||
// If wall move | ||
return __assign(__assign({}, game), { board: __assign(__assign({}, game.board), (_a = {}, _a[move] = true, _a)), wallMatrix: __assign(__assign({}, game.wallMatrix), (_b = {}, _b[exports.getHorizontalCoordinate(move)] = __assign(__assign({}, game.wallMatrix[exports.getHorizontalCoordinate(move)]), (_c = {}, _c[exports.getVerticalCoordinate(move)] = __assign(__assign({}, game.wallMatrix[exports.getHorizontalCoordinate(move)][exports.getVerticalCoordinate(move)]), (_d = {}, _d[exports.getWallOrientation(move)] = true, _d)), _c)), _b)), playerWallCounts: __assign(__assign({}, game.playerWallCounts), (_e = {}, _e[getTurn_1.getTurn(game)] = game.playerWallCounts[getTurn_1.getTurn(game)] - 1, _e)), playerPositions: __assign(__assign({}, game.playerPositions), (_f = {}, _f[getTurn_1.getTurn(game)] = __assign(__assign({}, game.playerPositions[getTurn_1.getTurn(game)]), { previousPosition: game.playerPositions[getTurn_1.getTurn(game)] }), _f)), history: __spreadArray(__spreadArray([], game.history), [move]) }); | ||
return __assign(__assign({}, game), { board: __assign(__assign({}, game.board), (_a = {}, _a[move] = true, _a)), wallMatrix: __assign(__assign({}, game.wallMatrix), (_b = {}, _b[exports.getHorizontalCoordinate(move)] = __assign(__assign({}, game.wallMatrix[exports.getHorizontalCoordinate(move)]), (_c = {}, _c[exports.getVerticalCoordinate(move)] = __assign(__assign({}, game.wallMatrix[exports.getHorizontalCoordinate(move)][exports.getVerticalCoordinate(move)]), (_d = {}, _d[exports.getWallOrientation(move)] = true, _d)), _c)), _b)), playerWallCounts: __assign(__assign({}, game.playerWallCounts), (_e = {}, _e[getTurn_1.getTurn(game)] = game.playerWallCounts[getTurn_1.getTurn(game)] - 1, _e)), playerPositions: __assign(__assign({}, game.playerPositions), (_f = {}, _f[getTurn_1.getTurn(game)] = __assign(__assign({}, game.playerPositions[getTurn_1.getTurn(game)]), { previousPosition: game.playerPositions[getTurn_1.getTurn(game)] }), _f)), pastMoves: __spreadArray(__spreadArray([], game.pastMoves), [move]), futureMoves: [] }); | ||
} | ||
@@ -263,3 +263,3 @@ else { | ||
previousPosition: game.playerPositions[getTurn_1.getTurn(game)], | ||
}, _j)), history: __spreadArray(__spreadArray([], game.history), [move]), pieceMatrix: __assign(__assign({}, pieceMatrixWithRemovedPiece), (_k = {}, _k[exports.getHorizontalCoordinate(move)] = __assign(__assign({}, pieceMatrixWithRemovedPiece[exports.getHorizontalCoordinate(move)]), (_l = {}, _l[exports.getVerticalCoordinate(move)] = getTurn_1.getTurn(game), _l)), _k)) }); | ||
}, _j)), pastMoves: __spreadArray(__spreadArray([], game.pastMoves), [move]), futureMoves: [], pieceMatrix: __assign(__assign({}, pieceMatrixWithRemovedPiece), (_k = {}, _k[exports.getHorizontalCoordinate(move)] = __assign(__assign({}, pieceMatrixWithRemovedPiece[exports.getHorizontalCoordinate(move)]), (_l = {}, _l[exports.getVerticalCoordinate(move)] = getTurn_1.getTurn(game), _l)), _k)) }); | ||
} | ||
@@ -948,1 +948,9 @@ }; | ||
exports.getValidWallMoveArray = getValidWallMoveArray; | ||
var butlast = function (array) { return array.slice(0, -1); }; | ||
exports.butlast = butlast; | ||
var first = function (array) { return array[0]; }; | ||
exports.first = first; | ||
var last = function (array) { return array[array.length - 1]; }; | ||
exports.last = last; | ||
var rest = function (array) { return array.slice(1); }; | ||
exports.rest = rest; |
{ | ||
"name": "quoridor", | ||
"version": "1.4.1", | ||
"version": "1.5.0", | ||
"description": "A JavaScipt Quoridor library for move validation etc.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -139,11 +139,11 @@ # quoridor.js | ||
### undoLastMove: (game: Game) => Game | ||
### undo: (game: Game) => Game | ||
Returns a new game with the last move undone. If no moves have been made yet, an identical game is returned. | ||
Returns a new game with the most recent move undone. If no moves have been made yet, an identical game is returned. | ||
```TypeScript | ||
import { createGameFromMoves, undoLastMove, getUnicodeRepresentation } from 'quoridor'; | ||
import { createGameFromMoves, undo, getUnicodeRepresentation } from 'quoridor'; | ||
const game = createGameFromMoves(['e2', 'e8', 'd7v']); | ||
const gameWithLastMoveUndone = undoLastMove(game); | ||
const gameWithLastMoveUndone = undo(game); | ||
@@ -204,2 +204,92 @@ console.log(getUnicodeRepresentation(game)); | ||
### redo: (game: Game) => Game | ||
Returns a new game with the most recently undone move redone. If no moves have been undone yet, an identical game is returned. | ||
```TypeScript | ||
import { createGameFromMoves, undo, getUnicodeRepresentation } from 'quoridor'; | ||
const game = createGameFromMoves(['e2', 'e8', 'd7v']); | ||
const gameWithUndoneMove = undo(game); | ||
const gameWithUndoneMoveRedone = redo(gameWithLastMoveUndone); | ||
console.log(getUnicodeRepresentation(game)); | ||
// ┌───╫───╫───╫───╫───╫───╫───╫───╫───╫───╫───┐ | ||
// │ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ │ | ||
// │ ┌───┬───┬───┬───┬───┬───┬───┬───┬───┐ │ | ||
// │ 9 │ │ │ │ │ │ │ │ │ │ │ | ||
// │ ├───┼───┼───┼───┼───┼───┼───┼───┼───┤ │ | ||
// │ 8 │ │ │ │ │ │ │ │ │ │ │ | ||
// │ ├───┼───┼───┼───┼───┼───┼───┼───┼───┤ │ | ||
// │ 7 │ │ │ │ ║ 2 │ │ │ │ │ │ | ||
// │ ├───┼───┼───┼───╫───┼───┼───┼───┼───┤ │ | ||
// │ 6 │ │ │ │ ║ │ │ │ │ │ │ | ||
// │ ├───┼───┼───┼───┼───┼───┼───┼───┼───┤ │ | ||
// │ 5 │ │ │ │ │ │ │ │ │ │ │ | ||
// │ ├───┼───┼───┼───┼───┼───┼───┼───┼───┤ │ | ||
// │ 4 │ │ │ │ │ │ │ │ │ │ │ | ||
// │ ├───┼───┼───┼───┼───┼───┼───┼───┼───┤ │ | ||
// │ 3 │ │ │ │ │ 1 │ │ │ │ │ │ | ||
// │ ├───┼───┼───┼───┼───┼───┼───┼───┼───┤ │ | ||
// │ 2 │ │ │ │ │ │ │ │ │ │ │ | ||
// │ ├───┼───┼───┼───┼───┼───┼───┼───┼───┤ │ | ||
// │ 1 │ │ │ │ │ │ │ │ │ │ │ | ||
// │ └───┴───┴───┴───┴───┴───┴───┴───┴───┘ │ | ||
// │ ║ A ║ B ║ C ║ D ║ E ║ F ║ G ║ H ║ I │ | ||
// └───╫───╫───╫───╫───╫───╫───╫───╫───╫───────┘ | ||
console.log(getUnicodeRepresentation(gameWithUndoneMove)); | ||
// ┌───╫───╫───╫───╫───╫───╫───╫───╫───╫───╫───┐ | ||
// │ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ │ | ||
// │ ┌───┬───┬───┬───┬───┬───┬───┬───┬───┐ │ | ||
// │ 9 │ │ │ │ │ │ │ │ │ │ │ | ||
// │ ├───┼───┼───┼───┼───┼───┼───┼───┼───┤ │ | ||
// │ 8 │ │ │ │ │ │ │ │ │ │ │ | ||
// │ ├───┼───┼───┼───┼───┼───┼───┼───┼───┤ │ | ||
// │ 7 │ │ │ │ │ 2 │ │ │ │ │ │ | ||
// │ ├───┼───┼───┼───┼───┼───┼───┼───┼───┤ │ | ||
// │ 6 │ │ │ │ │ │ │ │ │ │ │ | ||
// │ ├───┼───┼───┼───┼───┼───┼───┼───┼───┤ │ | ||
// │ 5 │ │ │ │ │ │ │ │ │ │ │ | ||
// │ ├───┼───┼───┼───┼───┼───┼───┼───┼───┤ │ | ||
// │ 4 │ │ │ │ │ │ │ │ │ │ │ | ||
// │ ├───┼───┼───┼───┼───┼───┼───┼───┼───┤ │ | ||
// │ 3 │ │ │ │ │ 1 │ │ │ │ │ │ | ||
// │ ├───┼───┼───┼───┼───┼───┼───┼───┼───┤ │ | ||
// │ 2 │ │ │ │ │ │ │ │ │ │ │ | ||
// │ ├───┼───┼───┼───┼───┼───┼───┼───┼───┤ │ | ||
// │ 1 │ │ │ │ │ │ │ │ │ │ │ | ||
// │ └───┴───┴───┴───┴───┴───┴───┴───┴───┘ │ | ||
// │ ║ A ║ B ║ C ║ D ║ E ║ F ║ G ║ H ║ I ║ │ | ||
// └───╫───╫───╫───╫───╫───╫───╫───╫───╫───╫───┘ | ||
console.log(getUnicodeRepresentation(gameWithUndoneMoveRedone)); | ||
// ┌───╫───╫───╫───╫───╫───╫───╫───╫───╫───╫───┐ | ||
// │ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ │ | ||
// │ ┌───┬───┬───┬───┬───┬───┬───┬───┬───┐ │ | ||
// │ 9 │ │ │ │ │ │ │ │ │ │ │ | ||
// │ ├───┼───┼───┼───┼───┼───┼───┼───┼───┤ │ | ||
// │ 8 │ │ │ │ │ │ │ │ │ │ │ | ||
// │ ├───┼───┼───┼───┼───┼───┼───┼───┼───┤ │ | ||
// │ 7 │ │ │ │ ║ 2 │ │ │ │ │ │ | ||
// │ ├───┼───┼───┼───╫───┼───┼───┼───┼───┤ │ | ||
// │ 6 │ │ │ │ ║ │ │ │ │ │ │ | ||
// │ ├───┼───┼───┼───┼───┼───┼───┼───┼───┤ │ | ||
// │ 5 │ │ │ │ │ │ │ │ │ │ │ | ||
// │ ├───┼───┼───┼───┼───┼───┼───┼───┼───┤ │ | ||
// │ 4 │ │ │ │ │ │ │ │ │ │ │ | ||
// │ ├───┼───┼───┼───┼───┼───┼───┼───┼───┤ │ | ||
// │ 3 │ │ │ │ │ 1 │ │ │ │ │ │ | ||
// │ ├───┼───┼───┼───┼───┼───┼───┼───┼───┤ │ | ||
// │ 2 │ │ │ │ │ │ │ │ │ │ │ | ||
// │ ├───┼───┼───┼───┼───┼───┼───┼───┼───┤ │ | ||
// │ 1 │ │ │ │ │ │ │ │ │ │ │ | ||
// │ └───┴───┴───┴───┴───┴───┴───┴───┴───┘ │ | ||
// │ ║ A ║ B ║ C ║ D ║ E ║ F ║ G ║ H ║ I │ | ||
// └───╫───╫───╫───╫───╫───╫───╫───╫───╫───────┘ | ||
``` | ||
## Publishing a new version | ||
@@ -206,0 +296,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
106034
41
2220
315