Skip to content

ferthus/example-code-challenges-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Code challenge: TCG Booster Pack Opener

Challenge description:

In this challenge, you will create the logic for a Trading Card Game (TCG) where players can open booster packs to enhance their deck.

On TCG games, cards are grouped by collections that are groups of cards that belong together, usually sharing a common theme or set.

Booster packs are sealed packs that contains a fixed number of cards from a single collection, which players can open to obtain new cards for their deck.

Cards are assigned to booster packs based on specific probability rules and rarity constraints.

Your task is to write a function that simulates the opening of a booster pack for an online TCG game and assigns cards according to the given rules.

Objective:

Write a service in Python that:

  1. Simulates the opening of a booster pack.
  2. Assigns cards to the player based on predefined probabilities, rarity constraints, and specific rules regarding card types and collections.

Definitions:

Card Types:

  • Character card: Cards with a playable character, they have a rarity defined by the number of stars (1 to 5 stars) printed on the card.
  • Equipment card: Cards with upgrades that can be equiped to character cards, they do not have star ratings.

Rarity probabilities for character cards:

  • 5 stars: 0.5%
  • 4 stars: 3.5%
  • 3 stars: 16%
  • 2 stars: 30%
  • 1 star: 50%

Booster pack rules:

  1. Each booster pack contains exactly 8 cards.
  2. A booster pack can only contain cards from a single collection.
  3. Each booster pack must have exactly one equipment card and seven character cards.
  4. Each booster pack is guaranteed to contain at least one character card of 3 stars or higher.
  5. Each booster pack can contain at most one 5-star character card.
  6. Each booster pack can contain up to three character cards of 3 to 5 stars.
  7. The remaining character cards must be of 1 or 2 stars.

Required classes:

  1. Card: Represents a card in the game.
  2. Collection: Represents a collection of cards and provides methods to access the cards that belongs to it.
  3. BoosterPackOpener: A service that defines the open_booster_pack() method, which takes an instance of the Collection class as argument and returns a list of the cards assiged to the booster pack according to the described rules.

Guidelines:

  1. Define the Card and Collection classes.
  2. Implement the BoosterPackOpener service class to generate a booster pack of cards according to the rules.
  3. Ensure the open_booster_pack() method respects the minimum and maximum constraints for each rarity type and card type.
  4. The open_booster_pack() method should return a list of card types and rarities that make up the booster pack.
  5. Only standard Python library packages can be used to implement the solution. No external libraries are allowed.
  6. The solution must include the necessary unit tests to assert the code works as expected. Tests should be written using pytest, the pytest-mock and pytest-cov libraries are allowed to be used. Tests must cover 100% of the implemented code.

Instructions:

  1. Create a fork of this repo.
  2. Clone yout fork to your local development environment.
  3. Create a new branch were you'll implement your solution.
  4. Commit and push your code to the branch you have created.
  5. Open a Pull Request from your fork to this repository with your solution for the challenge.
  6. Write an explanation of your solution in the description of the Pull Request to allow reviewers to understand what you've done.
  7. Reviewers will add comments to your Pull Request asking specific questions of your solution, please make sure to answer comments and elaborate where necessary.

About

Code challenge: TCG Booster Pack Opener

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages