2017-06-22 03:03:27

hello, I have played magic for a while by brailling card sleeves, and I heard about a game for the computer and phone that
are not accessible. I wanted to build an accessible magic the gathering game for the computer. Unless someone knows of a project that is updated already and provides a good experience for playing magic?

Otherwise, I am looking at building this in java, and I wanted some ideas of how to manage the cards. I found a java library that can pull down all of the card info for each card, but I would still have to write the methods for each card class to make the card's abilities interact with the rest of the game. For example, if a card effect says when this card enters battle tap 3 creatures, I will have to build a method in that card class to perform that action. This would be a very tedious process to do for all of the magic cards even just in standard.

I currently have a hierarchy of classes, starting with a generic Card class, then defining a cardType, such as a creature, land, instant etc... This way I can create all of my getters and setters for my cards and just inherit those methods.

So, does anyone have any good ideas of how to speed up this process?

TJ Breitenfeldt

2017-06-22 10:29:39

Hi,

great idea, but unsolveable IMHO. Experience shows that people tend to drop ideas and stop working on projects they don't see results coming from, and this one is definitely one of those projects.
I know of cockatrice, a table top simulator which also knows magic, but it's really simple-minded and it nearly only provides the table view, everything else (gaining and losing lp, playing cards and putting them into exile and such stuff) needs to be done by the player himself.
The only currently active project of this calibre might be YGOPro, which assembles the game engine for Yu-Gi-Oh and contains all cards available today. That's possible due to a very simple lua engine sitting under the hood and assembling the effects of the card, so people with less programming skills just have to think of a card with a nearly identical effect, take a look at this cards script and more or less copy it over to the new card, place the lua file into the engine and tada, magic's done. The work here splits up into two parts, the developer himself improving and extending the gaming engine himself and the community throwing the card effect scripts together and maybe setting up a nice launcher with community functions for it, like DevPro does.
So that's it, try taking some of those ideas for your project, but honestly, I don't think that one person alone will ever make such a project possible, not with allavailable cards.
Best Regards.
Hijacker

2017-06-22 14:57:35

I like the idea of an accessible MTG game a lot. I'd be interested in testing it, once the beta is complete.
As for the programming side of things, I'd advise building the main game engine in Java (or Python) and implementing a scripting language, relying on Lua or Python. Said scripting language could be used to create cards for the system.

“Can we be casual in the work of God — casual when the house is on fire, and people are in danger of being burned?” — Duncan Campbell
“There are four things that we ought to do with the Word of God – admit it as the Word of God, commit it to our hearts and minds, submit to it, and transmit it to the world.” — William Wilberforce

2017-06-22 19:31:13

Thanks for the reply's. I know, it is an enormous project to undertake, it seems to me that once I can figure out how I am going to handle the cards themselves, the rest is just putting it all together and programming.

The only way I can see to automate the whole process of creating cards is by writing a program that can parse the card text and identify certain key words, then write the code to the card class accordingly. A number of keywords already exist, and I can account for them pretty easily such as; flying, haste, menis, first strike etc.., by just creating a class of keyword methods, it is all of the other effects that I will have trouble with,and I would have to see how consistent Magic is about using specific words for specific things.

I have heard of LUA scripting before, but I know nothing about it. What would be the benifit of using LUA scripting for the creation of the cards?

That is definitely an interesting idea that YGOPro uses. I will think on that. It just feels like there should be a way to automate the creation of the cards since there are so many similarities between all cards.

TJ Breitenfeldt

2017-06-22 20:40:04 (edited by Hijacker 2017-06-22 20:46:50)

Don't bother trying this. That's exactly the same global concerns like Apple try to do with systems like Siri, you know why their functions are limited right? Yeah, because they don't understand what you want from them, at least not in most of all cases. Just because the word "flying" happens to appear in the text it doesn't mean that this creature is actually flying, it could mean around 100 other things besides that. Not to mention that the card text's don't always look the same. The card text styles changed over the years, and they happen to contain text which even humans have problems understanding. I sometimes needed to Google up some texts to understand the order or the connections or functionalities they're explaining there. Don't expect a computer to understand things his developer doesn't, a device will always be just as intelligent as it's engineer.
There are people alive who try to investigate learning algorithms which really understand text or pictures and are doing this for 20 and more years now. You'd absolutely lose track of your main project when trying such attempt.
Lua is by far the smallest and fastest scripting language available. It's standard library doesn't contain very much, but with around 100 kilobytes of size it fits nearly everywhere possible. It's strength llys in its embeddability. You can easily embed a lua stack into your game, expose an api to it and the user can script as far as they want without interfering with your main program or damaging something on runtime. That's how e.g. World Of Warcraft realizes it's monster and spell scripts and such stuff. The main game runs and just loads those scripts which implement the features of the possible enemies.
To see more of lua, just Try yourself out and go here
Best Regards.
Hijacker

2017-06-24 04:15:52 (edited by Jabberwocky 2017-06-24 04:30:10)

Let's try that again. It seems to have lost my entire post!

I highly recommend googling "programming MTG card effects" or "programming TCG card effects". There are a lot of posts out there and you may be able to pull together some ideas from them.

Note that I've never programmed this kind of thing myself, but I've done some research into it while considering making an accessible digital version of a card game called Sentinels of the Multiverse. I'll refer to it in the rest of the post as examples. The basic idea is that you want to be able to reuse things as much as possible. Think about what core actions or effects exist in the game. For example, in Sentinels, and I suspect in Magic, there are effects like gaining/losing hit points, increasing/decreasing damage dealt, increasing/decreasing damage taken, being immune to certain types of damage, etc. You want to code the effects, not the cards themselves. Keywords can be useful in that they might determine some rule that the game needs to keep track of. For example, Sentinels has the "ongoing" keyword to mean that a card's effects remain active until it is trashed.

If you've ever played Tactical Battle, looking at how the game allows people to create their own units, maps, etc, is a good way to understand what you're trying to achieve. Ideally, you should be able to write a custom card with effects that are already implemented in the code, and have it work smoothly with the other existing cards.

I don't know what you're programming experience is, so I won't make assumptions about your abilities. If you're determined enough, and you start off small, getting a few cards to work, and expanding from there, I don't see why you couldn't get somewhere with this. At the very least, it's a great learning experience.

Sorry if this was kind of vague and rambling. Since I don't have specific experience with implementing this type of program, I don't want to give you misleading information.

2017-06-24 05:47:45

Hi, thank you for the tips. I am working on getting my bachelors in computer science, but I just finished my first year of programming classes. I have two more years left. I will take a look with google to see if I can dig some things up. That is what I was thinking, there are a lot of commonalities between all of the cards, and a lot of the effects are the same on different cards. There are some strange effects sometimes that really aren't shared with other cards, but that is not the norm. I haven't built a game yet, that I can say I am proud of, and this didn't seem terribly hard if I can figure out how to handle the cards. It is complicated, but I think with in my skill level.

I primarily wanted to use java to build this because that is the language I am learning in my classes for the most part, so I know java the best. I also felt that object oriented programming would fit this type of project well, however I am running into an issue because java doesn't allow for a child class to have two or more parents. I think the way I was designing it may have worked, but I don't think I should use java if I am going to approach this problem using object oriented programming. Main problem is that I have a card class, and all card cards have names, then I have a class called permanence, which all permanents can be tapped, then I have a creature class, and the creature class has various properties, and finally I would create a class for each creature, passing in its properties up the hierarchy, however creatures can be more than one card type, so I would have to make the creature I am working on extend the Creature class as well as say the Artifact class, which I can't do in java. Sure I can use interfaces, but I can't get the same effect as I am wanting with classes. I think I need a different language, or a different approach.

I started looking at BGT, and I have a couple questions on that which I will post in a different thread, I was also just thinking of learning C++. I know that it can do what I want and more, but I took a C class at one point and I did not like it. I am going to have to learn it for my degree eventually though.

TJ Breitenfeldt

2017-06-24 11:28:59

Hi,
so it shouldn't be necessary to add classes to support things like "permanent", "quickplay" or effects like "haste" or "defender". All those things can be toggled with flags instead of parent classes. With this way you can reduce classes to Creature, Spell, Land, Artifact and some more, and that should be it. This skips the multiple parents problem you're javing with Java. But that's one of the reasons I don't like Java as a language, I like multiple parents, even if you can usually avoid such structures.
Best Regards.
Hijacker

2017-06-24 17:38:19

Okay, that makes sense, but if I have a card that is an artifact creature how do I pull in the properties of both the creature class and the artifact class? Also, I suppose I will want a design that will account for being able to switch card types, since some cards directly effect card type, such as make 1 of your land into a 1/1 token or something.

TJ Breitenfeldt

2017-06-24 19:35:05

That's right, I didn't think of these. The card transformation stuff could be done quite easy. Just create a new class which is now a creature, with the ability to tap and gain one mana, since that's actually the same thing. Of course this creature must react on cards which search for land targets, but this should be no problem. The artifact creatures are a bit harder though. It might be the best way to implement a separate class for those, inheriting the creature and just setting up the artifact features on top of it. Just my spontaneous ideas. I didn't take very much time to re-invent the wheel though. Since I don't plan to make such things I didn't create a nice class model for it. Anyway, you see, its all but not an easy attempt you're trying here.
Best Regards.
Hijacker

2017-06-30 03:10:19

Hi,

First of all, this idea is something I've wanted to do since a long time, but unfortunately I lack the programming skills needed, so your topic got me very happy smile

Let me suggest a completely different approach to the problem

2017-06-30 03:30:52

Hi vcaparica, I would be happy to take other suggestions, I am still pondering how to do this, so if you have a different idea, please share.

TJ Breitenfeldt

2017-06-30 04:50:54

Oh, boy, I thought the message was sent but it posted just the first paragraphs. I'll rewrite, perhaps this time I'll be shorter.

TLDR: You don't need to code all this stuff. You don't NEED automation. All you really need is a P2P client that manages cards, moving cards from buffer to buffer, and a chat. The players can do the rest.

Now, introducing Dragonstudios' Apprentice for those who don't know it.

Back in the 90's, a bunch of guys named Dragonstudios released Apprentice, a P2P software to play MtG online. The software was very small, used very simple graphics, and had no automation at all. Despite that, it was a hit. Thousands of people played using it, there was the PlaneswalkerLeague centered on IRC channels that promoted tournaments almost everyday. Here in Brazil we had LigaMagic which was our national version of Planeswalker League, so I imagine that many other countries had their own.

What did Apprentice consist on? The window was divided into menubars, toolbars, sidebar, main tabletop and chat bar. On the left side, there was the sidebar which showed your hand on a list, every row containing the card name and casting cost. The chat bar was on the bottom of screen. The toolbar and menubar were atop everything and 70% of the screen was the tabletop, where you could drag and drop cards and right-click them to access quick actions such as tap or bury. The toolbar contained buttons such as "Draw Card", "+1 Life", "-1 Life", "Advance Phase", "Pass Turn", "+1 Counter", "+1/+1", and so on. Now, I'm probably getting redundant, but I'll explain why it worked for many, many years without any automation.

You're gonna attack. You choose and declare attackers, tap them and it goes. Your opponent sees your tapped attackers and declares and assigns blockers. You and your opponent both know who died and who didn't. You know how double strike works, just so you can play with real cards on a tabletop without any computers. The non-blocked creatures will deal say 6 damage to your opponent, and he knows that he needs to lower his life points by six. And if he doesn't, if anybody runs out of the rules, well, same things applies online and offline, specially if a third person, a judge for tournaments, can be watching. Besides all the talking, the chat would also register every action, so there would be no problem determining what happened.

So, that's it. I don't think you need to code all of Magic's functionalities so it runs things for you, you just need a platform with a nice deck editor that allows you to run the game yourself. I tried a lot to reproduce Apprentice in an accessible application, but I seriously lack even the most basic programming skills. Hope this ideas can help you.

PS: On card databases, try googling for magic the gathering full card spoilers, it will take you to text listings of all cards, then you can parse and store it.

2017-06-30 04:58:22

If you would like to chat about this project, I have many ideas waiting for a programmer. My skype username is cego.em.tiroteio

2017-07-01 10:26:53 (edited by Dino 2017-07-01 10:27:33)

I play Magic. A major part of the game are combos--groups of cards whose effects interact with one another to create a situation that usually leads to either an instant win or a major advantage for the player who played the combo. I'll give an example of one: in my Merfolk themed deck, I have the cards "Wanderwine Prophets", "Sygg, River Guide", and "Seahunter". The interaction works like this:

1. Every time Wanderwine Prophets does combat damage to a player (the attack is not blocked by a creature), I have the option of sacrificing a merfolk creature (taking it out of play and putting it into the graveyard). Doing so will allow me to play another turn.

2. I can pay mana to let Sygg, River Guide give protection to Wanderwine Prophets from the colours of the creatures my enemy has which would block its attacks.

3. Seahunter allows me to pay mana to search my deck for any merfolk creature card and put it directly onto the battlefield.

The result is that I can attack as many times as I have merfolk in my deck without allowing my opponent to attack, as each turn I use Seahunter's ability to fetch a new Merfolk for Wanderwine Prophets to sacrifice, letting me play another turn almost indefinitely (I have a lot of merfolk in my deck).

Things like this are what makes MTG hard to program effects for and why Cockatrice is 'simple-minded'--because things like this are easy for players to reason about but hard to program into a computer.

So I think that forking Cockatrice might be the best place to start, or at least making something similar, perhaps with a decent guide to how to play Magic built into it. I would not wanna be the guy who has to make sure all the combos work (there are many possibilities).

Prehistoric terror.
My github.

2017-07-01 16:02:48

It's complicated and nothing I would expect one man to do on his own, alone, with the need to program each card himself, that's what I already said.
But it isn't impossible. Wizards of the Coast themselves provided a Magic The Gathering game on their own, even if it isn't accessible at all. YGOPro prooves that it is possible even for community-projects to bloom and support full-featured effect chaining and such stuff, but it takes time and many ambitioned people.
It would be nice to have such simple tabletop simulator like Cockatrice, this would actually enable us to play Magic at all, but I can tell you from my own experience it's loads more fun to have a client which supports all functionalities on it's own, not just because it fixes all misunderstanding problems you might have with some effects automatically.
Best Regards.
Hijacker

2017-07-04 20:33:46

I absolutely agree with Hijacker that it would be really nice to provide a fully automated magic the gathering game, It is definitely an interesting idea vcaparica has though. It is very time consuming to braille card sleeves, and if I could play magic with out all of the hassle of brailling cards, I will take it. Even if I use it just to test cards so I have to braille fewer cards that I am not going to actually use. I have started looking into what I will need to build this, and the only thing that I am still trying to figure out how to deal with is how to store the cards.

So, I can use a tool that already exists, to pull down the information from the gatherer's database, but how should I store them, should I have it create an class for each card, just writing to a file each time? This doesn't seem like it will go well, because there is going to be about 10,000 cards, give or take, and I am going to have to write to disk that many times, and then more as more sets come out. That is my first instinct, but I don't think that will work very well, so I am guessing I should have it create some kind of local database that is distributed with the game, and it can just work with the local database as the player builds their deck. Decks, could be written to file, so that you don't have to continue to pull from the database.

Does anyone have any other suggestions, or comments on how to create a local database like what I am thinking?

TJ Breitenfeldt

2017-07-04 21:42:16

Hi,

