Magarena
by ubeefx
Moderators: ubeefx, beholder, melvin, ShawnieBoy, Lodici, CCGHQ Admins
Magarena
by ubeefx » 26 Nov 2010, 23:08
Magarena is a game I developed as a hobby project to play limited against the computer.
Creating an advanced AI was the main challenge. I am very happy with the result.
I want to share the code and ideas to inspire.
People are certainly welcome to continue working on this project.
More information can be found on the project page, see download link below.
Creating an advanced AI was the main challenge. I am very happy with the result.

I want to share the code and ideas to inspire.
People are certainly welcome to continue working on this project.
More information can be found on the project page, see download link below.
Re: Magarena
by Huggybaby » 26 Nov 2010, 23:41
This is cool, I hope folks here check it out.
Artificial Intelligence
* Multi-threaded
* Minimax game tree
* Fast forward and backward tree traversing
* Fast iterative scoring system : determines the AI behavior
* Alpha-beta pruning and score caching
* Specific algorithms for :
o Paying mana costs
o Playing spells and abilities
o Picking targets and colors
o Declaring attackers and blockers
* Difficulty level : number of main phases used for lookahead
The AI is limited by how far it can lookahead because the further the more processing power is needed. The AI will only play the best moves for the period in time it can lookahead, for instance a full turn. This also means that it will not try to hold back creatures or removal. To reduce the number of future game permutations, the AI must sometimes limit the number of choices it makes locally. The scoring system that is used has a large impact on how the computer plays and will sometimes result in choices a human player would not generally make. The AI does not work with fuzzy facts, e.g. it will not try to bluff or take into account the hand and unused mana of the player.
-
Huggybaby - Administrator
- Posts: 3225
- Joined: 15 Jan 2006, 19:44
- Location: Finally out of Atlanta
- Has thanked: 734 times
- Been thanked: 601 times
Re: Magarena
by nantuko84 » 27 Nov 2010, 06:41
it's amazing! especially AI, I believe it's the best one I've seen last time.
Mage\MagicWars blog: http://mwars.blogspot.com/
Re: Magarena
by nantuko84 » 27 Nov 2010, 09:24
Bug:
AI plays Goblin Artillery
on my turn I attach equip to my creature, and AI uses Goblin Artillery as though it has haste (at that moment it still should have summoning sickness).
Reproduced twice.
Though need to say that I played lots of game, and your application is bugs free
And just feature request: is it possible to show creature's abilities somehow (e.g. using tooltips)? now sometime it doesn't clear whether creature has flying or trample or not.
AI plays Goblin Artillery
on my turn I attach equip to my creature, and AI uses Goblin Artillery as though it has haste (at that moment it still should have summoning sickness).
Reproduced twice.
Though need to say that I played lots of game, and your application is bugs free

And just feature request: is it possible to show creature's abilities somehow (e.g. using tooltips)? now sometime it doesn't clear whether creature has flying or trample or not.
Mage\MagicWars blog: http://mwars.blogspot.com/
Re: Magarena
by MageKing17 » 28 Nov 2010, 20:46
Just thought I'd point this out:
This isn't a change; this is consistent with current combat rules.Rule Differences
[...]
- combat damage is automatically assigned :
- attacker deals combat damage in order of blockers
- all remaining damage is dealt to first blocker
- trample : all remaining damage is dealt to defending player
- deathtouch : lethal damage dealt to blockers is 1
-
MageKing17 - Programmer
- Posts: 473
- Joined: 12 Jun 2008, 20:40
- Has thanked: 5 times
- Been thanked: 9 times
Re: Magarena
by silly freak » 28 Nov 2010, 21:13
slightly not... in the real game, the player has the choice to assign excess combat damage among blockers, even with trample etc.
Edit: Cool! Just tried the game out, and it looks awesome. What I've read so far about the AI is impressing, I'm definitely checking your code
Edit: Cool! Just tried the game out, and it looks awesome. What I've read so far about the AI is impressing, I'm definitely checking your code

