Settings

Theme

Open source rules engine for Magic: The Gathering

github.com

214 points by moxvallix 2 years ago · 84 comments

Reader

archargelod 2 years ago

That's my favourite way to play magic. Real cardboard magic is very expensive hobby. Digital magic (like Mtg Arena) is usually toxic, too competitive and meta-driven for my liking.

So, instead, I enjoy playing against AI. And AI here is actually decent. It can't do combo or play slow control decks well, but with aggro archetypes it's an actual challenge.

If you want to try it - start with Adventure - it is a mode where you get a starter deck and go into the open world to explore and challenge other planeswalkers. You earn cards and gold that can be spent on more cards. It's fun because you don't get stuck playing the same best cards over and over. All cards from a long magic history are available and have equal chances to show up in rewards. It takes a skill to build a deck from pile of random variable quality cards. But, oh boy, does it feel good when you get good at it.

  • 542458 2 years ago

    I mostly play commander, and find the AI to be pretty dumb to be honest. That’s not saying it’s not fun! But I find that even with the AI using simple deck archetypes I usually have to put three of them on an enemy team before they hit moderately-skilled-human-player levels of challenge. The AI is pretty bad at threat assessment, so removal, counters and board wipes get used pretty randomly sometimes.

    • archargelod 2 years ago

      If you want to feel more challenge - try the "experimental" difficulty level for opponents. And maybe enable AI cheating (they would see cards in your hand).

      Normally, I believe, AI can blunder or miss some triggers. But with these settings they'll try to play more optimally.

  • grensley 2 years ago

    How is Arena toxic? There's basically no opportunity for the players to converse besides bland preset options which rarely even gets used outside of a greeting at the start of the game.

    • archargelod 2 years ago

      Toxic as in the toxic play styles: turn 3 kills, decks that you wouldn't bring to play in person casually, games where you have near zero chances to win unless you play one of 3 meta decks. Also, I found BM (usually time wasting) is a lot more common on Arena than in other games I play (e.g. Hearthstone).

  • piyh 2 years ago

    Playing face to face with friends is the best part of magic.

    I've proxied 30+ edh decks on my laser printer. I still money on real cards, but increasing my kitchen table meta diversity with proxies was a great move. Building infinite budget Slivers, having perfect mana bases, and exploring jank to cedh power levels are what I've wanted from this game all my life.

    • water-data-dude 2 years ago

      I’ve done the same thing. I’ll eventually buy the cards, but I don’t want to buy cards, playtest the deck, and then find out that I want to replace this slightly expensive card with this other slightly expensive card. My friends are ok with playing against a proxied deck, in part because I keep the overall price of the deck reasonable (since eventually I’ll probably buy the cards if the deck isn’t an absolute dog).

      I made my proxies with some card-stock with a grammage of 300 g/m^2 which is roughly what MTG cards have (had to grab a big pack from a craft store, but that’s ok since I’ll find a use for the rest). I have a guillotine paper cutter, which made things a LOT easier than when I did this in college, and I also had a little corner-rounder-punch thing that made the final product look way better than expected. I have an inkjet printer, so they didn’t look perfect or anything, but they still looked a lot better than expected! And when they were in sleeves the “feel” was pretty close too!

    • PNewling 2 years ago

      Woah, did you have to hand cut all of those decks or how did you do that?

      • piyh 2 years ago

        I did it by hand with a scissors. I was losing my sanity every night for months trying to keep my newborn from crying. Printing tons of decks, cutting and sleeving was the kind of thoughtless work that fit in that time period.

      • starkparker 2 years ago

        Can't speak to OP but a Cricut or budget equivalent cardstock cutter is a M:tG hacker's best friend. That and an unlimited supply of Modge Podge.

        A guillotine or rotary cutter and corner punch are probably faster but nothing's more satisfying than a whole deck of precision cut cards.

  • Buttons840 2 years ago

    My approach to an AI for MTG would be to not even pretend to play by the same rules, just make a series of challenges the player can face with their deck, Slay the Spire style. Like, one challenge the Computer adds 2 "Zombies" each turn and attacks, next challenge the Computer plays a random arc-bound card and each card on the table has a 50% chance to attack, etc, etc.

    Players can build their decks and then see how far they can get through the challenges.

  • ncallaway 2 years ago

    Are there any… archives of past MtG games or tournaments? Is there a standard format for recording a draft and a game of magic?

    Curious if there’s any existing data to start training AIs on, or if these are more of the classic build an AI approach

    • everforward 2 years ago

      XMage has a JSON output format, but last I looked it was difficult to parse. The potential effects for Magic are so vast it's extremely difficult to find a sane structured format to record things in, so the JSON format is mostly a couple of identifying fields and a string describing what happened (ie. Source was this permanent, target was this player, what happened is a giant string field).

    • freeone3000 2 years ago

      There’s lots of footage of games, and programs like 17lands to extract games you have played from the arena log, and commentary of games… but no easy-to-ingest recordings

  • JoshTriplett 2 years ago

    > Digital magic (like Mtg Arena) is usually toxic, too competitive and meta-driven for my liking.

    I found that Gatherer had a much more friendly environment. If you take a land-destruction or a counter/permission deck into a game there, folks will just resign when they realize what kind of deck you're playing, and word will get around to not play with you unless you change decks. It's more the kind of environment where you can play a fun, decent, creative deck, and have a good time with other folks doing the same.

  • echelon 2 years ago

    > toxic

    I hear this about a lot of gaming communities. Smash, Xbox, any FPS.

    Why does this happen? How and to what degree does it manifest? How do you avoid it?

    • loveiswork 2 years ago

      > Why does this happen?

      A blend of anonymity, low self-soothing ability, human instinct to talk trash during competition, people tying identity to performance, skew towards younger people playing, etc.

      > How and to what degree does it manifest?

      How? Mostly through voice and chat systems in-game. Also through quitting the game, or blatantly "throwing" a match.

      To what degree? From "You suck" to racial slurs to harm yourself. It's ubiquitous across competitive games -- you'll probably experience it every session.

      > How do you avoid it?

      The best way is to find a consistent group of folks to play with. Stay away from "random queue". Certain games you can turn off chat features, submit reports, etc. You can also just ignore it and accept it as part of the thing.

      • tedunangst 2 years ago

        There's really very little one can do to be "toxic" in mtg arena, outside playing a control deck, which is clearly part of the game or they'd stop making counterspells. "Arena is toxic" means "I lost".

        • wredcoll 2 years ago

          It's funny how biased against "playing to win" hacker news frequently is. On one article you'll have dozens of people arguing that a company is legally allowed to hurt people and therefor they should, then the next comment section everyone is complaining about losing in a game of mtg.

        • tstrimple 2 years ago

          Only toxicity possible is roping which definitely gets annoying. WOTC should crack down on serial ropers. They certainly have the stats to be able to do this.

    • npteljes 2 years ago

      I'd like to answer on the handling part. Handling it really depends on the game / community itself. I play Rainbow 6 Siege online, it's 10 people per match, in two teams. Most toxicity is easily avoided, because I only allow chat and voice from teammates (default setting), and if someone is toxic, it's very easy to block their chat, or voice. Killing teammates only succeeds once, then the TK-er's friendly fire will actually hurt the player itself, not the teammate, and this, if repeated, even propagates from match to match. This status is reflected with a red marker for everyone to see in a match. There's also a ticker on the top right where they sometimes show the names of a bunch of cheaters, griefers, or other toxic elements, after banning their accounts.

      I wouldn't even restrict the toxicity conversation to gaming, or to online communities even. Whenever people interact, there can be toxicity. The main factor is usually the interaction setup itself. If that is handled well, the effects of toxic actors is manageably minimal. If the system lets them proliferate, they will. Gaming the system's toxicity management behavior is also a sport in itself. Communities can be even set up to explicitly allow the behavior, acknowledging the existence of this pursuit and making it plain to see that it will happen.

    • moate 2 years ago

      If you want to avoid toxic behavior in your game, don’t allow multiplayer.

      Some people will always be shitty, some people will want to play your game, and some number of people will meet both those criteria. The only way to fix it is after the fact, but there’s no way to avoid it.

      As to the “how and to what degree” depends on the game and the type of person it attracts. The second something is competitive, toxicity is inevitable because many people take losing personally.

      • akerl_ 2 years ago

        Imagine if we took this approach outside of gaming.

        “If you want to avoid toxic behavior at your workplace, don’t get a job”.

        We should be building systems and environments that can sustain interpersonal interaction while combatting toxicity.

        • moate 2 years ago

          The better allegory (and actual advice that might be useful): If you want to avoid a toxic workplace, work by yourself.

          Now, that said I’m being specifically pedantic: these are steps to AVOID toxic environments. To COMBAT toxicity is a whole other problem with way too many variables. I went for the solvable problem.

    • vmilner 2 years ago

      Even playing bridge (card game) with random people online can be pretty grim, though playing online games organised by some national authority (eg the English Bridge Union) is a lot better.

  • prepend 2 years ago

    Has anyone recreated Shandalar in this engine?

    • archargelod 2 years ago

      The adventure mode is basically the Shandalar. It was added only a couple years ago by a single developer[0]. But it had excellent support since, especially in 2023. And right now it's very feature-rich with a lot of dungeons, bosses, artifacts, simple quest system, etc. New stuff comes out every month.

      [0] - https://www.slightlymagic.net/forum/viewtopic.php?f=26&t=304...

      • falsaberN1 2 years ago

        Not quite, there was another developer that quietly made a lot of work in the time he was around, after Grimm just vanished shortly after those posts, and basically left the entire thing in an usable state for later. Unfortunately he left after a series of personal tragedies that rendered him unable to function for a while.

        That guy never gets any credit which is rather sad. I really don't know how he still has a will to live after all that has happened to him.

mdaniel 2 years ago

In case anyone is curious, it uses Scryfall for the card art https://github.com/Card-Forge/forge/blob/forge-1.6.59/forge-... and I wish they'd offer a torrent (or IPFS) because I can't imagine the amount of bandwidth it must cost them and I would seed the hell out of any such thing

Now, one possible reason would be copyright something-something but as it currently stands it's not like one needs to log in to download the card art one at a time, so ... I struggle to think of what risk they're driving down

j_m_b 2 years ago

Great to see Forge making the front page! It runs on mobile too and the UI is frankly better than the desktop version. Definitely install a snapshot version so that your client stays up to date. The bots can play surprisingly well with agro and even control decks, but can't play any kind of combo... Or even assemble Tron.

I've even used this to play local network games against other players. If they had a global server that allowed you to find games, it would be the perfect way to play MtG.

sigma5 2 years ago

There is also Xmage https://github.com/magefree/mage

khaki54 2 years ago

Is the adventure mode like that old Microprose Magic the Gathering game? My brother and I loved playing that as kids!

yowlingcat 2 years ago

I've played a lot of Hearthstone over the past decade, and one thing that I've loved about it is Battlegrounds, to the extent where I have stopped playing the traditional meta where you have to build actual decks. Battlegrounds is somewhat similar to the draft meta in MtG and YGO where on a turn by turn basis, you get selection of cards to draft, but with a certain economic limit of cards to pull. It corrects for "buying" your way in and instead focuses ELO on ramping correctly and inflects an RTS flavor on the game. I enjoy it a lot and I kinda wonder why such a flavor on gameplay hasn't similarly taken hold of the other classic CCGs. What am I missing or misunderstanding?

