Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

quoridor

Package Overview
Dependencies
Maintainers
1
Versions
58
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

quoridor - npm Package Compare versions

Comparing version 2.1.4 to 2.1.5

2

lib/aStar.js

@@ -61,3 +61,3 @@ "use strict";

var aStar = function (game, player) {
var startPosition = utils_1.moveObjectToMove(game.playerPositions[player]);
var startPosition = game.playerPositions[player].position;
var positionToPreviousPosition = Object.fromEntries(consts_1.pawnPositions.map(function (position) { return [position, null]; }));

@@ -64,0 +64,0 @@ // When a node is relaxed it is removed from exploredPositions

import { DecrementableHorizontalPiecePosition, DecrementableHorizontalWallPosition, DecrementableVerticalPiecePosition, DecrementableVerticalWallPosition, HorizontallyDecrementablePawnPosition, HorizontallyIncrementablePawnPosition, HorizontalPiecePosition, HorizontalWallPosition, IncrementableHorizontalPiecePosition, IncrementableHorizontalWallPosition, IncrementableVerticalPiecePosition, IncrementableVerticalWallPosition, PawnPosition, VerticallyDecrementablePawnPosition, VerticallyIncrementablePawnPosition, VerticalPiecePosition, VerticalWallPosition, WallPosition } from './types';
export declare const pawnPositions: PawnPosition[];
export declare const wallPositions: WallPosition[];
export declare const pawnAndWallPositions: (PawnPosition | WallPosition)[];
/**

@@ -5,0 +6,0 @@ * These are the only piece positions where a player risks not having a path to the goal if a specific number of walls are placed

"use strict";
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
to[j] = from[i];
return to;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.isHorizontallyDecrementablePawnPositionMap = exports.horizontallyDecrementedPawnPositions = exports.isHorizontallyIncrementablePawnPositionMap = exports.horizontallyIncrementedPawnPositions = exports.isVerticallyDecrementablePawnPositionMap = exports.verticallyDecrementedPawnPositions = exports.isVerticallyIncrementablePawnPositionMap = exports.verticallyIncrementedPawnPositions = exports.isDecrementableVerticalPiecePositionMap = exports.isIncrementableVerticalPiecePositionMap = exports.isDecrementableHorizontalPiecePositionMap = exports.isIncrementableHorizontalPiecePositionMap = exports.isDecrementableVerticalWallPositionMap = exports.isIncrementableVerticalWallPositionMap = exports.isDecrementableHorizontalWallPositionMap = exports.isIncrementableHorizontalWallPositionMap = exports.isVerticalWallCoordinateMap = exports.isHorizontalWallCoordinateMap = exports.incrementedHorizontalPiecePositions = exports.incrementedVerticalPiecePositions = exports.decrementedVerticalPiecePositions = exports.decrementedHorizontalPiecePositions = exports.incrementedVerticalWallPositions = exports.decrementedVerticalWallPositions = exports.incrementedHorizontalWallPositions = exports.decrementedHorizontalWallPositions = exports.verticalPiecePositions = exports.verticallyDecrementableWallPositions = exports.verticallyIncrementableWallPositions = exports.horizontallyDecrementableWallPositions = exports.horizontallyIncrementableWallPositions = exports.possiblyTrappedPositions = exports.wallPositions = exports.pawnPositions = void 0;
exports.isHorizontallyDecrementablePawnPositionMap = exports.horizontallyDecrementedPawnPositions = exports.isHorizontallyIncrementablePawnPositionMap = exports.horizontallyIncrementedPawnPositions = exports.isVerticallyDecrementablePawnPositionMap = exports.verticallyDecrementedPawnPositions = exports.isVerticallyIncrementablePawnPositionMap = exports.verticallyIncrementedPawnPositions = exports.isDecrementableVerticalPiecePositionMap = exports.isIncrementableVerticalPiecePositionMap = exports.isDecrementableHorizontalPiecePositionMap = exports.isIncrementableHorizontalPiecePositionMap = exports.isDecrementableVerticalWallPositionMap = exports.isIncrementableVerticalWallPositionMap = exports.isDecrementableHorizontalWallPositionMap = exports.isIncrementableHorizontalWallPositionMap = exports.isVerticalWallCoordinateMap = exports.isHorizontalWallCoordinateMap = exports.incrementedHorizontalPiecePositions = exports.incrementedVerticalPiecePositions = exports.decrementedVerticalPiecePositions = exports.decrementedHorizontalPiecePositions = exports.incrementedVerticalWallPositions = exports.decrementedVerticalWallPositions = exports.incrementedHorizontalWallPositions = exports.decrementedHorizontalWallPositions = exports.verticalPiecePositions = exports.verticallyDecrementableWallPositions = exports.verticallyIncrementableWallPositions = exports.horizontallyDecrementableWallPositions = exports.horizontallyIncrementableWallPositions = exports.possiblyTrappedPositions = exports.pawnAndWallPositions = exports.wallPositions = exports.pawnPositions = void 0;
exports.pawnPositions = [

@@ -217,2 +222,3 @@ 'a1',

];
exports.pawnAndWallPositions = __spreadArray(__spreadArray([], exports.pawnPositions), exports.wallPositions);
/**

@@ -219,0 +225,0 @@ * These are the only piece positions where a player risks not having a path to the goal if a specific number of walls are placed

@@ -13,11 +13,5 @@ "use strict";

};
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
to[j] = from[i];
return to;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.createNewBoard = void 0;
var getAllPawnPositions_1 = require("./getAllPawnPositions");
var getAllWallPositions_1 = require("./getAllWallPositions");
var consts_1 = require("./consts");
var utils_1 = require("./utils");

@@ -34,3 +28,3 @@ var getDefaultValueForPosition = function (position) {

var createNewBoard = function () {
return __spreadArray(__spreadArray([], getAllPawnPositions_1.getAllPawnPositions()), getAllWallPositions_1.getAllWallPositions()).reduce(function (board, position) {
return consts_1.pawnAndWallPositions.reduce(function (board, position) {
var _a;

@@ -37,0 +31,0 @@ return (__assign(__assign({}, board), (_a = {}, _a[position] = getDefaultValueForPosition(position), _a)));

@@ -105,3 +105,3 @@ "use strict";

futureMoves: [],
playerPositions: { 1: { x: 'e', y: 1 }, 2: { x: 'e', y: 9 } },
playerPositions: { 1: { position: 'e1' }, 2: { position: 'e9' } },
playerWallCounts: { 1: 10, 2: 10 },

@@ -108,0 +108,0 @@ };

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getWinner = void 0;
var utils_1 = require("./utils");
var getWinner = function (game) {
if (game.playerPositions[1].y === 9)
if (utils_1.getVerticalCoordinate(game.playerPositions[1].position) === 9)
return 1;
if (game.playerPositions[2].y === 1)
if (utils_1.getVerticalCoordinate(game.playerPositions[2].position) === 1)
return 2;

@@ -9,0 +10,0 @@ return null;

@@ -33,3 +33,4 @@ export { createNewGame } from './createNewGame';

pastMoves: import("./types").Move[];
playerPositions: Record<import("./types").Player, import("./types").PiecePosition & {
playerPositions: Record<import("./types").Player, {
position: import("./types").PawnPosition;
previousPosition?: import("./types").PiecePosition | undefined;

@@ -36,0 +37,0 @@ }>;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isGameOver = void 0;
var getWinner_1 = require("./getWinner");
var isGameOver = function (game) {
return game.playerPositions[1].y === 9 || game.playerPositions[2].y === 1;
return getWinner_1.getWinner(game) !== null;
};
exports.isGameOver = isGameOver;
"use strict";
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
to[j] = from[i];
return to;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.isMove = void 0;
var getAllPawnPositions_1 = require("./getAllPawnPositions");
var getAllWallPositions_1 = require("./getAllWallPositions");
var consts_1 = require("./consts");
var isMove = function (maybeMove) {
return __spreadArray(__spreadArray([], getAllPawnPositions_1.getAllPawnPositions()), getAllWallPositions_1.getAllWallPositions()).includes(maybeMove);
return consts_1.pawnAndWallPositions.includes(maybeMove);
};
exports.isMove = isMove;

@@ -10,3 +10,3 @@ "use strict";

// Handle wall moves
var currentPosition = game.playerPositions[getTurn_1.getTurn(game)];
var currentPosition = game.playerPositions[getTurn_1.getTurn(game)].position;
if (utils_1.isWallPosition(move)) {

@@ -24,4 +24,4 @@ if (game.playerWallCounts[getTurn_1.getTurn(game)] < 1)

}
return utils_1.isValidNormalMove(game, utils_1.moveObjectToMove(currentPosition), move);
return utils_1.isValidNormalMove(game, currentPosition, move);
};
exports.isMoveValid = isMoveValid;

@@ -24,3 +24,3 @@ "use strict";

var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
var currentPosition = game.playerPositions[getTurn_1.getTurn(game)];
var currentPosition = game.playerPositions[getTurn_1.getTurn(game)].position;
if (utils_1.isWallPosition(move)) {

@@ -31,3 +31,3 @@ // If wall move

else {
var pieceMatrixWithRemovedPiece = __assign(__assign({}, game.pieceMatrix), (_g = {}, _g[currentPosition.x] = __assign(__assign({}, game.pieceMatrix[currentPosition.x]), (_h = {}, _h[currentPosition.y] = 0, _h)), _g));
var pieceMatrixWithRemovedPiece = __assign(__assign({}, game.pieceMatrix), (_g = {}, _g[utils_1.getHorizontalCoordinate(currentPosition)] = __assign(__assign({}, game.pieceMatrix[utils_1.getHorizontalCoordinate(currentPosition)]), (_h = {}, _h[utils_1.getVerticalCoordinate(currentPosition)] = 0, _h)), _g));
return __assign(__assign({}, game), { board: Object.fromEntries(Object.entries(game.board).map(function (_a) {

@@ -40,4 +40,3 @@ var pos = _a[0], val = _a[1];

})), playerPositions: __assign(__assign({}, game.playerPositions), (_j = {}, _j[getTurn_1.getTurn(game)] = {
x: utils_1.getHorizontalCoordinate(move),
y: utils_1.getVerticalCoordinate(move),
position: move,
previousPosition: game.playerPositions[getTurn_1.getTurn(game)],

@@ -44,0 +43,0 @@ }, _j)), pastMoves: __spreadArray(__spreadArray([], game.pastMoves), [move]), futureMoves: [], pieceMatrix: __assign(__assign({}, pieceMatrixWithRemovedPiece), (_k = {}, _k[utils_1.getHorizontalCoordinate(move)] = __assign(__assign({}, pieceMatrixWithRemovedPiece[utils_1.getHorizontalCoordinate(move)]), (_l = {}, _l[utils_1.getVerticalCoordinate(move)] = getTurn_1.getTurn(game), _l)), _k)) });

@@ -8,3 +8,4 @@ import { Game } from './types';

pastMoves: import("./types").Move[];
playerPositions: Record<import("./types").Player, import("./types").PiecePosition & {
playerPositions: Record<import("./types").Player, {
position: import("./types").PawnPosition;
previousPosition?: import("./types").PiecePosition | undefined;

@@ -11,0 +12,0 @@ }>;

@@ -56,3 +56,4 @@ export declare type HorizontalPiecePosition = 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | 'g' | 'h' | 'i';

futureMoves: Move[];
playerPositions: Record<Player, PiecePosition & {
playerPositions: Record<Player, {
position: PawnPosition;
previousPosition?: PiecePosition;

@@ -59,0 +60,0 @@ }>;

@@ -8,3 +8,4 @@ import { Game } from './types';

pastMoves: import("./types").Move[];
playerPositions: Record<import("./types").Player, import("./types").PiecePosition & {
playerPositions: Record<import("./types").Player, {
position: import("./types").PawnPosition;
previousPosition?: import("./types").PiecePosition | undefined;

@@ -11,0 +12,0 @@ }>;

@@ -585,11 +585,13 @@ "use strict";

var getShortestPathWithNoObstacles = function (game, player) {
var playerPosition = game.playerPositions[player];
var playerPosition = game.playerPositions[player].position;
var shortestPathVerticalCoordinates = player === 1
? consts_1.verticalPiecePositions.slice(playerPosition.y - 1)
: __spreadArray([], consts_1.verticalPiecePositions).reverse().slice(9 - playerPosition.y);
return shortestPathVerticalCoordinates.map(function (y) { return "" + playerPosition.x + y; });
? consts_1.verticalPiecePositions.slice(exports.getVerticalCoordinate(playerPosition) - 1)
: __spreadArray([], consts_1.verticalPiecePositions).reverse()
.slice(9 - exports.getVerticalCoordinate(playerPosition));
return shortestPathVerticalCoordinates.map(function (y) { return "" + exports.getHorizontalCoordinate(playerPosition) + y; });
};
exports.getShortestPathWithNoObstacles = getShortestPathWithNoObstacles;
var doesHorizontalWallBlockPlayer = function (game, player, horizontalWall) {
var _a = game.playerPositions[player], playerX = _a.x, playerY = _a.y;
var playerX = exports.getHorizontalCoordinate(game.playerPositions[player].position);
var playerY = exports.getVerticalCoordinate(game.playerPositions[player].position);
var wallX = exports.getHorizontalCoordinate(horizontalWall);

@@ -706,3 +708,3 @@ var wallY = exports.getVerticalCoordinate(horizontalWall);

var getValidPawnMoveArray = function (game) {
var currentPosition = exports.moveObjectToMove(game.playerPositions[getTurn_1.getTurn(game)]);
var currentPosition = game.playerPositions[getTurn_1.getTurn(game)].position;
var validPawnMoveArray = [

@@ -1158,4 +1160,4 @@ exports.isVerticallyIncrementablePawnPosition(currentPosition) &&

var isWallAdjacentToAtLeastOnePawn = function (game, wall) {
var player1Position = exports.moveObjectToMove(game.playerPositions[1]);
var player2Position = exports.moveObjectToMove(game.playerPositions[2]);
var player1Position = game.playerPositions[1].position;
var player2Position = game.playerPositions[2].position;
return (isWallAdjacentToPosition(wall, player1Position) ||

@@ -1286,4 +1288,4 @@ isWallAdjacentToPosition(wall, player2Position));

if (numberOfPlacedWalls <= 2) {
if (!consts_1.possiblyTrappedPositions[(numberOfPlacedWalls + 1)].includes(exports.moveObjectToMove(game.playerPositions[1])) &&
!consts_1.possiblyTrappedPositions[(numberOfPlacedWalls + 1)].includes(exports.moveObjectToMove(game.playerPositions[2]))) {
if (!consts_1.possiblyTrappedPositions[(numberOfPlacedWalls + 1)].includes(game.playerPositions[1].position) &&
!consts_1.possiblyTrappedPositions[(numberOfPlacedWalls + 1)].includes(game.playerPositions[2].position)) {
return consts_1.wallPositions.filter(function (wallMove) { return !overlapsWall(game, wallMove); });

@@ -1290,0 +1292,0 @@ }

{
"name": "quoridor",
"version": "2.1.4",
"version": "2.1.5",
"description": "A JavaScipt Quoridor library for move validation etc.",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc