Package: azusa
AzusaMTG Curve helps Magic: the Gathering players estimate the amount of mana they will have on a specific turn. It is primarily geared towards EDH/Commander players, but will hopefully be generic enough to support other formats in the future.InstallationWe are on Pypi, so all you have to do is:pip install azusaIf you are wanting to use the web app, install with thewebappopion:pip install 'azusa[webapp]'When running the webclient, you'll need to enable local computation, which unlocks multi-processing. To do this, add the following line to your.bashrcfile:export AZUSA_LOCAL=1UsageFirst, build a deck on Moxfield. Then copy the url of the deck and run:python -m azusa https://www.moxfield.com/decks/IlUDC5c-MUejd0psQ6HNoAreplacing the above url with your own. It may take some time to run, as more mana producing cards and higher max turn parameters will provide exponential effects to runtime. Additionally,python -m azusa --helpwill display additional arguments that can be tuned.If you want the web application experience, ensure that you installed with the extra dependencies and then run:streamlit run azusa/client.pyVocabularyThe explanations in this document assume familiarity with Magic the Gathering terms. In addition to these terms, we describe two additional terms:Amana producer, orproducer, ramps the player by at least one mana in some way. This includes mana rocks, mana dorks, land fetch effects (like Rampant Growth, not actual fetch lands), etc.Cards that are not lands nor producers are termed asother.MethodThis estimator works by performing a tree search and assigning probability from each starting hand. Each starting hand has a number of land cards, mana producing card (i.e. dorks or mana rocks), and then other cards. Given a starting hand, the following gives the probability of any specific hand:.After an initial hand is generated, a tree search is performed to account for the probabilities that come from drawing cards at the beginning of a turn. Turn actions are performed according to a heuristic. When the search tree has finished, it moves on to the next hand. This process has further been multi-threaded allowing multiple hands to be considered at a time.ComplexityThis package performs a tree search per hand, which is bounded bytime, so be careful in defining the maximum number of turns and realize that the more producers included in the decklist, the longer this method will take. Further, the number of starting hands is:, so be careful of running with a high number of turns and mana producers. This bound will be lowered in practice when equivalent mana producers are grouped, e.g. Llanowar Elves and Fyndhorn Elves.AssumptionsThere are a few assumptions that are made to make this project possible:All lands are basic. Currently, all lands are assumed to be basic lands. While future versions may allow for tapped lands, this assumption feels fine and is close to how the on-curve estimator of Moxfield functions.All mana costs are generic. Future iterations could support specific casting costs, however it is too expensive for the time being.Every turn, we try to make the mana-optimal play. That is, every card we play is a mana producer. This tool does not take into account holding mana open for counterspells or any other reasons. That being said, the 'mana-optimal' play would require more search and would depend on which CMC was most important. Future versions may include other heuristics like this and if you would like to contribute one, please look submitting a pull request.Enchantments like Wild Growth and Utopia Sprawl take a turn to activate. This will be fixed in a future iteration that will check the number of lands in play when these are cast.ContributionsContributions are heavily encouraged! Even if you don't have much experience with Python, there is a lot of work to be done on this project. If you have any suggestions or contributions, please go ahead and open a Github Issue or submit a Pull Request.Appendix A: Probability of each starting handSuppose we have a library with c cards at the beginning of the game. For a commander deck with one commander, c would be 99. Let us suppose that there are n lands in the deck, s mana producers, and u other cards. We can formulate the total number of possible opening hands without mulligaining as:This can be expanded usingVandermonde's Identityto first break up the lands from the rest of the library:Then, we can break apart the mana producers from the other cards in the library:Finally, if we consider each possible combination of mana producers separately, we can assign each starting hand withequivalent combinations. Therefore, the probability of each drawing each starting hand is:Appendix B: Performing probability calculationsThere is an issue with calculating the probability of a starting hand:.
The issue is that each term of the expression can, and does, grow to be quite large. To solve this problem, we perform most of the calculations in log space:This reduces large multiplications and divisions to simple arithmatic once the log of each term has been calculated.