so yes, there need to be one class per card, at last that's what i would do, and no, magic doesn't have 10,000 cards yet, it barely has as much as Yu-Gi-Oh has, and that's just something around 4,000 to 5,000.
Anyway, those are just some few files which don't take very much space for each one.
YGOPro uses a splitted system. It contains one database file (sqlite3) which contains all cards with an unique id, the card text, the possibility to set small text pieces (more of that later), attack and defense power, the element, the type... and all that kind of stuff. When loading this database, YGOPro then looks if it can find a lua script for the id found in the database, and if yes, loads this lua script to backup the card class already existing in the game itself. If it doesn't find a lua script with the id of the card, the card simply doesn't have any effects and therefore just is a useless spell, trap, or monster card.
The text pieces are shown on screen if the card e.g. has multiple effects. You can then left click the card you want to activate and the game will show you a selection screen with as many choices as the card has effects and as many text pieces as the card has effects and each text piece will be mapped to one effect of the card and describe it in a KISS (keep-it-short-and-simple) way.
Example:
First effect: pay 1 to tab card
Second effect: pay 1 to untab card

This way of handling databases makes it easy to translate the game without losing any functionality, because everything you must do here is to change the texts. As long as the ids stay the same, the game can map the lua scripts towards the cards and all will work as expected.
Best Regards.
Hijacker

2017-07-05 00:00:20

In fact, Magic the Gathering has, as of today, 16505 different cards, according to
http://mtg.gamepedia.com/Magic:_The_Gat … and_trivia

So yes, a class for each card being loaded everytime would be something of a slow move. Apprentice stored all cards inside a single DAT file, and there was also a GUI made to edit and add new cards to that DAT file, so I imagine it was a text to parse, a serialized dictionary, dunno, I really lack programming skills.

And yes, a way to play MtG without brailled sleeves, oh, man, that would be a dream came true.

Best regards.

2017-07-05 00:48:20

Hi,
wow, that came unexpected. Thanks for pointing that one out, didn't expect it to be so many cards.
Anyway, you don't actually have to load all cards each time the game runs, didn't you? You actually do just need to load the classes as soon as any player plays this card, but in no other case. This reduces the classes instanciated to a maximum of a thousand (one very very long gaming sessions with more than 10 decks per player, if you calculate with two players, and no card may exist twice). This is totally acceptable. I'd expect the amount to be drastically lower (maybe something around 200 in one average gaming session?).
I can just repeat myself, YGOPro does it like this, and it works without any slowdowns or such stuff, that's just fine.
I don't recommend to use any new file format for this. This forces users to use your (and only your!) tools to modify it, and if they don't like it, you miss some probably really helpful users who could have assisted you if they had more choices. Using an open database format like SQLite 3 (which is a database system which enables you to search data quickly without much time lost) enables your users to use any database editing frontend they like. Hell yeah, there is even a Firefox add-on out there which is just amazing and you don't even need to install any application to your computer, as long as you got Firefox. There are command-line versions. And so on. Anyone will find a GUI which fits his needs. That's an opportunity a single-man-project shouldn't miss out.
Best Regards.
Hijacker

2017-07-05 01:27:32

If you account for lands which are by far the most numerous cards in any match, and also account the fact that except by Legends every player will have more than one copy of each card in his deck, then a single match would handle 50 to 80 different cards, eventually less. I also agree with file formats, open is better.

2017-07-05 17:58:12

Okay, I just went to have a small look at something. I am rather interested in this project, but there appears to be a program that at least has solved the rules enforced thing. Probably not accessible, though. It's a program called XMage. Might be worth a look.

I have a website now.
"C: God's Programming Language
C++: The object-oriented programming language of a pagan deity" -- The Red Book
"There, but for the grace of God go I"

2017-07-05 21:17:32

Wow, even though I googled alot to find something useful, this seems to be totally it. It's written in Java (such as you wanted TJ) and it supports everything I could have imagined. I think it will be alot easier to make this product accessible, since it's open source and hosted on GitHub, than writing your own stuff.
Best Regards.
Hijacker

2017-07-08 20:06:52

That sounds awesome. If someone's already implemented it, then, as Hijacker said, making it accessible would be a much more manageable feat than programming all the rules... which is what I was wary about. This looks like a much more achievable thing than it originally did, good luck big_smile

Prehistoric terror.
My github.

2017-07-13 04:30:56

I'm very much looking forward to the results of this project.

I have a website now.
"C: God's Programming Language
C++: The object-oriented programming language of a pagan deity" -- The Red Book
"There, but for the grace of God go I"