Skip to content

Commit

Permalink
Historian: don't draw card if hand is full
Browse files Browse the repository at this point in the history
  • Loading branch information
elynnlee committed Dec 26, 2023
1 parent afefddf commit b502d55
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 5 deletions.
75 changes: 75 additions & 0 deletions src/model/card.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1594,6 +1594,81 @@ describe("Card", () => {
]);
expect(player.numCardsInHand).to.be(0);
});

it("should not draw a card when the player's hand is full", () => {
const cards = [
CardName.KING,
CardName.QUEEN,
CardName.POSTAL_PIGEON,
CardName.POSTAL_PIGEON,
CardName.FARM,
CardName.HUSBAND,
CardName.CHAPEL,
CardName.MONK,
];
gameState = testInitialGameState({ meadowCards: cards });

// card we expect to draw, if we had space in our hand
gameState.deck.addToStack(CardName.WIFE);

// card that will be filled into the meadow
gameState.deck.addToStack(CardName.KING);

const deckLength = gameState.deck.length;

player = gameState.getActivePlayer();

player.addToCity(gameState, CardName.HISTORIAN);
player.addCardToHand(gameState, CardName.WANDERER);
player.addCardToHand(gameState, CardName.WANDERER);
player.addCardToHand(gameState, CardName.WANDERER);
player.addCardToHand(gameState, CardName.WANDERER);
player.addCardToHand(gameState, CardName.WANDERER);
player.addCardToHand(gameState, CardName.WANDERER);
player.addCardToHand(gameState, CardName.WANDERER);
player.addCardToHand(gameState, CardName.WANDERER);

const cardToPlay = Card.fromName(CardName.FARM);
player.gainResources(gameState, cardToPlay.baseCost);

const playCardFromMeadowInput = {
inputType: GameInputType.PLAY_CARD as const,
clientOptions: {
card: CardName.FARM,
fromMeadow: true,
paymentOptions: {
resources: {
[ResourceType.TWIG]: 2,
[ResourceType.RESIN]: 1,
},
},
},
};

[player, gameState] = multiStepGameInputTest(gameState, [
playCardFromMeadowInput,
]);

// check state of player's hand
expect(player.getCardsInHand().indexOf(CardName.WIFE)).to.be.lessThan(
0
);

expect(player.getCardsInHand()).to.eql([
CardName.WANDERER,
CardName.WANDERER,
CardName.WANDERER,
CardName.WANDERER,
CardName.WANDERER,
CardName.WANDERER,
CardName.WANDERER,
CardName.WANDERER,
]);

// expect that 1 card was taken from the deck to replenish meadow
// if a second card had been drawn, we would expect the difference to be 2
expect(gameState.deck.length).to.be(deckLength - 1);
});
});

describe(CardName.HUSBAND, () => {
Expand Down
18 changes: 13 additions & 5 deletions src/model/card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1307,11 +1307,19 @@ const CARD_REGISTRY: Record<CardName, Card> = {
gameInput.inputType === GameInputType.PLAY_CARD &&
gameInput.clientOptions.card !== CardName.HISTORIAN
) {
player.drawCards(gameState, 1);
gameState.addGameLogFromCard(CardName.HISTORIAN, [
player,
` drew 1 CARD.`,
]);
if (player.numCardsInHand >= player.maxHandSize) {
gameState.addGameLogFromCard(CardName.HISTORIAN, [
player,
`already has ${player.maxHandSize} CARD in their hand. `,
`No additional CARD were drawn or discarded`,
]);
} else {
player.drawCards(gameState, 1);
gameState.addGameLogFromCard(CardName.HISTORIAN, [
player,
` drew 1 CARD.`,
]);
}
}
},
}),
Expand Down

0 comments on commit b502d55

Please sign in to comment.