Building notes: I can't stop playing Slay the Spire (send help) and so I must program something in Python
Justifying my time wasted by making a short and sweet Python project.
There’s this card game that I love playing on my phone called Slay the Spire (You can also play on your computer). It’s a rogue-lite game where your character must climb a tower, and each floor generally has a monster that you must defeat. Other times, you have some silly random events. Being a card game, you will collect and organize your cards to defeat the great evilbeing inside the tower itself:
It’s a weirdly addicting game that has a lot of strategic depth with different build styles, because the tower will be randomized each time. Different cards, different bosses, and different events.
However, the core mechanics largely remain the same. You draw 5 cards, and when your draw pile has no more cards left, the discard pile is shuffled. For most cards in the game, your card can be upgraded permanently by smithing at the campfire. Doing a battle, you can upgrade the cards temporarily by using a card called Armaments (upgraded version):
It’s a somewhat useful early game card in that for this combat, all the cards in your hand (NOTE: not your entire deck) will be upgraded. So if you have a low number of cards, you can theoretically upgrade your entire deck which is useful because you have more defense and offense. So I just had a fun question: how many turns until my entire deck is upgraded? How does this increase with the total number of cards that you have. Again a Python project (I am starting to get a little bit more comfortable with Python)
Attack Plan
So I coded this in Python using NumPy! Here, depending on how many cards I have in my deck (generally between 10 and 35 in a single run), I generated all of these cards into an array, and their index is their unique identifier. The first column is this index, while the second column checks the status of the cards. If it’s 1, that means the card has been upgraded, while if it’s 0, it’s just the standard card.
matrix = np.column_stack((np.arange(n_size), np.array([1] + [0]*(n_size-1))))
Note that I made the first card (0 index) the upgrade card and it’s already upgraded.
Here’s a schematic that I made to describe what I’m doing:
Draw 5 cards from your draw file
If you draw the 0 card, upgrade all the cards in your hands! This will have the status of the card changed in the array (end of Turn 1). These cards are then put in the discard pile
Draw the next 5 cards. Because these cards will not have 0, no card will be upgraded and these are also discarded (end of Turn 2)
If there are not enough cards to make up 5 cards in your hand, take all the available cards in the draw pile. Then take your discard pile and shuffle it! Pull out enough cards to finish having 5 in your hand (end of Turn 3).
Note just because you pull an upgraded card, does not mean that the card will be upgraded. Only when you pull the 0 card, will the cards update!
Keep doing this until ALL cards are upgraded and record the number of times.
Keep going, recording the number of turns
So I did this! I increased the number of cards in your total deck and ran 1,000 trials to see how many turns it would take for the entire deck to be upgraded. Here, I made a plot. For the total number of cards in the deck (x-axis), I counted the total number of turns until all cards in your deck were upgraded (y-axis). Each point represents one of the 1,000 replicates. The red points show the average.
This shows why Armaments is a useful early-game card. You can upgrade your deck in a small number of turns if you don’t have many cards. However, as you increase the total number of cards in your deck (which will happen naturally as you go up the tower), it takes more turns for Armaments to upgrade all the cards in the deck. It’s considered a noob trap card because of this exact scenario.
I really love Slay the Spire, and I think there are already a lot of interesting data projects you can do with it! Also it’s a fun thing to have when you’re on the Subway or when you have some minutes of down time.
Here’s the GitHub for it!