A Magic: the Gathering™ expert system
Switch branches/tags
Nothing to show
Clone or download
Latest commit 1bea94f Jan 27, 2012


Gleemin: The Magic Virtual Machine is a Magic the Gathering expert system, originally created as my dissertation for my CS course at the University of Brighton (the ugliest university in the UK). It is a command-line program meant as an AI research tool rather than entertainment. 

Gleemin is written entirely in the logic programming language Prolog. To run the code here all you need is the Swi-Prolog interpreter (It's free and open source and you can get it from: http://www.swi-prolog.org/Download.html)

Gleemin includes a rules engine that aims to fully and correctly implement the game's tournament rules, an AI player programmable with expert knowledge and an interpreter for the game's language (the rules text on the cards).

Gleemin is a "Magic Virtual Machine" in that it's based on a conceptual model of the game's rules as the specification of a finite state machine. The states of the machine represent all possible states of a Magic: the Gathering game. The language used on the cards to give instructions to the players is seen as the scripting language for this virtual machine and the cards themselves are scripts in this language. Every time you cast a spell or activate an ability, the Magic Game Language interpreter parses the script and calls the appropriate rules engine predicates that change the state of the machine and therefore the game. 

+-Running Gleemin-+
	1) Install Swi Prolog. 
	2) Get the Gleemin sources. 
	3) Cd to the sources directory and double-click on "main.pl", 
		or enter "main.pl" (no quotes) in your command line. 
	4) You should now see the Swi-Prolog listener window. Enter 
		"main." (no quotes). This should start Gleemin and you 
		should see a list of sources being loaded. Notice the 
		"shoulds". _Should_ there be any problem don't hesitate 
		to contact me by email. 
	5) Follow the prompts. If something goes wrong, take it from
		(3) again (this is necessary to cleanup the program's 
		database from possible erroneous facts). 

============================== Git commit History ==============================

=== ToDo list: ===
	> Implement the rules missing from the engine: 
		> Timing restrictions for spells and abilities.
		> Triggered abilities.
		> Planeswalkers.
		> Layer system for continuous effects (rule 613). 
		> Hybrid, Phyrexian, Snow and Variable mana costs
			(currently those are recognised by the interpreter
			but can't be paid). 
	> Overhaul of the AI (using symbolic game trees).  
	> User interface (see comments [27/01/12]). 
	> Higher-level documentation (so that users don't have to 
		source-dive to figuer out how to use the system). A 
		man page for the linux version would be nice.
	> Complete the overhaul of predicates dealing with mana.
	> Cards and decks representation is stupid. Do something 
		that makes sense (eg, put each deck in a separate file
		and keep cards as text in a file, not as a Prolog list).

=== [27/01/12] Mana grammar update===

+- Changes: -+
	> mana_grammar.pl. This is a new mana grammar for the interpeter, which
		correctly recognises the textual mana symbols used in the CompRules 
		(but see my comments in the source file mana_grammar.pl for details). 
		It also recognises hybrid mana, phyrexian mana, snow mana and mana 
	> Players' mana pools can also now use the CompRules symbols. 
	> Optimised the addition of mana to pools by way of using difference 
		lists for append operations (which was a long time coming). 
	* None of these changes have yet been merged into the engine. 

	> Also buffed up this README a bit.	

+- Comments -+			
	Dealing with crashes.	
	I've decided to stop trying to correct the crashes caused by transferring 
		the code from Swi-Prolog and Win-LPA Prolog (the proprietary Prolog I 
		originally developpwed the project on). These crashes happen when Glee-min 
		is playing a deck it doesn't know, and particularly while taking combat 
		decisions. They seem to be caused by my heavy use of variables as functors 
		(as in: Functor(Args)) which is allowed in LPA, but not in Swi. Since I'll 
		be throwing out all of that code anyway, there is no point in trying to 
		correct the problem. 

=== [17/12/11] First Commit === 

Gleemin is still in alpha, and still crashes occasionally, due to the migration of the code from a proprietary Prolog interpeter to Swi-Prolog. The full Magic: the Gathering rules are not yet implemented, the full card text grammar is not yet implemented and the AI player is still dumb as all hell (although this is largely due to lack of knowledge). 

Despite all of the above, you can already play a full game, in that you can take all player actions, including making combat decisions, casting spells and activating abilities.