mdaniel 2 years ago

It must be M:TG week, which I think is fantastic!

https://news.ycombinator.com/item?id=38646892 is the I guess annual(?) repost of the "Magic: The Gathering Is Turing Complete (2019)" paper

and then there were some other M:TG threads that may interest those who didn't see them

https://news.ycombinator.com/item?id=38525978 (I hacked Magic the Gathering: Arena for a 100% win rate)

https://news.ycombinator.com/item?id=38533105 (Fine-tuning Mistral 7B on Magic the Gathering Draft)

  • moxvallixOP 2 years ago

    It was actually the turing complete post that reminded me of this project, hence why I posted it here.

    Honestly surprised it hadn’t really been posted on HN before (afaict from search).

Waterluvian 2 years ago

Oh this is a gold mine for me. Recently I’ve wondered how games architect card game rules. So many rules feel kind of bespoke, so I wasn’t sure if you could implement a sort of logic so that rules become configuration, or if each rule is just a function.

  • Daegalus 2 years ago

    You might enjoy this official article on a bug in Arena rules engine that goes into how they designed their systems.

    https://magic.wizards.com/en/news/mtg-arena/on-whiteboards-n...

    • LelouBil 2 years ago

      > Now we come to the other program that we rules engineers spend our time working on, along with the GRE, which is the Game Rules Parser (GRP). This program (written in Python) takes raw English rules text of Magic cards and converts them into one or more CLIPS rules. It's what allows 80% or so of newly written Magic cards to just work in MTG Arena automatically.

      Wow, didn't even think about this being a possibility! But I guess if they have a very strict dictionary and grammar rules for card effects this kind of thing can work !

      • moate 2 years ago

        Tons of creatures with only evergreen/deciduous abilities would probably be super easy to template for something to parse, as would most lands.

        80% feels “right” as someone who’s done some game design in the tabletop space.

        • OskarS 2 years ago

          Yeah, obviously a creature with Haste or Trample or whatever is very easy to make a simple parser for. But I can imagine because WotC is so strict on how they word text on cards, even more advanced interactions would be pretty straight-forward to parse. Like, if a card says:

          "When <card name> enters the battlefield, return target non-land card from your graveyard to your hand".

          Both parts of that sentence is always worded the same, so it's probably quite straight-forward to make a parser for this: just have a parse rule for "When <card name> enters the battlefield, <triggered ability X>", with a database of triggered abilities (and their implementation) that include all the ones that have already been printed.

    • mdaniel 2 years ago

      That's interesting, thank you. It seems what's old is new again: I had a lot of contact with CLIPS early in my career but I found that most of the programming tasks weren't heavy rules based as much as CRUD and reporting apps. Given that Forge is in Java, they may enjoy Drools <https://github.com/apache/incubator-kie-drools#readme> (which used to be a JBoss project but I guess has been donated to the Apache Foundation)

