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

Commit

Permalink
Do not move same side marbles to same step #19
Browse files Browse the repository at this point in the history
  • Loading branch information
mort3za committed Jul 5, 2019
1 parent ec255dc commit a5b6f8b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/functions/dice-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export async function turnDice(activePlayer: Player) {
await store.dispatch("board/update", {
key: "diceInfo",
value: createDiceInfo({
// @ts-ignore FIXME: remove
// value: window.dice || result,
value: result,
isDone: false,
player: activePlayer
Expand Down
34 changes: 28 additions & 6 deletions src/functions/move-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,12 @@ export function getStrategicalAction(action: MoveAction, player: Player): MoveAc

upgradedAction.distanceToFinal = getDistance(action.to, finalStepPosition, player);
upgradedAction.kickoutList = getKickoutList(player, action.to);
upgradedAction.isCurrentPositionSafepoint = getStepPlaceOfPosition(action.from)[StepPlaceProps.STEP_TYPE].includes(
StepType.SAFEZONE
);
upgradedAction.isTargetPositionSafepoint = getStepPlaceOfPosition(action.to)[StepPlaceProps.STEP_TYPE].includes(StepType.SAFEZONE);
upgradedAction.isCurrentPositionSafepoint = getStepPlaceOfPosition(action.from)[
StepPlaceProps.STEP_TYPE
].includes(StepType.SAFEZONE);
upgradedAction.isTargetPositionSafepoint = getStepPlaceOfPosition(action.to)[
StepPlaceProps.STEP_TYPE
].includes(StepType.SAFEZONE);
return upgradedAction;
}

Expand Down Expand Up @@ -132,9 +134,17 @@ function _getBenchActions(diceInfo: DiceInfo, player: Player): MoveAction[] {
const playerMarblesInBench = store.getters["marbles/listInBenchByPlayer"](player);
const hasAnyBenchMarbles = playerMarblesInBench.length > 0;

if (!hasAnyBenchMarbles) {
// prevent move to filled step
const startpointStep = store.getters["steps/sideStartpoint"](player);
const playerMarblesAtStartpoint = store.getters["marbles/listPlayerMarblesByPosition"](
player,
getPositionOfStep(startpointStep)
);
const startpointIsFilled = playerMarblesAtStartpoint.length > 0;
if (!hasAnyBenchMarbles || startpointIsFilled) {
return availableActions;
}

if (diceInfo.canMoveBench) {
const sideStartpointStep = store.getters["steps/sideStartpoint"](player);
playerMarblesInBench.forEach((marble: Marble) => {
Expand All @@ -157,10 +167,22 @@ 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 });

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

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 = {
from: marblePosition,
Expand Down
8 changes: 8 additions & 0 deletions src/store/modules/marbles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ export default {
(m: Marble) => m.side !== player.side && isSameStep(getPositionOfMarble(m), position)
);
},
listPlayerMarblesByPosition: (state: any, getters: any) => (
player: Player,
position: PositionInBoard
) => {
return getters.list.filter(
(m: Marble) => m.side === player.side && isSameStep(getPositionOfMarble(m), position)
);
},
listInitial(state: any): Marble[] {
return state.listInitial;
},
Expand Down

0 comments on commit a5b6f8b

Please sign in to comment.