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.6.2 to 2.6.3

99

lib/immutable/aStar.js

@@ -23,10 +23,7 @@ "use strict";

};
// TODO: Maybe this could rather be a map from position to distance
var getVerticalDistanceToGoal = function (position, turn) {
return turn === 1
? 9 - (0, utils_1.getVerticalCoordinate)(position)
: (0, utils_1.getVerticalCoordinate)(position) - 1;
return consts_1.verticalDistanceToGoalMap[turn][position];
};
var hasReachedGoal = function (position, turn) {
return getVerticalDistanceToGoal(position, turn) === 0;
return consts_1.goalPositionsMap[turn].has(position);
};

@@ -64,9 +61,90 @@ /**

var startPosition = game.playerPositions[player].position;
var positionToPreviousPosition = Object.fromEntries(consts_1.pawnPositions.map(function (position) { return [position, null]; }));
// When a node is relaxed it is removed from exploredPositions
var positionToPreviousPosition = {
a1: null,
a2: null,
a3: null,
a4: null,
a5: null,
a6: null,
a7: null,
a8: null,
a9: null,
b1: null,
b2: null,
b3: null,
b4: null,
b5: null,
b6: null,
b7: null,
b8: null,
b9: null,
c1: null,
c2: null,
c3: null,
c4: null,
c5: null,
c6: null,
c7: null,
c8: null,
c9: null,
d1: null,
d2: null,
d3: null,
d4: null,
d5: null,
d6: null,
d7: null,
d8: null,
d9: null,
e1: null,
e2: null,
e3: null,
e4: null,
e5: null,
e6: null,
e7: null,
e8: null,
e9: null,
f1: null,
f2: null,
f3: null,
f4: null,
f5: null,
f6: null,
f7: null,
f8: null,
f9: null,
g1: null,
g2: null,
g3: null,
g4: null,
g5: null,
g6: null,
g7: null,
g8: null,
g9: null,
h1: null,
h2: null,
h3: null,
h4: null,
h5: null,
h6: null,
h7: null,
h8: null,
h9: null,
i1: null,
i2: null,
i3: null,
i4: null,
i5: null,
i6: null,
i7: null,
i8: null,
i9: null,
};
// When a node is relaxed it is removed from discoveredPositions
var discoveredPositions = new Set([startPosition]);
// This is a subset of discoveredPositions
var relaxedPositions = new Set();
var goalPosition = null;
while (!goalPosition) {
while (true) {
var mostPromisingPosition = getMostPromisingPosition(discoveredPositions, player);

@@ -76,3 +154,3 @@ if (!mostPromisingPosition)

if (hasReachedGoal(mostPromisingPosition, player)) {
goalPosition = mostPromisingPosition;
return getPath(positionToPreviousPosition, mostPromisingPosition);
}

@@ -88,4 +166,3 @@ var positionsDiscoveredFromMostPromisingPosition = getValidSurroundingPositions(game, mostPromisingPosition, discoveredPositions, relaxedPositions);

}
return getPath(positionToPreviousPosition, goalPosition);
};
exports.aStar = aStar;
import { DecrementableHorizontalPiecePosition, DecrementableHorizontalWallCoordinate, DecrementableVerticalPiecePosition, DecrementableVerticalWallCoordinate, HorizontallyDecrementablePawnPosition, HorizontallyIncrementablePawnPosition, HorizontalPiecePosition, HorizontalWallCoordinate, IncrementableHorizontalPiecePosition, IncrementableHorizontalWallCoordinate, IncrementableVerticalPiecePosition, IncrementableVerticalWallCoordinate, PawnPosition, PlayerMatrix, VerticallyDecrementablePawnPosition, VerticallyIncrementablePawnPosition, VerticalPiecePosition, VerticalWallCoordinate, WallMatrix, WallPosition } from '../types';
export declare const pawnPositions: PawnPosition[];
export declare const wallPositions: WallPosition[];
export declare const verticalDistanceToGoalMap: {
1: Record<PawnPosition, number>;
2: Record<PawnPosition, number>;
};
export declare const goalPositionsMap: {
1: Set<string>;
2: Set<string>;
};
export declare const positions: Set<PawnPosition | WallPosition>;

@@ -17,2 +25,3 @@ export declare const horizontallyMirroredPositionsMap: Record<PawnPosition, PawnPosition> & Record<WallPosition, WallPosition>;

3: Set<string>;
4: Set<string>;
};

@@ -19,0 +28,0 @@ export declare const horizontallyIncrementableWallPositions: string[];

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.moveUpUpMap = exports.moveUpMap = exports.moveRightMap = exports.moveLeftLeftMap = exports.moveLeftMap = exports.moveDownMap = exports.moveDownDownMap = exports.moveRightRightMap = exports.moveDownRightMap = exports.moveUpRightMap = exports.horizontallyDecrementedPawnPositions = exports.horizontallyDecrementablePositions = exports.horizontallyIncrementablePositions = exports.horizontallyIncrementedPawnPositions = exports.verticallyDecrementedPawnPositions = exports.verticallyIncrementedPawnPositions = exports.isDecrementableVerticalPiecePositionMap = exports.isIncrementableVerticalPiecePositionMap = exports.isDecrementableHorizontalPiecePositionMap = exports.isIncrementableHorizontalPiecePositionMap = exports.isDecrementableVerticalWallCoordinateMap = exports.isIncrementableVerticalWallCoordinateMap = exports.isDecrementableHorizontalWallCoordinateMap = exports.isIncrementableHorizontalWallCoordinateMap = exports.isVerticalWallCoordinateMap = exports.isHorizontalWallCoordinateMap = exports.incrementedHorizontalPiecePositions = exports.incrementedVerticalPiecePositions = exports.decrementedVerticalPiecePositions = exports.decrementedHorizontalPiecePositions = exports.incrementedVerticalWallCoordinates = exports.decrementedVerticalWallCoordinates = exports.incrementedHorizontalWallCoordinates = exports.decrementedHorizontalWallCoordinates = exports.verticalPiecePositions = exports.verticallyDecrementablePositions = exports.verticallyIncrementablePositions = exports.verticallyIncrementableWallPositions = exports.horizontallyIncrementableWallPositions = exports.possiblyTrappedPositions = exports.horizontalPawnCoordinates = exports.initialWallMatrix = exports.initialPlayerMatrix = exports.isWallPositionMap = exports.horizontallyMirroredPositionsMap = exports.positions = exports.wallPositions = exports.pawnPositions = void 0;
exports.moveUpUpMap = exports.moveUpMap = exports.moveRightMap = exports.moveLeftLeftMap = exports.moveLeftMap = exports.moveDownMap = exports.moveDownDownMap = exports.moveRightRightMap = exports.moveDownRightMap = exports.moveUpRightMap = exports.horizontallyDecrementedPawnPositions = exports.horizontallyDecrementablePositions = exports.horizontallyIncrementablePositions = exports.horizontallyIncrementedPawnPositions = exports.verticallyDecrementedPawnPositions = exports.verticallyIncrementedPawnPositions = exports.isDecrementableVerticalPiecePositionMap = exports.isIncrementableVerticalPiecePositionMap = exports.isDecrementableHorizontalPiecePositionMap = exports.isIncrementableHorizontalPiecePositionMap = exports.isDecrementableVerticalWallCoordinateMap = exports.isIncrementableVerticalWallCoordinateMap = exports.isDecrementableHorizontalWallCoordinateMap = exports.isIncrementableHorizontalWallCoordinateMap = exports.isVerticalWallCoordinateMap = exports.isHorizontalWallCoordinateMap = exports.incrementedHorizontalPiecePositions = exports.incrementedVerticalPiecePositions = exports.decrementedVerticalPiecePositions = exports.decrementedHorizontalPiecePositions = exports.incrementedVerticalWallCoordinates = exports.decrementedVerticalWallCoordinates = exports.incrementedHorizontalWallCoordinates = exports.decrementedHorizontalWallCoordinates = exports.verticalPiecePositions = exports.verticallyDecrementablePositions = exports.verticallyIncrementablePositions = exports.verticallyIncrementableWallPositions = exports.horizontallyIncrementableWallPositions = exports.possiblyTrappedPositions = exports.horizontalPawnCoordinates = exports.initialWallMatrix = exports.initialPlayerMatrix = exports.isWallPositionMap = exports.horizontallyMirroredPositionsMap = exports.positions = exports.goalPositionsMap = exports.verticalDistanceToGoalMap = exports.wallPositions = exports.pawnPositions = void 0;
exports.pawnPositions = [

@@ -217,2 +217,176 @@ 'a1',

];
var player1VerticalDistanceToGoalMap = {
a1: 8,
a2: 7,
a3: 6,
a4: 5,
a5: 4,
a6: 3,
a7: 2,
a8: 1,
a9: 0,
b1: 8,
b2: 7,
b3: 6,
b4: 5,
b5: 4,
b6: 3,
b7: 2,
b8: 1,
b9: 0,
c1: 8,
c2: 7,
c3: 6,
c4: 5,
c5: 4,
c6: 3,
c7: 2,
c8: 1,
c9: 0,
d1: 8,
d2: 7,
d3: 6,
d4: 5,
d5: 4,
d6: 3,
d7: 2,
d8: 1,
d9: 0,
e1: 8,
e2: 7,
e3: 6,
e4: 5,
e5: 4,
e6: 3,
e7: 2,
e8: 1,
e9: 0,
f1: 8,
f2: 7,
f3: 6,
f4: 5,
f5: 4,
f6: 3,
f7: 2,
f8: 1,
f9: 0,
g1: 8,
g2: 7,
g3: 6,
g4: 5,
g5: 4,
g6: 3,
g7: 2,
g8: 1,
g9: 0,
h1: 8,
h2: 7,
h3: 6,
h4: 5,
h5: 4,
h6: 3,
h7: 2,
h8: 1,
h9: 0,
i1: 8,
i2: 7,
i3: 6,
i4: 5,
i5: 4,
i6: 3,
i7: 2,
i8: 1,
i9: 0,
};
var player2VerticalDistanceToGoalMap = {
a1: 0,
a2: 1,
a3: 2,
a4: 3,
a5: 4,
a6: 5,
a7: 6,
a8: 7,
a9: 8,
b1: 0,
b2: 1,
b3: 2,
b4: 3,
b5: 4,
b6: 5,
b7: 6,
b8: 7,
b9: 8,
c1: 0,
c2: 1,
c3: 2,
c4: 3,
c5: 4,
c6: 5,
c7: 6,
c8: 7,
c9: 8,
d1: 0,
d2: 1,
d3: 2,
d4: 3,
d5: 4,
d6: 5,
d7: 6,
d8: 7,
d9: 8,
e1: 0,
e2: 1,
e3: 2,
e4: 3,
e5: 4,
e6: 5,
e7: 6,
e8: 7,
e9: 8,
f1: 0,
f2: 1,
f3: 2,
f4: 3,
f5: 4,
f6: 5,
f7: 6,
f8: 7,
f9: 8,
g1: 0,
g2: 1,
g3: 2,
g4: 3,
g5: 4,
g6: 5,
g7: 6,
g8: 7,
g9: 8,
h1: 0,
h2: 1,
h3: 2,
h4: 3,
h5: 4,
h6: 5,
h7: 6,
h8: 7,
h9: 8,
i1: 0,
i2: 1,
i3: 2,
i4: 3,
i5: 4,
i6: 5,
i7: 6,
i8: 7,
i9: 8,
};
exports.verticalDistanceToGoalMap = {
1: player1VerticalDistanceToGoalMap,
2: player2VerticalDistanceToGoalMap,
};
exports.goalPositionsMap = {
1: new Set(['a9', 'b9', 'c9', 'd9', 'e9', 'f9', 'g9', 'h9', 'i9']),
2: new Set(['a1', 'b1', 'c1', 'd1', 'e1', 'f1', 'g1', 'h1', 'i1']),
};
exports.positions = new Set(exports.pawnPositions.concat(exports.wallPositions));

@@ -865,2 +1039,76 @@ exports.horizontallyMirroredPositionsMap = {

]),
4: new Set([
'a1',
'a2',
'a3',
'a4',
'a5',
'a6',
'a7',
'a8',
'a9',
'b1',
'b2',
'b3',
'b4',
'b5',
'b6',
'b7',
'b8',
'b9',
'c1',
'c2',
'c3',
'c4',
'c6',
'c7',
'c8',
'c9',
'd1',
'd2',
'd3',
'd4',
'd6',
'd7',
'd8',
'd9',
'e1',
'e2',
'e8',
'e9',
'f1',
'f2',
'f3',
'f4',
'f6',
'f7',
'f8',
'f9',
'g1',
'g2',
'g3',
'g4',
'g6',
'g7',
'g8',
'g9',
'h1',
'h2',
'h3',
'h4',
'h5',
'h6',
'h7',
'h8',
'h9',
'i1',
'i2',
'i3',
'i4',
'i5',
'i6',
'i7',
'i8',
'i9',
]),
};

@@ -867,0 +1115,0 @@ exports.horizontallyIncrementableWallPositions = [

21

lib/immutable/utils.js

@@ -358,5 +358,3 @@ "use strict";

if (isSingleUpMove(currentPosition, move)) {
if (hasWallAbove(game, currentPosition))
return false;
return true;
return !hasWallAbove(game, currentPosition);
}

@@ -405,5 +403,3 @@ if (isDoubleUpMove(currentPosition, move) &&

if (isSingleRightMove(currentPosition, move)) {
if ((0, exports.hasWallToTheRight)(game, currentPosition))
return false;
return true;
return !(0, exports.hasWallToTheRight)(game, currentPosition);
}

@@ -452,6 +448,3 @@ if (isDoubleRightMove(currentPosition, move) &&

if (isSingleDownMove(currentPosition, move)) {
if ((0, exports.hasWallBelow)(game, currentPosition)) {
return false;
}
return true;
return !(0, exports.hasWallBelow)(game, currentPosition);
}

@@ -501,5 +494,3 @@ if (isDoubleDownMove(currentPosition, move) &&

if (isSingleLeftMove(currentPosition, move)) {
if (hasWallToTheLeft(game, currentPosition))
return false;
return true;
return !hasWallToTheLeft(game, currentPosition);
}

@@ -1172,3 +1163,3 @@ if (isDoubleLeftMove(currentPosition, move) &&

if (isSingleUpMove(previousPosition, currentPosition) &&
// Pawh is right above wall
// Pawn is right above wall
currentPositionY === wallMoveY + 1 &&

@@ -1229,3 +1220,3 @@ // Is wall below or below left

var numberOfPlacedWalls = (0, exports.getNumberOfPlacedWalls)(game);
if (numberOfPlacedWalls <= 2) {
if (numberOfPlacedWalls <= 3) {
if (!consts_1.possiblyTrappedPositions[(numberOfPlacedWalls + 1)].has(game.playerPositions[1].position) &&

@@ -1232,0 +1223,0 @@ !consts_1.possiblyTrappedPositions[(numberOfPlacedWalls + 1)].has(game.playerPositions[2].position)) {

"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -23,3 +12,6 @@ exports.doMakeUnvalidatedMove = void 0;

game.playerWallCounts[turn] -= 1;
game.playerPositions[turn] = __assign(__assign({}, game.playerPositions[turn]), { previousPosition: game.playerPositions[turn] });
game.playerPositions[turn] = {
position: game.playerPositions[turn].position,
previousPosition: game.playerPositions[turn],
};
}

@@ -26,0 +18,0 @@ else {

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

var numberOfPlacedWalls = (0, utils_1.getNumberOfPlacedWalls)(game);
if (numberOfPlacedWalls <= 2) {
if (numberOfPlacedWalls <= 3) {
if (!consts_1.possiblyTrappedPositions[(numberOfPlacedWalls + 1)].has(game.playerPositions[1].position) &&

@@ -20,0 +20,0 @@ !consts_1.possiblyTrappedPositions[(numberOfPlacedWalls + 1)].has(game.playerPositions[2].position)) {

{
"name": "quoridor",
"version": "2.6.2",
"version": "2.6.3",
"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