Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Commit

Permalink
hotfix getPositionAfterMove() throws error
Browse files Browse the repository at this point in the history
  • Loading branch information
mort3za committed Jul 8, 2019
1 parent 192a92e commit c256623
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ludo",
"version": "v1.2.1",
"version": "v1.2.2",
"private": true,
"scripts": {
"start": "yarn serve",
Expand Down
35 changes: 19 additions & 16 deletions src/functions/move-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,34 +167,37 @@ function _getInGameActions(diceInfo: DiceInfo, player: Player): MoveAction[] {
playerMarblesInGame.forEach((marble: Marble) => {
const marblePosition: PositionInBoard = getPositionOfMarble(marble);
const finalStepPosition: PositionInBoard = getPositionOfStep(store.getters["steps/finalStep"]);
const toPosition = getPositionAfterMove({ from: marblePosition, player, amount: diceInfo.value });
const distanceToFinal: number = getDistance(marblePosition, finalStepPosition, player);
const isOutOfPath: boolean = diceInfo.value <= distanceToFinal;

if (!isOutOfPath) {
return;
}

const toPosition: PositionInBoard = getPositionAfterMove({ from: marblePosition, player, amount: diceInfo.value });

// prevent move to filled step
const playerMarblesAtToPosition = store.getters["marbles/listPlayerMarblesByPosition"](
player,
toPosition
);

const toPositionIsFilled = playerMarblesAtToPosition.length > 0;
if (toPositionIsFilled) {
return;
}

const distance: number = getDistance(marblePosition, finalStepPosition, player);
// console.log("distance", distance);
if (diceInfo.value <= distance) {
const action: MoveAction = {
const action: MoveAction = {
from: marblePosition,
to: getPositionAfterMove({
from: marblePosition,
to: getPositionAfterMove({
from: marblePosition,
amount: diceInfo.value,
player
}),
type: MoveType.IN_GAME,
marble
};
availableActions.push(action);
}
amount: diceInfo.value,
player
}),
type: MoveType.IN_GAME,
marble
};
availableActions.push(action);

});
return availableActions;
}
Expand Down
2 changes: 1 addition & 1 deletion src/functions/path-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function getPositionAfterMove({
const positionIndex = playerPath.findIndex((step: StepPlace) => {
return step[StepPlaceProps.ROW] === from.row && step[StepPlaceProps.COLUMN] === from.column;
});

if (playerPath.length >= positionIndex + amount) {
const step = playerPath[positionIndex + amount];
return getPositionOfStep(step);
Expand Down

0 comments on commit c256623

Please sign in to comment.