0% found this document useful (0 votes)
47 views

Development Challenge

The document describes a programming challenge to create a card game for 2 players. It provides instructions to implement the following tasks: 1. Create a shuffled deck of 40 cards numbered 1-10 and deal 20 cards to each player. 2. Players draw cards each turn until they have no cards left, at which point their discard pile is shuffled to become their new draw pile. 3. Players compare drawn cards each turn, highest number wins both cards, ties result in both players winning on the next turn. 4. The program outputs each play including cards drawn and winner, and finally announces the overall winner.

Uploaded by

Jamal Pasha
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views

Development Challenge

The document describes a programming challenge to create a card game for 2 players. It provides instructions to implement the following tasks: 1. Create a shuffled deck of 40 cards numbered 1-10 and deal 20 cards to each player. 2. Players draw cards each turn until they have no cards left, at which point their discard pile is shuffled to become their new draw pile. 3. Players compare drawn cards each turn, highest number wins both cards, ties result in both players winning on the next turn. 4. The program outputs each play including cards drawn and winner, and finally announces the overall winner.

Uploaded by

Jamal Pasha
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Programming Challenge: Card Game

Introduction
You are building a card game for 2 players. Use any of programming language you feel comfortable with.
Please include the source code as well as instructions on how to compile and run the game in your
submission. The rules of the game are listed below and split into tasks. For each tasks, please implement
the indicated unit-tests. If you are struggling to complete the challenge, it is okay to submit a solution that
does not solve all tasks. The order of tasks is just a suggestion, feel free to implement in whatever order you
see fit. Please do not spend more than 4 hours on this challenge.
Task 1: Create a shuffled deck of cards
Each card shows a number from 1 to 10. Each number is in the deck four times for a total of 40 cards. At the
beginning of the game, the deck is shuffled (Hint: Look up Fisher-Yates Shuffle Algorithm) to
make sure it is in a random order. Each player receives a stack of 20 cards from the shuffled deck as their
draw pile. The draw pile is kept face-down in front of the player. Each player also keeps a discard pile (see
"Task 3" for more). Tests:
. A new deck should contain 40 cards
. A shuffle function should shuffle a deck
Hint: Consider mocking Math.random() or the equivalent of your chosen language
Task 2: Draw cards
Each turn, both players draw the top card. If there are no more cards in the draw pile, shuffle the discard
pile and use those cards as the new draw pile. Once a player has no cards in either their draw or discard
pile, that player loses. Test: If a player with an empty draw pile tries to draw a card, the discard pile is
shuffled into the draw pile
Task 3: Playing a turn
The players present their drawn card and compare the values. The player with the higher value card, takes
both cards and adds them to their discard pile, next to the draw pile. If the cards show the same value, the
winner of the next turn wins these cards as well Hint: The game will likely result in a stalemate, if this rule is
not implemented. Tests:
. When comparing two cards, the higher card should win
. When comparing two cards of the same value, the winner of the next round should win 4 cards
Task 4: Console Output
Your program should output the cards that are played each turn and who wins. At the end the program
should output the player that won.
Example output:
Player 1 (20 cards): 8
Player 2 (20 cards): 1
Player 1 wins this round

Player 1 (21 cards): 1


Player 2 (19 cards): 10
Player 2 wins this round

[...]

Player 1 (38 cards): 4


Player 2 (2 cards): 4
No winner in this round

Player 1 (37 cards): 7


Player 2 (1 cards): 3
Player 1 wins this round

Player 1 wins the game!

You might also like