___
where's the "trust me, that will work!" switch for the compiler?
Laterna Magica - blog, forum, project, 2010/09/06 release!
where's the "trust me, that will work!" switch for the compiler?
Laterna Magica - blog, forum, project, 2010/09/06 release!
- silly freak
- DEVELOPER
- Posts: 598
- Joined: 26 Mar 2009, 07:18
- Location: Vienna, Austria
- Has thanked: 93 times
- Been thanked: 25 times
Re: Magarena
by ubeefx » 28 Nov 2010, 22:20
I am very pleased that you like the AI!
Several compromises were needed to make it actually fast enough due to the complexity of Magic.
That's why this engine would currently not be suitable to implement all existing cards.
I added a couple of nice features suggested by nantuko84 :
- support for two colored decks (the biggest work here was to improve the deck generating code)
- symbols for flying, first/double strike, trample & deathtouch abilities on creature permanents
There is now also a downloadable jar with these latest changes on the project page.
Magarena should work much better on Mac and Linux this way.
Adding feature requests is now also possible.
However, programming this game was very work intensive and I will step back a bit.
Several compromises were needed to make it actually fast enough due to the complexity of Magic.
That's why this engine would currently not be suitable to implement all existing cards.
I added a couple of nice features suggested by nantuko84 :
- support for two colored decks (the biggest work here was to improve the deck generating code)
- symbols for flying, first/double strike, trample & deathtouch abilities on creature permanents
There is now also a downloadable jar with these latest changes on the project page.
Magarena should work much better on Mac and Linux this way.

Adding feature requests is now also possible.
However, programming this game was very work intensive and I will step back a bit.
Re: Magarena
by lord of 13 » 29 Nov 2010, 02:19
I'll join in complimenting your program! The deck generation is pretty well done, ensuring a reasonable mana curve and creature/spell ratio. Were you to add a deck editor, that would be fantastic. Also, would you like to talk sometime about AI and AI optimization algorithms, as well as how you implemented Minimax for MtG? I'll read some of your code soon!
><><><><><><><
Currently developing Mindgames, for playing a rules-enforced game of MtG.
RECENT PROJECTS
->XMLScript
->Zwiel Platformer
Currently developing Mindgames, for playing a rules-enforced game of MtG.
RECENT PROJECTS
->XMLScript
->Zwiel Platformer
-
lord of 13 - DEVELOPER
- Posts: 79
- Joined: 06 Jan 2010, 01:36
- Has thanked: 0 time
- Been thanked: 0 time
Re: Magarena
by MageKing17 » 29 Nov 2010, 18:04
D'oh; I can't believe I missed that. Thanks for the correction.silly freak wrote:slightly not... in the real game, the player has the choice to assign excess combat damage among blockers, even with trample etc.
-
MageKing17 - Programmer
- Posts: 473
- Joined: 12 Jun 2008, 20:40
- Has thanked: 5 times
- Been thanked: 9 times
Re: Magarena
by ubeefx » 29 Nov 2010, 18:27
I added a small howto on duel customizing, like deck editing, at the bottom of the project page.
It is nothing fancy with a gui, but you can actually do it with a text editor.
The edited file can also be backed up for later use.
The code currently lacks documentation so it might be hard to read.
If you have questions or want to discuss the AI, just send a pm.
It is nothing fancy with a gui, but you can actually do it with a text editor.
The edited file can also be backed up for later use.
The code currently lacks documentation so it might be hard to read.
If you have questions or want to discuss the AI, just send a pm.
Re: Magarena
by mtgrares » 29 Nov 2010, 21:13
Magarena sounds very interesting and you get bonus points for coding it in Java (because it is the only language that I'm really good at).
I just downloaded the images but I can't find them. Where does Magarena put the card pictures?
(Nevermind, I just found it under c:/Users/your username/Magarena)
Some of us have to download everything to a USB drive. Oh the price of being unplugged.
I just downloaded the images but I can't find them. Where does Magarena put the card pictures?
(Nevermind, I just found it under c:/Users/your username/Magarena)
Some of us have to download everything to a USB drive. Oh the price of being unplugged.

- mtgrares
- DEVELOPER
- Posts: 1352
- Joined: 08 Sep 2008, 22:10
- Has thanked: 3 times
- Been thanked: 12 times
Re: Magarena
by DennisBergkamp » 30 Nov 2010, 05:04
Wow, very impressive!!! There's a lot of things it does much better than Forge (especially the AI - which is also extemely snappy).
Keep up the good work
Keep up the good work

-
DennisBergkamp - AI Programmer
- Posts: 2602
- Joined: 09 Sep 2008, 15:46
- Has thanked: 0 time
- Been thanked: 0 time
Re: Magarena
by ubeefx » 30 Nov 2010, 22:09
Thanks for all the encouraging replies!
I fixed the Spider Umbra aura and also improved the download images dialog with proxy support.
Now you can always download the executable or jar of the latest version with the links on the project page.
The accompanying readme file contains what has changed and when.
I fixed the Spider Umbra aura and also improved the download images dialog with proxy support.
Now you can always download the executable or jar of the latest version with the links on the project page.
The accompanying readme file contains what has changed and when.
Re: Magarena
by silly freak » 01 Dec 2010, 21:18
by the way, at least under ubuntu, you can also use the exe, open it with the archive explorer, and save it as a jar file. worked for me
___
where's the "trust me, that will work!" switch for the compiler?
Laterna Magica - blog, forum, project, 2010/09/06 release!
where's the "trust me, that will work!" switch for the compiler?
Laterna Magica - blog, forum, project, 2010/09/06 release!
- silly freak
- DEVELOPER
- Posts: 598
- Joined: 26 Mar 2009, 07:18
- Location: Vienna, Austria
- Has thanked: 93 times
- Been thanked: 25 times
Great AI
by mtgrares » 02 Dec 2010, 18:22
After "intensive researching" Magarena for a couple of hours I determined that the AI is very smart and that the user interface is very good. Magarena takes up less resources than Forge and even runs on my ancient computer, which has less than 256 MB.
The only AI hiccups that I saw was when he suicidally attacked with a 1/1 into a 2/2 and another time the AI kept re-equipping (with some type of equipment) to a 1/1 creature, literally the computer paid to attach it to the creature 3 times in a row.
My only very minor quibble is that Magarena automatically skip some phases. This works out very good at the beginning of the game, when not much is going on, but later in the game I have to always read the phase name because I have no idea where I'm at because the computer won't skip anything if I have an instant or ability and will skip many phases if I don't. When playing Forge I don't always read which phase I am at since the phase stops are always the same. It seems lame but I would like to choose which phases to stop at.
On the plus side, I have no idea how long it took you to program Magarena but it is written very well. (OK my guess is 1.5 years.) I was also intrigued by your option that plays 123 matches and then shows the result. That was a very interesting feature that tries to balance the two random decks so that the player has a good game.
I'm probably your biggest fan and am very impressed by your program. I posted a short article about Magarena on my blog today and I plan to post a longer article later. Keep up the good work.
p.s.
It is nice that you chose Java because I can hopefully look at your code and learn a few things.
The only AI hiccups that I saw was when he suicidally attacked with a 1/1 into a 2/2 and another time the AI kept re-equipping (with some type of equipment) to a 1/1 creature, literally the computer paid to attach it to the creature 3 times in a row.
My only very minor quibble is that Magarena automatically skip some phases. This works out very good at the beginning of the game, when not much is going on, but later in the game I have to always read the phase name because I have no idea where I'm at because the computer won't skip anything if I have an instant or ability and will skip many phases if I don't. When playing Forge I don't always read which phase I am at since the phase stops are always the same. It seems lame but I would like to choose which phases to stop at.
On the plus side, I have no idea how long it took you to program Magarena but it is written very well. (OK my guess is 1.5 years.) I was also intrigued by your option that plays 123 matches and then shows the result. That was a very interesting feature that tries to balance the two random decks so that the player has a good game.
I'm probably your biggest fan and am very impressed by your program. I posted a short article about Magarena on my blog today and I plan to post a longer article later. Keep up the good work.

p.s.
It is nice that you chose Java because I can hopefully look at your code and learn a few things.
- mtgrares
- DEVELOPER
- Posts: 1352
- Joined: 08 Sep 2008, 22:10
- Has thanked: 3 times
- Been thanked: 12 times
31 posts
• Page 1 of 3 • 1, 2, 3
Who is online
Users browsing this forum: No registered users and 12 guests