-
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. - It returns success message if the card is drawn successfully else returns message error. - Also added relevant unit test, in engine.test.ts, to verify this function (drawCardFromDeck) works correctly.
- Loading branch information
1 parent
2e865b9
commit ad77ddb
Showing
2 changed files
with
51 additions
and
6 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,21 @@ | ||
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]; | ||
const status: EventResult = game.drawCardFromDeck(player); | ||
expect(player.cards.length).toBe(1); | ||
expect(status.type).toBe('SUCCESS'); | ||
}); | ||
}); |
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