Re: New Magic program: Gleemin
Posted: 01 Mar 2011, 23:51
Arch, hi. Here's the full source:
http://www.goblinopera.com/Gleemin/Gleemin_tests_01-03-11.tar
It will run in Win-Prolog if you compile main.pl and enter "main." at the listener. Please remember it's a working version that I'm still hacking at like mad (but I reckon you've seen source code before). Do be gentle while running it and keep a flamethrower handy for the bugs (think Starship Troopers).
To your Prolog questions.
Variables that start with an underscore are "don't-care" variables, as long as each is only encountered once in the body of a rule. Otherwise, Prolog will try to match them. A single underscore is truly don't-care, so two or more won't be matched. As you say, I'm using the named ones as reminders of what each unused field is.
The card structure is actually a Prolog list. You could see it as
The traditional way to do key-value pairs in prolog is to have lists of the form:
I'm using some of those too You can define your own operator to use as a key-value separator, if the Prolog implementation allows it.
Yes, unfortunately if you want to modify the data structure then you have to modify everything that uses it. Prolog is not object oriented. Basically, it's kind of pattern-based, so when you change one pattern you have to change everything that's trying to match it. You can of course define OOP-like hierarchical relationships, for which there's some code floating freely on the internet and L-space, but I wanted to get stuck in with the Magic right away. I'll probably have to do some more elaborate organisation at a later point.
The "state" field is there from the beginning of the project, when I was trying to figure out how to do things. It's kind of useless at this point but I left it in just in case. I might use it for cards with a comes-int-play tapped effect etc. There's lots of garbage in my code that I just can't bother fixing right now. I'm no software engineer, see )
http://www.goblinopera.com/Gleemin/Gleemin_tests_01-03-11.tar
It will run in Win-Prolog if you compile main.pl and enter "main." at the listener. Please remember it's a working version that I'm still hacking at like mad (but I reckon you've seen source code before). Do be gentle while running it and keep a flamethrower handy for the bugs (think Starship Troopers).
To your Prolog questions.
Variables that start with an underscore are "don't-care" variables, as long as each is only encountered once in the body of a rule. Otherwise, Prolog will try to match them. A single underscore is truly don't-care, so two or more won't be matched. As you say, I'm using the named ones as reminders of what each unused field is.
The card structure is actually a Prolog list. You could see it as
- Code: Select all
card(Characteristics)
- Code: Select all
card([Name, Cost, Type, Text, P, T, Loyalty, State])
- Code: Select all
card([card_name 'Maritime Guard', _, _, _, P, T, _, _]).
- Code: Select all
P = power [1] ,
T = toughness [3]
- Code: Select all
card([card_name 'Maritime Guard', _, _, _, power P, toughness T, _, _]).
- Code: Select all
P = [1] ,
T = [3]
The traditional way to do key-value pairs in prolog is to have lists of the form:
- Code: Select all
map([Key_1 - Value_1, Key_2 - Value_2... Key_n - Value_n]).
I'm using some of those too You can define your own operator to use as a key-value separator, if the Prolog implementation allows it.
Yes, unfortunately if you want to modify the data structure then you have to modify everything that uses it. Prolog is not object oriented. Basically, it's kind of pattern-based, so when you change one pattern you have to change everything that's trying to match it. You can of course define OOP-like hierarchical relationships, for which there's some code floating freely on the internet and L-space, but I wanted to get stuck in with the Magic right away. I'll probably have to do some more elaborate organisation at a later point.
The "state" field is there from the beginning of the project, when I was trying to figure out how to do things. It's kind of useless at this point but I left it in just in case. I might use it for cards with a comes-int-play tapped effect etc. There's lots of garbage in my code that I just can't bother fixing right now. I'm no software engineer, see )