Skip to content

Commit

Permalink
fix forest locations that copy others, issue #77
Browse files Browse the repository at this point in the history
  • Loading branch information
elynnlee committed Dec 26, 2023
1 parent 27e2c61 commit 9e86dec
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 11 deletions.
39 changes: 30 additions & 9 deletions src/model/location.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,8 @@ describe("Location", () => {
);
const gameInput = placeWorkerInput(location.name);
gameState.locationsMap[LocationName.FOREST_COPY_ANY_FOREST_LOCATION] = [];
gameState.locationsMap[LocationName.FOREST_FOUR_TWIG] = [];
player = gameState.getActivePlayer();

player.addCardToHand(gameState, CardName.BARD);
player.addCardToHand(gameState, CardName.INN);
Expand All @@ -701,9 +703,7 @@ describe("Location", () => {
inputType: GameInputType.SELECT_LOCATION,
prevInputType: GameInputType.PLACE_WORKER,
locationContext: LocationName.FOREST_COPY_ANY_FOREST_LOCATION,
locationOptions: Location.byType(LocationType.FOREST).filter(
(loc) => loc != LocationName.FOREST_COPY_ANY_FOREST_LOCATION
),
locationOptions: [LocationName.FOREST_FOUR_TWIG],
clientOptions: {
selectedLocation: LocationName.FOREST_FOUR_TWIG,
},
Expand All @@ -719,16 +719,15 @@ describe("Location", () => {
);
const gameInput = placeWorkerInput(location.name);
gameState.locationsMap[LocationName.FOREST_COPY_ANY_FOREST_LOCATION] = [];
gameState.locationsMap[LocationName.FOREST_FOUR_TWIG] = [];

gameState = gameState.next(gameInput);
expect(() => {
gameState.next({
inputType: GameInputType.SELECT_LOCATION,
prevInputType: GameInputType.PLACE_WORKER,
locationContext: LocationName.FOREST_COPY_ANY_FOREST_LOCATION,
locationOptions: Location.byType(LocationType.FOREST).filter(
(loc) => loc != LocationName.FOREST_COPY_ANY_FOREST_LOCATION
),
locationOptions: [LocationName.FOREST_FOUR_TWIG],
clientOptions: {
selectedLocation: LocationName.FOREST_COPY_ANY_FOREST_LOCATION,
},
Expand All @@ -741,22 +740,44 @@ describe("Location", () => {
);
const gameInput = placeWorkerInput(location.name);
gameState.locationsMap[LocationName.FOREST_COPY_ANY_FOREST_LOCATION] = [];
gameState.locationsMap[LocationName.FOREST_FOUR_TWIG] = [];

gameState = gameState.next(gameInput);
expect(() => {
gameState.next({
inputType: GameInputType.SELECT_LOCATION,
prevInputType: GameInputType.PLACE_WORKER,
locationContext: LocationName.FOREST_COPY_ANY_FOREST_LOCATION,
locationOptions: Location.byType(LocationType.FOREST).filter(
(loc) => loc != LocationName.FOREST_COPY_ANY_FOREST_LOCATION
),
locationOptions: [LocationName.FOREST_FOUR_TWIG],
clientOptions: {
selectedLocation: LocationName.BASIC_ONE_BERRY,
},
});
}).to.throwException(/Invalid location selected/i);

expect(player.getNumResourcesByType(ResourceType.BERRY)).to.be(0);
});
it("player cannot copy location that's not in play", () => {
const location = Location.fromName(
LocationName.FOREST_COPY_ANY_FOREST_LOCATION
);
const gameInput = placeWorkerInput(location.name);
gameState.locationsMap[LocationName.FOREST_COPY_ANY_FOREST_LOCATION] = [];
gameState.locationsMap[LocationName.FOREST_FOUR_TWIG] = [];

gameState = gameState.next(gameInput);
expect(() => {
gameState.next({
inputType: GameInputType.SELECT_LOCATION,
prevInputType: GameInputType.PLACE_WORKER,
locationContext: LocationName.FOREST_COPY_ANY_FOREST_LOCATION,
locationOptions: [LocationName.FOREST_FOUR_TWIG],
clientOptions: {
selectedLocation: LocationName.FOREST_ONE_PEBBLE_THREE_CARD,
},
});
}).to.throwException(/Invalid location selected/i);

expect(player.getNumResourcesByType(ResourceType.BERRY)).to.be(0);
});
});
Expand Down
20 changes: 18 additions & 2 deletions src/model/location.ts
Original file line number Diff line number Diff line change
Expand Up @@ -552,13 +552,21 @@ const LOCATION_REGISTRY: Record<LocationName, Location> = {
if (gameInput.inputType === GameInputType.PLACE_WORKER) {
player.drawCards(gameState, 1);

const keys = (Object.keys(
gameState.locationsMap
) as unknown) as LocationName[];

const basicLocations = keys.filter((location) => {
return Location.byType(LocationType.BASIC).indexOf(location) > -1;
});

// Ask player which location they want to copy
gameState.pendingGameInputs.push({
inputType: GameInputType.SELECT_LOCATION,
prevInputType: GameInputType.PLACE_WORKER,
label: "Select basic location to copy",
locationContext: LocationName.FOREST_COPY_BASIC_ONE_CARD,
locationOptions: Location.byType(LocationType.BASIC),
locationOptions: basicLocations,
clientOptions: {
selectedLocation: null,
},
Expand Down Expand Up @@ -1126,13 +1134,21 @@ const LOCATION_REGISTRY: Record<LocationName, Location> = {
playInner: (gameState: GameState, gameInput: GameInput) => {
const player = gameState.getActivePlayer();
if (gameInput.inputType === GameInputType.PLACE_WORKER) {
const keys = (Object.keys(
gameState.locationsMap
) as unknown) as LocationName[];

const forestLocations = keys.filter((location) => {
return Location.byType(LocationType.FOREST).indexOf(location) > 0;
});

// Ask player which location they want to copy
gameState.pendingGameInputs.push({
inputType: GameInputType.SELECT_LOCATION,
prevInputType: GameInputType.PLACE_WORKER,
label: "Select basic location to copy",
locationContext: LocationName.FOREST_COPY_ANY_FOREST_LOCATION,
locationOptions: Location.byType(LocationType.FOREST).filter(
locationOptions: forestLocations.filter(
// filter out this location
(loc) => loc != LocationName.FOREST_COPY_ANY_FOREST_LOCATION
),
Expand Down

0 comments on commit 9e86dec

Please sign in to comment.