It is currently 16 Apr 2024, 08:08
   
Text Size

MagicGrove - Play magic against computer

by magicgrove

Moderator: CCGHQ Admins

MagicGrove - Play magic against computer

Postby magicgrove » 25 May 2012, 08:43

Hi all,

MagicGrove is a game that I wrote for fun, it lets you play mtg against computer opponent.

My goal was to produce a game playable as soon as possible, but it took about a year and a half anyway :) I made a lot of bad decisions which cost me plenty of rewritting. At the beggining I did not think about how I would implement AI and that was an expensive mistake. I borrowed many ideas from magarena, most importantly its usage of the undo system for the search tree traversal. The codebase of magarenea is a great place to learn the core things about mtg programming and I would recommend it to everyone.

AI
The AI uses a minmax algorithm with some additional tweaks to reduce the search space (equal states prunning, target scoring, spell timming) and is capable of looking 12 steps ahead in under 2 seconds most of the time. I plan to improve its performance so that it would consider 2 turns ahead in roughly the same time.

Cards
Cards are defined in C#. I started with xml, but soon abandoned it. In the future the definitions could be in some clr compatible scripting language (e.g. Boo).

Example of card:

Code: Select all
public class Shock : CardsSource
  {
    public override IEnumerable<ICardFactory> GetCards()
    {
      yield return C.Card
        .Named("Shock")
        .ManaCost("{R}")
        .Type("Instant")
        .Timing(Timings.InstantRemoval)
        .Text("Shock deals 2 damage to target creature or player.")
        .Effect<DealDamageToTarget>((e, _) => e.Amount = 2)
        .Category(EffectCategories.DamageDealing)
        .Target(C.Selector(
          validator: target => target.IsPlayer() || target.Is().Creature,
          scorer: TargetScores.OpponentStuffScoresMore(spellsDamage: 2)));
    }
  }
Release 1.0
Release 1.0 has 73 cards and supports 4 decks from magarena. Cards with similar mechanincs can be added very quickly.

Screenshots
play-original.jpg

play-custom.jpg


Source & Binaries

code(dot)google(dot)com/p/magicgrove/

Any comments & feedback are very welcome.
magicgrove
DEVELOPER
 
Posts: 39
Joined: 25 May 2012, 08:22
Has thanked: 7 times
Been thanked: 21 times

Re: MagicGrove - Play magic against computer

Postby Hellfish » 27 May 2012, 00:15

That's very cool! Looking forward to trawl through the source and try to figure out the ai ;)

I'm on-and-off working on my own Rule Enforcement Engine written in C# as well. Some points are eerily familiar (In all seriousness, that is not an accusation, in fact it gives me hope that I'm actually doing things the right way :mrgreen: ) but I have no intention to start AI support as that entire field makes my head spin :lol:
So now you're
Screaming for the blood of the cookie monster
Evil puppet demon of obesity
Time to change the tune of his fearful ballad
C is for "Lettuce," that's good enough for me
User avatar
Hellfish
Programmer
 
Posts: 1297
Joined: 07 Jun 2009, 10:41
Location: South of the Pumphouse
Has thanked: 110 times
Been thanked: 169 times

Re: MagicGrove - Play magic against computer

Postby ubeefx » 27 May 2012, 09:39

The screenshot certainly looks nice. :)

I also had some attempts at making a Magic program before Magarena.
You are right about AI, it is not something you can just add afterwards.
Learning is all part of the game.

The undo system in Magarena was indeed made for the AI search tree.
Then I realised that it would be a very cool feature for the users too.

In order to grow the card base, the work to add cards should be as small as possible with a lot of reuse.
That is why some kind of scripting can be good. Even cooler would be converting Magic rule text to code.
For Magarena, my focus was never on adding many cards, so it worked well enough the way I did it.
User avatar
ubeefx
DEVELOPER
 
Posts: 748
Joined: 23 Nov 2010, 19:16
Has thanked: 34 times
Been thanked: 249 times

Re: MagicGrove - Play magic against computer

Postby MageKing17 » 27 May 2012, 18:58

ubeefx wrote:In order to grow the card base, the work to add cards should be as small as possible with a lot of reuse.
That is why some kind of scripting can be good. Even cooler would be converting Magic rule text to code.
If anyone needs help with that kind of thing, Incantus's online editor has an oracle parser that tries to turn card text into usable Python code; it succeeds with a surprising number of cards, and definitely helps with others (as an example, it can code Etherwrought Page by itself). It's always kind of surprising when I open up a card and find that the parser has written the whole thing for me; it's extremely helpful. Of course, it's nowhere near as functional as I'd like it to be, but something is better than nothing, and there are still projects out there to make grammar-based parsers that could be extremely interesting if one of them got finished.
User avatar
MageKing17
Programmer
 
Posts: 473
Joined: 12 Jun 2008, 20:40
Has thanked: 5 times
Been thanked: 9 times

Re: MagicGrove - Play magic against computer

Postby magicgrove » 08 Jun 2012, 16:31

Hi,

New magicgrove release is available at:

code(dot)google(dot)com/p/magicgrove/

Release 1.1

- AI performance improved
- Lookahead increased to 16 steps
- Users can now select a deck from the list or play a random game
- The list of available cards is distributed with the game
- Added instructions on how to add your deck

For Release 1.2, I plan to add some new cards/decks. If you would like certain cards/decks to be implemented, I am open to suggestions :)

If anyone would like to contribute to the project, just send me an email.
magicgrove
DEVELOPER
 
Posts: 39
Joined: 25 May 2012, 08:22
Has thanked: 7 times
Been thanked: 21 times

Re: MagicGrove - Play magic against computer

Postby magicgrove » 08 Jun 2012, 16:49

For magicgrove 2.0, I am planning to add draft support to the game. If anyone has any thoughts about this eg:

- How AI should work,
- best magic edition (for drafting)

Your suggestions are very welcome.
magicgrove
DEVELOPER
 
Posts: 39
Joined: 25 May 2012, 08:22
Has thanked: 7 times
Been thanked: 21 times


Return to MagicGrove

Who is online

Users browsing this forum: No registered users and 11 guests


Who is online

In total there are 11 users online :: 0 registered, 0 hidden and 11 guests (based on users active over the past 10 minutes)
Most users ever online was 4143 on 23 Jan 2024, 08:21

Users browsing this forum: No registered users and 11 guests

Login Form