A Super-Swiss pairing algorithm for casual Magic: The Gathering leagues.
At my workplace, we have a recurring Magic: the Gathering sealed league. A problem we faced was that people needed flexibility to play varying numbers of matches. We also wanted to maintain the benefits of Swiss pairings.
This software uses the min-weight graph matching to assign matches in a way that respects requested numbers of matches while minimizing differences in win-percentage among the pairings. It can post those pairings directly to a Google sheet that is specifically formatted.
pip install -r requirements.txt
To connect to a spreadsheet for automatic import and export, you'll need a Google Cloud project with a service account. Then we'll download its credentials.
-
Select or create a Cloud project. https://console.cloud.google.com/project
-
Enable Sheets API and Drive API at https://console.cloud.google.com/apis/library . Search for "Sheets", then separately "Drive", and enable each.
-
Now go to https://console.cloud.google.com/apis/credentials . If you don't have a dedicated service account for this exact purpose yet (posting pairings), create one through
Create credentials > Server account
. -
Select your service account from the
Service accounts
section.- Navigate to the
KEYS
tab. - Select
ADD KEY
andCreate new key
to download a credentials file in JSON format.
- Navigate to the
-
Save that file in the project root directory as
credentials.json
. -
Give the account write access to the league Sheet through Google Sheets's sharing interface by sharing it with the email address found in
credentials.json
underclient_email
.
The most common invocation:
python swiss.py <set code> <cycle number> -w
or --helpshort
for all the options.
The cells from which to read past pairings and to which to post new pairings are
hard-coded in sheet_manager.py
. You can use this template sheet to track
your own league, or adapt sheet_manager
to use ranges appropriate to an
existing sheet.