Comparing version 1.7.2 to 1.7.3
@@ -14,1 +14,2 @@ import { PawnPosition } from './types'; | ||
export declare const verticallyDecrementableWallPositions: string[]; | ||
export declare const verticalPiecePositions: number[]; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.verticallyDecrementableWallPositions = exports.verticallyIncrementableWallPositions = exports.horizontallyDecrementableWallPositions = exports.horizontallyIncrementableWallPositions = exports.possiblyTrappedPositions = void 0; | ||
exports.verticalPiecePositions = exports.verticallyDecrementableWallPositions = exports.verticallyIncrementableWallPositions = exports.horizontallyDecrementableWallPositions = exports.horizontallyIncrementableWallPositions = exports.possiblyTrappedPositions = void 0; | ||
/** | ||
@@ -542,1 +542,2 @@ * 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 | ||
]; | ||
exports.verticalPiecePositions = [1, 2, 3, 4, 5, 6, 7, 8, 9]; |
@@ -187,7 +187,7 @@ "use strict"; | ||
}; | ||
var isHorizontalWallMove = function (wallMove) { | ||
return wallMove.charAt(2) === 'h'; | ||
var isHorizontalWallMove = function (move) { | ||
return move.charAt(2) === 'h'; | ||
}; | ||
var isVerticalWallMove = function (wallMove) { | ||
return wallMove.charAt(2) === 'v'; | ||
var isVerticalWallMove = function (move) { | ||
return move.charAt(2) === 'v'; | ||
}; | ||
@@ -761,4 +761,36 @@ var doesWallMoveOverlapExistingWall = function (game, wallMove) { | ||
exports.isValidNormalMove = isValidNormalMove; | ||
var getShortestPathWithNoObstacles = function (game, player) { | ||
var playerPosition = game.playerPositions[player]; | ||
var shortestPathVerticalCoordinates = player === 1 | ||
? consts_1.verticalPiecePositions.slice(playerPosition.y) | ||
: consts_1.verticalPiecePositions.slice(0, -playerPosition.y); | ||
return shortestPathVerticalCoordinates.map(function (y) { return ({ | ||
x: playerPosition.x, | ||
y: y, | ||
}); }); | ||
}; | ||
var doesHorizontalWallBlockPlayer = function (game, player, horizontalWall) { | ||
var _a = game.playerPositions[player], playerX = _a.x, playerY = _a.y; | ||
var wallX = exports.getHorizontalCoordinate(horizontalWall); | ||
var wallY = exports.getVerticalCoordinate(horizontalWall); | ||
var wallOverlapsWithPlayerColumn = playerX === wallX || | ||
(isIncrementableHorizontalWallPosition(wallX) && | ||
playerX === incrementHorizontalWallPosition(wallX)); | ||
if (!wallOverlapsWithPlayerColumn) | ||
return false; | ||
if (player === 1) { | ||
return wallY >= playerY; | ||
} | ||
return wallY < playerY; | ||
}; | ||
var shortestPath = function (game, player) { | ||
return aStar_1.aStar(game.pieceMatrix, game.wallMatrix, player); | ||
var placedHorizontalWalls = game.pastMoves.filter(isHorizontalWallMove); | ||
if (placedHorizontalWalls.some(function (wall) { | ||
return doesHorizontalWallBlockPlayer(game, player, wall); | ||
})) { | ||
return aStar_1.aStar(game.pieceMatrix, game.wallMatrix, player); | ||
} | ||
// The shortest path has no obstacles if no horizontal walls have been placed | ||
// between the player and the goal | ||
return getShortestPathWithNoObstacles(game, player); | ||
}; | ||
@@ -765,0 +797,0 @@ exports.shortestPath = shortestPath; |
{ | ||
"name": "quoridor", | ||
"version": "1.7.2", | ||
"version": "1.7.3", | ||
"description": "A JavaScipt Quoridor library for move validation etc.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
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
148204
3486