A brige visualizer and recommender for the Yu-Gi-Oh card Small World using graph theory.
Small World is a Yu-Gi-Oh! card which can search any monster in your deck. The idea is that you reveal a card from your hand, reveal a card from your deck with exactly one property in common with your original card, then reveal a third card also with exactly one property in common with the second card, and add that third card to your hand.
In theory, Small World can search any monster from your deck and add it to your hand. However, it may not be possible to bridge a card in your hand to the card that you want to search. The first card you reveal in your deck is referred to as the bridge which connects the card you reveal in your hand and the card you add to your hand.
If you use Small World, it is generally desirable to include one or more dedicated bridges that connects many cards in your deck so you have plenty of options for what to search starting from any card. However, such cards are difficult to find due to the many ways that cards can be considered connected. Because of the difficulty in optimizing a deck for Small World, there is a high barrier of entry to use the card.
The purpose of this repository is to assist in finding the best Small World bridges for any deck, as well as to visualize the connections between cards.
git clone https://github.com/KennethJAllen/ygo-small-world
cd ygo-small-world
- Install UV if not already installed.
- Create the virtual environment:
uv sync
- Activate the Virtual Environment
- Install project
uv pip install -e .
You can now run the project's scripts within the poetry shell.
The graphical user interface can be accessed as a streamlit app: https://smallworld.streamlit.app/
To run Streamlit locally: streamlit run app.py
- The command line interface for interacting with the Yu-Gi-Oh! Small World analysis tools is through
cli.py
. - Takes path to
.ydk
file, outputs bridges, adjacency matrix plot, squared adjacency matrix plot, and graph plot to output path (defaults to./output
) - Example:
py -m cli "data/sample_deck.ydk"
- For a more interactive approach or for example usage, you can utilize demo the Jupyter notebook located in the
examples/demo.ipynb
. - Run
fetch_card_data.py
to update the card data to the latest version if needed. - Alter path to
.ydk
file or update requiored target ids as desired.
The card data cardinfo.json
is obtained from the Yu-Gi-Oh! API.
Consider a Mathmech deck consisting of the monsters
'Ash Blossom & Joyous Spring',
'D.D. Crow',
'Effect Veiler',
'Ghost Belle & Haunted Mansion',
'Mathmech Addition',
'Mathmech Circular',
'Mathmech Diameter',
'Mathmech Multiplication',
'Mathmech Nabla',
'Mathmech Sigma',
'Mathmech Subtraction',
'Nibiru, the Primal Being',
'PSY-Frame Driver',
'PSY-Framegear Gamma'.
Then the graph of connections via Small World can be visualized as follows.
The adjacency matrix corresponding to cards in a Mathmech deck is the following matrix. If an entry is black, that means the corresponding cards connect via Small World. If an entry is white, that means there is no connection.
Squaring the adjacency matrix, we get the following figure. If an entry is non-white, that means that one corresponding card can be searched from the other. The darker the color, the more connecting bridges the two cards have.
Every entry in the column corresponding to Mathmech Circular is non-zero except for the entry corresponding to Mathmech Multiplication, which means that Mathmech Circular can be searched with Small World starting from any monster in the deck except Mathmech Multiplication.
Moreover, the diagonal entries are the number of connections a card has to another card in the deck. The darker the entry, the more connections a card has to other cards in the deck.
The code to generate these figures may be found in the examples/demos.ipynb
notebook.
We can use graph theory to calculate which cards can and cannot be searched via Small World starting from any card.
We can model the cards in a deck as the vertices of an undirected graph
Let
Starting with card
Entry
When using the bridge_generator_examples.ipynb
notebook, there is a bridge_score
output for each potential bridge
More specifically, the bridge score for any particular bridge
In more mathematical terms, consider a potential bridge
The bridge score is calculated as the number of non-zero elements in
Because of the block matrix structure of
Because
Therefore if there are