-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
engine: improved card drawing logic.
this commit handles the drawing logic from an empty cardDeck. - It reshuffles the thrown cards into the card deck when the card deck is empty and a player needs to draw a card. - Also added relevant unit test, in engine.test.ts, to verify this function (drawCardFromDeck) works correctly.
- Loading branch information
1 parent
f05595c
commit be3882e
Showing
2 changed files
with
33 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { GameEngine } from '../uno-game-engine/engine'; | ||
|
||
describe('testing drawCardFromDeck()', () => { | ||
test('draws a card when deck is empty but thrownCards is not', () => { | ||
const game = new GameEngine(); | ||
game.addPlayer({ id: '1', cards: [] }); | ||
game.cardDeck = []; | ||
game.thrownCards = [ | ||
{ | ||
type: 'number', | ||
color: 'yellow', | ||
value: '1', | ||
id: 'card-number-yellow-1-1', | ||
}, | ||
]; | ||
const player = game.players[0]; | ||
game.drawCardFromDeck(player); | ||
expect(player.cards.length).toBe(1); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters