Skip to main content

Probability estimator for being on curve in mtg

Project description

Azusa

Open in Streamlit Python PyPI Status License

MTG 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.

Installation

We are on Pypi, so all you have to do is:

pip install azusa

If you are wanting to use the web app, install with the webapp opion:

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 .bashrc file:

export AZUSA_LOCAL=1

Usage

First, build a deck on Moxfield. Then copy the url of the deck and run:

python -m azusa https://www.moxfield.com/decks/IlUDC5c-MUejd0psQ6HNoA

replacing 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 --help will 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.py

Vocabulary

The explanations in this document assume familiarity with Magic the Gathering terms. In addition to these terms, we describe two additional terms:

  1. A mana producer, or producer, 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.
  2. Cards that are not lands nor producers are termed as other.

Method

This 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.

Complexity

This package performs a tree search per hand, which is bounded by time, 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.

Assumptions

There are a few assumptions that are made to make this project possible:

  1. 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.
  2. All mana costs are generic. Future iterations could support specific casting costs, however it is too expensive for the time being.
  3. 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.
  4. 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.

Contributions

Contributions 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 hand

Suppose 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 using Vandermonde's Identity to 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 with equivalent combinations. Therefore, the probability of each drawing each starting hand is:

Appendix B: Performing probability calculations

There 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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

azusa-0.1.7.tar.gz (19.5 kB view details)

Uploaded Source

File details

Details for the file azusa-0.1.7.tar.gz.

File metadata

  • Download URL: azusa-0.1.7.tar.gz
  • Upload date:
  • Size: 19.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.0 importlib_metadata/3.7.3 packaging/20.9 pkginfo/1.7.0 requests/2.25.0 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.7.4

File hashes

Hashes for azusa-0.1.7.tar.gz
Algorithm Hash digest
SHA256 b52c6de1b67c49c4bf2edd6d4aca904add61501d63c52bafb1abba4d3c7e603d
MD5 5d5f84ec9ce8f4c184b23c928d621791
BLAKE2b-256 bcfd2024d48b6555051b569d7028dff97c5a0ef7b8ad88fd9eab3b277c6f2d0e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page