LelouBil 2 years ago

Here is an equivalent for Yu-Gi-Oh!

https://github.com/edo9300/ygopro-core

I find the CardScript repository very interesting to look at: https://github.com/ProjectIgnis/CardScripts

And here is the actual game client :

https://github.com/edo9300/edopro

THENATHE 2 years ago

Has anyone actually tried the network multiplayer? I won't have a chance to try this out for a while, but if there is now a great way for me to play actual commander with the MTGA rules engine (for speed and accuracy) with friends I would love this so much. Can anyone share their experiences?

ryanbigg 2 years ago

I’ve done some work on something “less serious” in Ruby:

https://github.com/radar/mtg

I view it as a wide project full of little interlinked code katas.

I’ve thought about the card parsing stuff but that’s beyond my ability.

freediver 2 years ago

Oh neat, would get us much closer to having a 'best deck simulator' like this:

https://www.youtube.com/watch?v=Xq4T44EvPvo

7373737373 2 years ago

Has anyone tried simulating the Turing complete deck? https://youtu.be/pdmODVYPDLA

spartanatreyu 2 years ago

Man I used to play this engine and Battle for Wesnoth 10 years ago back when I had intermittent internet.

I thought the project died, glad to see it's still going!

pdntspa 2 years ago

Wow, if this is what I think it was I remember using this to play MTG online vs some friends waaaaaaaaaaaaay back in the day. This was/is a really good alternative to MTGO

edit- It is!

Yhippa 2 years ago

Want to play any Commander deck with friends on the cheap? Spelltable + OBS (or any desktop streaming software) + Moxfield in deck playtest mode.

agazso 2 years ago

I downloaded this and it looks cool and comprehensive, but for me the card artwork is missing.

Maybe some server is hugged by HN? Or something needs to be set?

  • 542458 2 years ago

    It’s a bit unintuitive, but IIRC you need to go into the settings and tell it to download the card art. Two reasons for this: 1, copyright and 2, it’s a big download if you get them at full quality.

    • agazso 2 years ago

      Thanks, I found it in the 'Content Downloaders' menu!

      It estimates the download time to 6 hours, and it's not because of the size but most likely their server works slowly. And in the meanwhile it does not let you play, well tomorrow then :)

      • Marthinwurer 2 years ago

        There's a setting somewhere to auto download cards when they're seen. That should get you up and running quicker!

bhickey 2 years ago

How does it compare with Xmage and cockatrice?

  • archargelod 2 years ago

    It's similar to Xmage, but with heavy leaning into PVE.

    There are around a dozen original modes to play against AI opponents: Adventure (à la Shandalar 1997), Quest, Planar Conquest, Gauntlet, Puzzles. Plus practically every somewhat popular format, including digital-only: Momir from Shandalar, Drafts, Sealed, Cube, Commander, Oathbreaker, Brawl, Archenemy, etc. etc.

    There's a way to setup online multiplayer games, but no hubs or rooms like in Xmage. It's also somewhat under-utilised feature and therefore not so well supported.

    I haven't actually tried cockatrice, but I believe it's more like a tabletop simulator, e.g. you have to shuffle, draw, and play the game almost manually? Forge is completely automatic like Xmage, Shandalar and Magic Online. It also could be a fun way to learn the rules of the game.

7373737373 2 years ago

Would it be possible to apply MuZero to this?

  • mdaniel 2 years ago

    I went looking for MuZero implementations in order to see how, exactly, they interact with the game space. Based on this one, which had the most stars in the muzero topic, it appears that it needs to be able to discern legal next steps from the current game state https://github.com/werner-duvaud/muzero-general/blob/master/...

    So, I guess for the cards Forge has implemented one could MuZero it, but I believe it's a bit chicken and egg with a "free text" game like M:TG -- in order to train one would need to know legal steps for any random game state, but in order to have legal steps one would need to be able to read and interpret English rules and card text

    • piyh 2 years ago

      I was floated the idea of doing an AI competition for Sabberstone, the open source rules engine for Hearthstone. Even though Hearthstone is hugely limited in game complexity compared to MtG, building an interface for a program to take actions in Sabberstone and evaluate boardstates is not trivial.

EE84M3i 2 years ago

This is cool, but I'm a bit surprised this isn't AGPL.

mnky9800n 2 years ago

There should be a screenshot on the homepage to show what gameplay is like

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection