-
Notifications
You must be signed in to change notification settings - Fork 10
/
mgl_interpreter.pl
1719 lines (1439 loc) · 55.5 KB
/
mgl_interpreter.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
% First saved: 24/02/2011
% Last saved: 26/04/2011
%
% Status:
%
%
%
% Doing:
% noticed that burn effect sends only name of source
% (also needs Id). The reason is I'm not actually associating
% the source of an effect with the effect (this/1 does recognise
% a permanent with an ability that refers to itself, so use it)
% Todo
% Fix targeting (uncontrolled backtracking)
% and update to current version again.
%
% NOTES:
% Handles both abilities and effects.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% Swi Compatibility %%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
:- set_prolog_flag(backquoted_string,true).
% Swi LPA backtic string compatibility.
:- style_check(-singleton).
% Stop Swi warning on singleton vars.
:- style_check(-discontiguous).
% Stop Swi warning on discontiguous clauses.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% Abilities Syntax %%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%ability 25/02/11
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Kind of works-ish. I can ask
% phrase(triggered_ability, ['Flying']).
% and get yes, same for ability_word and some others.
ability --> spell_ability.
ability --> activated_ability.
ability --> triggered_ability.
ability --> static_ability.
ability --> ability_word, [-], ability.
ability --> keyword_ability.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%spell_ability 25/02/11
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
spell_ability --> effect.
spell_ability --> effect(_Target).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%activated_ability 25/02/11
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
activated_ability --> cost, [:], effect.
activated_ability --> cost, [:], effect, activation_instructions.
activated_ability --> mana_ability.
%%activated_ability --> loyalty_ability.
% activated_ability --> keyword_ability. Swi, 24/06/11; temp fix.
% ^ This will need further definition- not all keyword abilities
% are activated. Basically, each keyword ability that is an
% activated ability should be defined separately with its
% activated form.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%triggered_ability 25/02/11
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% triggered_ability: non-terminals
% triggered_ability --> condition, [','], effect.
triggered_ability --> trigger_condition, [','], effect.
% triggered_ability --> trigger_word, trigger_event, [','], effect.
triggered_ability --> mana_ability.
triggered_ability --> keyword_ability.
% query: phrase(triggered_ability, [when, X]).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%static_ability 25/02/11
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
static_ability --> keyword_ability.
static_ability --> effect.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%ability_word 25/02/11
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ability_word --> ['Channel'].
ability_word --> ['Chroma'].
ability_word --> ['Domain'].
ability_word --> ['Grandeur'].
ability_word --> ['Hellbent'].
ability_word --> ['Imprint'].
ability_word --> ['Kinship'].
ability_word --> ['Landfall'].
ability_word --> ['Metalcraft'].
ability_word --> ['Radiance'].
ability_word --> ['Sweep'].
ability_word --> ['Threshold'].
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%keyword_ability 25/02/11
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
keyword_ability(_X) --> keyword_ability.
keyword_ability --> ['Deathtouch'].
keyword_ability --> ['Defender'].
keyword_ability --> ['Defender'].
keyword_ability --> ['Double Strike'].
keyword_ability --> ['Enchant'].
keyword_ability --> ['Equip'].
keyword_ability --> ['First Strike'].
keyword_ability --> ['Flash'].
keyword_ability --> ['Flying'].
keyword_ability --> ['Haste'].
keyword_ability --> ['Intimidate'].
keyword_ability --> ['Landwalk'].
keyword_ability --> ['Lifelink'].
keyword_ability --> ['Protection'].
keyword_ability --> ['Reach'].
keyword_ability --> ['Shroud'].
keyword_ability --> ['Trample'].
keyword_ability --> ['Vigilance'].
keyword_ability --> ['Banding'].
keyword_ability --> ['Rampage'].
keyword_ability --> ['Cumulative Upkeep'].
keyword_ability --> ['Flanking'].
keyword_ability --> ['Phasing'].
keyword_ability --> ['Buyback'].
keyword_ability --> ['Shadow'].
keyword_ability --> ['Cycling'].
keyword_ability --> ['Echo'].
keyword_ability --> ['Horsemanship'].
keyword_ability --> ['Fading'].
keyword_ability --> ['Kicker'].
keyword_ability --> ['Flashback'].
keyword_ability --> ['Madness'].
keyword_ability --> ['Fear'].
keyword_ability --> ['Morph'].
keyword_ability --> ['Amplify'].
keyword_ability --> ['Provoke'].
keyword_ability --> ['Storm'].
keyword_ability --> ['Affinity'].
keyword_ability --> ['Entwine'].
keyword_ability --> ['Modular'].
keyword_ability --> ['Bushido'].
keyword_ability --> ['Soulshift'].
keyword_ability --> ['Splice'].
keyword_ability --> ['Offering'].
keyword_ability --> ['Ninjutsu'].
keyword_ability --> ['Epic'].
keyword_ability --> ['Convoke'].
keyword_ability --> ['Dredge'].
keyword_ability --> ['Transmute'].
keyword_ability --> ['Bloodthirst'].
keyword_ability --> ['Haunt'].
keyword_ability --> ['Replicate'].
keyword_ability --> ['Forecast'].
keyword_ability --> ['Graft'].
keyword_ability --> ['Recover'].
keyword_ability --> ['Ripple'].
keyword_ability --> ['Split Second'].
keyword_ability --> ['Suspend'].
keyword_ability --> ['Vanishing'].
keyword_ability --> ['Absorb'].
keyword_ability --> ['Aura Swap'].
keyword_ability --> ['Delve'].
keyword_ability --> ['Fortify'].
keyword_ability --> ['Frenzy'].
keyword_ability --> ['Gravestorm'].
keyword_ability --> ['Poisonous'].
keyword_ability --> ['Transfigure'].
keyword_ability --> ['Champion'].
keyword_ability --> ['Changeling'].
keyword_ability --> ['Evoke'].
keyword_ability --> ['Hideaway'].
keyword_ability --> ['Prowl'].
keyword_ability --> ['Reinforce'].
keyword_ability --> ['Conspire'].
keyword_ability --> ['Persist'].
keyword_ability --> ['Wither'].
keyword_ability --> ['Retrace'].
keyword_ability --> ['Devour'].
keyword_ability --> ['Exalted'].
keyword_ability --> ['Unearth'].
keyword_ability --> ['Cascade'].
keyword_ability --> ['Annihilator'].
keyword_ability --> ['Level Up'].
keyword_ability --> ['Rebound'].
keyword_ability --> ['Totem Armor'].
keyword_ability --> ['Infect'].
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%mana_ability 25/02/11
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% mana_ability --> [mana].
% mana_ability --> [add,Mana,'to your mana pool'].
%mana_ability --> ['add'],mana,['to', 'your', 'mana', 'pool'].
/* mana_ability --> cost, [:], ['add'],mana,['to', 'your', 'mana', 'pool'].
% Triggered mana ability definitions are probably not correct, see 605.1b
mana_ability --> trigger_word, trigger_event, ['add'],mana,['to', 'your', 'mana', 'pool'].
mana_ability --> trigger_word, trigger_event(X), ['add'],mana,['to', 'your', 'mana', 'pool'].
*/
/* mana_ability --> cost, [:], ['add'],mana,['to'], player(Player), ['mana', 'pool'].
% Triggered mana ability definitions are probably not correct, see 605.1b
mana_ability --> trigger_word, trigger_event, ['add'],mana,['to'], player(Player), ['mana', 'pool'].
mana_ability --> trigger_word, trigger_event(X), ['add'],mana,['to'], player(Player), ['mana', 'pool'].
*/
% mana_ability --> [add],mana,[to], [your, mana, pool]. % probably also needed. Swi, 24/06/11
mana_ability --> cost, [:], [add],mana,[to], [your, mana, pool].
% Triggered mana ability definitions are probably not correct, see 605.1b
mana_ability --> trigger_word, trigger_event, ['add'],mana,['to'], your(X), ['mana', 'pool'].
mana_ability --> trigger_word, trigger_event(X), ['add'],mana,['to'], your(Y), ['mana', 'pool'].
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%loyalty_ability 25/02/11
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%loyalty_ability --> [loyalty Loyalty].
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%cost 25/02/11
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
cost --> mana_cost.
cost --> [tap].
% ^ Will need to deal with "tap a permanent you control" type
% of costs!
cost --> mana_cost, [tap].
cost --> [tap], mana_cost.
mana_cost --> mana.
% mana_cost --> mana(X).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%condition 25/02/11
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% condition: non-terminals
trigger_condition --> trigger_word, trigger_event(_X).
trigger_condition --> trigger_word, trigger_event.
trigger_condition --> trigger_word, trigger_event, [if], condition.
% ^ ie, "When/Whenever/At [trigger event], if [condition], [effect]."
% condition: terminals
trigger_word --> ['When'];['Whenever'];['At'].
%^ needs further disambiguation, otherwise it may accept
% "At enters the battlefield".
trigger_event(X) --> [X], ['enters', 'the', 'Battlefield'].
trigger_event --> [trigger, event, placeholder].
condition --> target(X), [controls], {player(X)}.
%condition --> [condition, placeholder].
/*| ?- phrase(triggered_ability,
['When',trigger,event,placeholder,
if,condition, placeholder,(','),
'Tap',target,'Creature'] ).
yes*/
% Not sure about those above, try phrase(triggered_ability, X).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%effect 25/02/11
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Use to find/ validate an effect's target(s).
effect --> effect(_Target).
effect(Target) --> effect(Target,_Y).
effect(Target) --> effect(Target,_Y,_Z).
effect(Target) --> effect(_X,_Y,Target,_A).
effect(Target) --> effect(_X,_Y,_Z,Target).
effect(Target) --> effect(_X,_Y,Target,_A,_B).
effect(Target) --> effect(Target,_Y,_Z,_A,_B).
effect(Target) --> effect(_X,_Y,_Z,_A,_B,_C,Target,_E).
% Use to determine what is an effect
% effect --> effect(_X).
effect --> effect(_X,_Y).
effect --> effect(_X,_Y,_Z).
effect --> effect(_X,_Y,_Z,_A).
effect --> effect(_X,_Y,_Z,_A,_B).
effect --> effect(_X,_Y,_Z,_A,_B,_C,_D,_E).
effect(X,Y) --> return(X,Y).
effect(X) --> return(X).
effect(X,Y) --> tap(X,Y).
effect(X,Y,Z) --> tap(X,Y,Z).
effect(X,Y) --> untap(X,Y).
effect(X,Y) --> destroy(X,Y).
effect(X,Y) --> regenerate(X,Y).
effect(X,Y) --> exile(X,Y).
effect(X,Y,Z,A) --> deals(X,Y,Z,A).
effect(X,Y,Z) --> deals(X,Y,Z).
effect(X,A,B,C,D) --> gets(X,A,B,C,D).
effect(X) --> gains(X).
effect(X,Y) --> gains(X,Y).
effect(X,Y,Z) --> gains(X,Y,Z).
effect(X,Y,Z) --> gain(X,Y,Z).
effect(X,Y,A,S,Z,B,D,E) --> put(X,Y,A,S,Z,B,D,E).
% effects
return(X) --> (['Return', target] ; [return, target]),
permanent(X), [to, its, 'owner''s', hand].
/*| ?- phrase(return(X), Z).
X = copy('Goblin Balloon Brigade',1,[]) ,
Z = ['Return',target,permanent,to,its,'owner''s',hand] ;*/
return(X,Y) --> (['Return'] ; [return]),
target(X,Y), [to, its, 'owner''s', hand], {permanent_Type(Y)}.
%{Y = 'Artifact';
%Y = 'Creature';
%Y = 'Enchantment';
%Y = 'Land';
%Y = 'Planeswalker'}.
/*| ?- phrase(return(X,Y), Z).
X = 'Goblin Balloon Brigade' ,
Y = 'Creature' ,
Z = ['Return',target,'Creature',to,its,'owner''s',hand] ; */
% Tap target permanent of a specified type with a given keyword ability
tap(X,Y,Z) --> (['Tap'];[tap]), target(X,Y,Z), (condition ; []),{permanent_Type(Y)}.
% Tap target permanent of a specified type
tap(X,Y) --> (['Tap'];[tap]), target(X,Y), (condition ; []),{permanent_Type(Y)}.
% Tap all of a type of permanent
tap(X,Y) --> (['Tap'];[tap]), all(X,Y), (condition ; []).
% ^ No need to specify permanents here (it's done in "all").
% Untap target permanent of a specified type
untap(X,Y) --> (['Untap'];[untap]), target(X,Y), {permanent_Type(Y)}.
% Untap all
untap(X,Y) --> (['Untap'];[untap]), all(X,Y).
% Destroy target permanent ...
destroy(X,Y) --> (['Destroy'];[destroy]), target(X,Y), {permanent_Type(Y)}.
% Destroy all...
destroy(X,Y) --> (['Destroy'];[destroy]), all(X,Y).
% Regenerate...
regenerate(X,Y) --> (['Regenerate'];[regenerate]), target(X,Y), {permanent_Type(Y)}.
% ...all
regenerate(X,Y) --> (['Regenerate'];[regenerate]), all(X,Y).
% Exile...
exile(X,Y) --> (['Exile'];[exile]), target(X,Y), {permanent_Type(Y)}.
% ...all
exile(X,Y) --> (['Exile'];[exile]), all(X,Y).
% Damage to all Z of type A - this doesn't seem to be used in the Oracle
deals_to_all(X,Y,Z,A) --> /*{Z \= []},*/ [X], [deals], [Y], [damage, to], all(Z,A),
{ (A = creatures ; A = planeswalkers ; A = players)}.
% X deals Y Damage to each Z of type A
deals_to_each(X,Y,Z,A) -->
[X], [deals], [Y], [damage, to], each(Z,A),
{ (A = creature ; A = planeswalker ; A = player)}.
/*| ?- phrase(deals_to_each('Pyroclasm',2,Z,creature), Effect).
Z = [object('Goblin Piker' - 1,[])] ,
Effect = ['Pyroclasm',deals,2,damage,to,each,creature] ; */
% X deals Y Damage to each Z of type A and each Z of type B
deals_to_each(X,Y,Z,A,B) -->
[X], [deals], [Y], [damage, to], each(Z,A,B).
{ (A = creature ; A = planeswalker ; A = player),
(B = creature ; B = planeswalker ; B = player) }.
/*| ?- phrase(deals_to_each('Earthquake',Y,Z,creature,player), Effect).
Y = _ ,
Z = [object('Goblin Piker' - 1,[]),'Player 1','Glee-min'] ,
Effect = ['Earthquake',deals,Y,damage,to,each,creature,and,each,player] ; */
% Deal damage to a target creature or Planeswalker, or a target player
% X: source; Y: damage amount; Z: creature; A: player.
deals(X,Y,Z,[]) --> [X], deals_to(Y,Z), [or, player]. % to target creature
deals(X,Y,[],A) --> [X], [deals,Y,damage,to,target,'Creature',or], deals_or(A). %or target player
deals_to(Y,Z) --> [deals], [Y], [damage, to], target(Z,B),
%{ (B = 'Creature' ; B = 'Planeswalker')}. % Planeswalkers are actually player types!
{ (B = 'Creature' ; B = 'Planeswalker')}.
% deals_or(Z), [target] --> target(Z), Swi, ??/06/11
deals_or(Z) --> target(Z),
{ player(Z) }.
/* | ?- phrase(deals('Bolt',3,[],'Player 1'), B).
B = ['Bolt',deals,3,damage,to,target,creature,or,player] ;
no
| ?- phrase(deals('Bolt',3,[],'Player 2'), B).
B = ['Bolt',deals,3,damage,to,target,creature,or,player] ;
no
| ?- phrase(deals('Bolt',3,copy('Goblin Piker',1,[]),[]), B).
B = ['Bolt',deals,3,damage,to,target,'Creature',or,player] ;
no */
% Incorrectly implemented: Planeswalkers
% A source deals damage to a target creature or Planeswlker
deals(X,Y,Z) --> [X], [deals], [Y], [damage, to], target(Z,B),
{ (B = 'Creature' ; B = 'Planeswalker')}.
% A source deals damage to a target player
deals(X,Y,Z) --> [X], [deals], [Y], [damage, to], target(Z),
{ player(Z) }.
% Try also source(X), [deals], amount(X), ... etc.
% Creature buff:
%Target creature gets +3/+3 until end of turn
gets(X,A,B,C,D) --> target(X,Y), [gets,A,B,/,C,D],([until,end,of,turn];[]),
{ (Y = 'Creature')}.
/*| ?- phrase(gets(X,+,1,+,1), Z).
X = copy('Goblin Piker',1,[]) ,
Z = [target,'Creature',gets,+,1,/,+,1,until,end,of,turn] ;*/
% Nope, I don't think that ^looks ^ very fetching.
/*
Remember you can do:
| ?- A = +, B =1, C is A(B).
A = + ,
B = C = 1
| ?- A = +, B =1, C is A(B,2).
A = + ,
B = 1 ,
C = 3
Also, you should be using atom_list to compose the
symbols (+,-,/,etc) in to an atom, but a) atom_list
throws a tantrum with, eg: atom_to_list(X, [+,1,+,1])
(because it doesn't like non-atomic numbers) and b)
if you keep them as atoms you will have to re-numberize
them later for evaluation of the effect.
*/
% Ability graft:
%This permanent gains <keyword> until end of turn
gains(X) --> this(X), [gains],keyword_ability,([until,end,of,turn];[]).
/*| ?- phrase(gains(X), Z).
X = copy('Goblin Balloon Brigade',1,[]) ,
Z = ['Goblin Balloon Brigade',gains,'Flying',until,end,of,turn] ; */
%Target permanent gains <keyword> until end of turn
gains(X,Y) --> target(X,Y), [gains],keyword_ability,([until,end,of,turn];[]),
{ permanent_Type(Y)}.
/*| ?- phrase(gains(X,Y), Z).
X = copy('Goblin Balloon Brigade',1,[]) ,
Y = 'Creature' ,
Z = [target,'Creature',gains,'Deathtouch',until,end,of,turn] ; */
% ^ Not all abilities can be grafted on all permanent types.
% Determine which ones can on what types, with
% keyword_ability = Kw1 ; Kw2 ; Kw3... etc.
% Target player gains control of target permanent (until end of turn).
gains(X,Y,Z) --> target(X), [gains,control,of], target(Y,Z), ([until,end,of,turn] ; []),
{ player(X), permanent_Type(Z)}.
/*| ?- phrase(gains(X,Y,A), Z).
X = 'Player 1' ,
Y = copy('Island',3,[]) ,
A = 'Land' ,
Z = [target,player,gains,control,of,target,'Land',until,end,of,turn] ; */
gain(X,Y,Z), [you] --> you(X), (['Gain'];[gain]),[control,of], target(Y,Z), ([until,end,of,turn]; []),
{ permanent_Type(Z)}.
/*| ?- phrase(gain(X,Y,Z), A).
X = 'Player 1' ,
Y = copy('Goblin Piker',1,[]) ,
Z = 'Creature' ,
A = ['Gain',control,of,target,'Creature',until,end,of,turn] ; */
% A player gains poison counters
gains(X,Y,Z) --> target(X), [gains,A,poison,Z],
{ player(X), (Y = 1, A = a, Z = counter ;
Y \= 1, A = Y, Z = counters) }.
/*| ?- phrase(gain(X,2,Z), A).
X = 'Player 1' ,
Z = counters ,
A = [target,player,gains,2,poison,counters] ; */
% ^ instantiating Y to a number distinguishes from other
% gains/3 clauses.
% It could even happen to you!
gain(X,Y,Z),[you] --> you(X), [gain,A,poison,Z],
{ player(X), (Y = 1, A = a, Z = counter;
Y \= 1, A = Y, Z = counters) }.
% Put X: a/amount,Y: sign,A: value, Z: sign,
% S: slahs or [], B: value, C: counter/counters
% eg: Put 3 +1/-3 counters on target creature.
put(X,Y,A,S,Z,B,D,E) --> [put,M,Y,A,S,Z,B,C,on], target(D,E),
{X = 1, M = a, C = counter ; M = X, C = counters,
permanent_Type(E)}.
/*| ?- phrase(put(1,[],[],[],[],audition,X,Y), D).
X = copy('Goblin Piker',1,[]) ,
Y = 'Creature' ,
D = [put,a,[],[],[],[],audition,counter,on,target,'Creature']
| ?- phrase(put(2,+,1,/,+,1,X,Y), D).
X = copy('Goblin Piker',1,[]) ,
Y = 'Creature' ,
D = [put,2,+,1,/,+,1,counters,on,target,'Creature']
*/ %^ Still needs some work... :\
%%%% Notes %%%%
%%%%%%%%%%%%%%%
/*
% effect --> ['Choose one - '], effect(X), [;], [or], effect(Y).
effect --> mode, effect(X), [;], [or], effect(Y).
%effect(Player) --> mode(Player), effect(X), [;], [or], effect(Y).
% ^ backstack full
mode(Player) --> player(Player), [' chooses one -'].
mode --> ['Choose one - '] ; ['Choose two - '] ; ['Choose one or both- '].
% effect(X) --> ['Choose one'], effect(X).
*/
/* Keep this:
deals(X,Y,Z,A) --> [X], deals_to(Y,Z), [or], [X], deals_or(Y,A).
deals_to(Y,Z) --> [deals], [Y], [damage, to], target(Z,B),
{ (B = 'Creature' ; B = 'Planeswalker')}.
deals_or(Y,Z) --> [deals], [Y], [damage, to], target(Z),
{ player(Z) }.
Because:
| ?- phrase(deals('Bolt',3,Target,Other), Z).
Target = copy('Goblin Piker',1,[]) ,
Other = 'Player 1' ,
Z = ['Bolt',deals,3,damage,to,target,'Creature',or,'Bolt',deals,3,damage,to,target,player] ;
*/
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%activation_instructions 27/02/11
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%activation_instructions --> [with], keyword_ability.
% ^ what, really?
activation_instructions --> [placeholder].
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%all 25/02/11
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% All permanents of a specified type
all(X,Y) --> [all, Y],
{ ( Y = artifacts, T = 'Artifact';
Y = creatures, T = 'Creature';
Y = enchantments, T = 'Enchantment';
Y = lands, T = 'Land';
Y = planeswalkers, T = 'Planeswalker';
Y = permanents
% Btw, this simply replaces the singular, capitalised form
% with the plural, just for some grammatical correctness.
),
findall(Z,
(zone('Battlefield', Cards),
Z = object(Name -_Id,_State),
member(Z, Cards),
check_type(Name, _, [T], _)),
X) }.
/*| ?- phrase(all(Y,creatures), X).
Y = [copy('Goblin Piker',1,[]),copy('Birds of Paradise',1,[])] ,
X = [all,creatures] ;*/
% Instantiate Y to "permanents" to return all permanents.
% Leave undefined, and all permanent types are returned
% in successive backtracking.
% Do: Extend this to cover all types in any zone.
% All players
all(X,Y) --> [all, players],
{Y = players, findall(Z, player(Z), X)}.
/*| ?- phrase(all(X,players), Effect).
X = ['Player 1','Glee-min'] ,
Effect = [all,players]*/
% I'm not sure if "all X and all players" appears anywhere.
all(X,Y,Z) --> ([all] ; ['All']), [Y, and, all, Z],
{(( ((Y = artifacts ; Z = artifacts), T = 'Artifact');
((Y = creatures ; Z = creatures), T = 'Creature');
((Y = enchantments ; Z = enchantments), T = 'Enchantment');
((Y = lands ; Z = lands), T = 'Land');
((Y = planeswalkers ; Z = planeswalkers), T = 'Planeswalker');
(Y = permanents ; Z = permanents)
),
findall(A,
(zone('Battlefield', Cards),
A = object(Name -_Id,_State),
member(A, Cards),
check_type(Name, _, [T], _)),
X1)) , ( (Y = players ; Z = players),
findall(B, player(B), X2) ),
append(X1, X2, X) }.
/*| ?- phrase(all(X,Y,Z), Effect).
X = [object('Goblin Piker' - 1,[]),'Player 1','Glee-min'] ,
Y = creatures ,
Z = players ,
Effect = [all,creatures,and,all,players] ; ;*/
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%each 05/04/11
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This and all are really the same except for number (artifact/artifacts etc).
% It's just that it'll look a bit ugly to disambiguate between them.
% I should generalise number of type atoms later,
% but for now it's clearer like this.
% Each permanent of a specified type
each(X,Y) --> ([each];['Each']), [Y],
{ ( Y = artifact, T = 'Artifact';
Y = creature, T = 'Creature';
Y = enchantment, T = 'Enchantment';
Y = land, T = 'Land';
Y = planeswalker, T = 'Planeswalker';
Y = permanent
% Btw, this simply replaces the singular, capitalised form
% with the plural, just for some grammatical correctness.
),
findall(Z,
(zone('Battlefield', Cards),
Z = object(Name -_Id,_State),
member(Z, Cards),
check_type(Name, _, [T], _)),
X) }.
/*| ?- phrase(each(X,land), Effect).
X = [object('Mountain' - 6,[tapped]),object('Mountain' - 1,[])] ,
Effect = [each,land] ; */
% Each player
each(X,Y) --> ([each];['Each']), [player],
{ Y = player, findall(Z, player(Z), X)}.
/*| ?- phrase(each(X,player), Effect).
X = ['Player 1','Glee-min'] ,
Y = player ,
Effect = ['Each',player] */
% Each permanent of a specified type and each player
each(X,Y,Z) --> ([each] ; ['Each']), [Y, and, each, Z],
{(( ((Y = artifact ; Z = artifact), T = 'Artifact');
((Y = creature ; Z = creature), T = 'Creature');
((Y = enchantment ; Z = enchantment), T = 'Enchantment');
((Y = land ; Z = land), T = 'Land');
((Y = planeswalker ; Z = planeswalker), T = 'Planeswalker');
(Y = permanent ; Z = permanent)
),
findall(A,
(zone('Battlefield', Cards),
A = object(Name -_Id,_State),
member(A, Cards),
check_type(Name, _, [T], _)),
X1)) , (
((Y = player ; Z = player),
findall(B, player(B), X2) ),
append(X1, X2, X)) }.
/*| ?- phrase(each(X,creature,player), Effect).
X = [object('Goblin Piker' - 1,[]),'Player 1','Glee-min'] ,
Effect = [each,creature,and,each,player] ; */
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%target 25/02/11
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
/*
114.2. Only permanents are legal targets for spells and abilities,
unless a spell or ability
(a) specifies that it can target an object in another zone
or a player,
(b) targets an object that can't exist on the battlefield,
such as a spell or ability, or
(c) targets a zone.
*/
target --> target(X).
target --> target(X,Y).
target --> target(X,Y,Z).
%target(X,Y) --> target(X), ([or]; [and] ; [',']), target(Y).
%target --> target, target. % not too useful.
% eg: phrase(target,[target,'Creature',and,target,player]).
% phrase(target,[target,'Creature',or,player]).
% A target can be a permanent of a specified type,
% with a keyword ability.
target(X,Y,Z) --> [target, Y], [with,Z], %keyword_ability(Z),
{zone('Battlefield', Cards),
X = object(Name -_Id,_State),
member(X, Cards),
check_type(Name, _, [Y], _),
card([card_name Name, _, _, text_box Text_box, _, _, _, _]),
member(A, Text_box) ,phrase(keyword_ability(A),A),
[Z] = A}. %remove brackets
/*| ?- phrase(target(X,Y,Z), A).
X = copy('Air Servant',1,[]) ,
Y = 'Creature' ,
Z = 'Flying' ,
A = [target,'Creature',with,'Flying'] */
%^ Temp patch until I fix BoP Mana ability
% (it clashes with determine_ability/2
/*determine_abilities(Name, Abilities),
member(Z,Abilities)}.*/
% A target can be a permanent of a specified type.
% target(X,Y) --> [target, Y],
target(X,Y) --> ([target];['Target']), [Y],
{zone('Battlefield', Cards),
X = object(Name -_Id,_State),
member(X, Cards),
check_type(Name, _, [T], _) ,
invert_case(Y, T)}. % This does something weird...
/*| ?- phrase(target(X,Y), Z).
X = copy('Goblin Piker',1,[]) ,
Y = creature ,
Z = [target,creature] ;*/ % Alternative to >
% A target can be a permanent of a certain type.
% target(X) --> [target, Y],
target(X) --> ([target];['Target']), [Y],
{zone('Battlefield', Cards),
X = object(Name -_Id,_State),
member(X, Cards),
check_type(Name, _, [Y], _)}.
/*| ?- phrase(target(X), Z ).
X = 'Goblin Balloon Brigade' ,
Z = [target,'Creature'] ;
X = 'Mountain' ,
Z = [target,'Land'] ; */
% A target can be a permanent of a type other than one specified.
% target(X) --> [target, non, - ,Y], object(X),
target(X) --> ([target];['Target']), [non, - ,Y], object(X),
{ X = object(Name -_Id,_State),
\+ check_type(Name, _, [Y], _) }.
/* | ?- phrase(target(X), [target, non, - ,'Land',permanent]).
X = copy('Goblin Balloon Brigade',1,[]) ; */
% A target can be an object, reporting its type and
% object class (permanent or spell, basically)
% target(X) --> [target, Y], object(X,Y).
target(X) --> ([target];['Target']), [Y], object(X,Y).
/*| ?- phrase(target(X), Z).
X = copy('Goblin Balloon Brigade',1,[]) ,
Z = [target,['Creature'],spell] ;
% ^ Good start, but then... >
X = copy('Mountain',1,[tapped]) ,
Z = [target,['Land'],permanent] ;*/
% A target can be any object, reporting its object class
% (permanent, spell etc)
% target(X) --> [target], object(X).
target(X) --> ([target];['Target']), object(X).
/*| ?- phrase(target(X), A).
X = copy('Goblin Balloon Brigade',1,[]) ,
A = [target,spell] ;
X = copy('Mountain',1,[tapped]) ,
A = [target,permanent] ;
| ?- phrase(target(copy('Goblin Balloon Brigade',1,[])), A).
A = [target,spell] ;
| ?- phrase(target(X), [target,spell]).
X = copy('Goblin Balloon Brigade',1,[]) */
% A target can be a player:
% target(X) --> [target], player(X).
target(X) --> ([target];['Target']), player(X).
/*| ?- phrase(target(X), Y).
X = 'Player 1' ,
Y = [target,player]
| ?- phrase(target('Player 2'), [target,player]).
yes*/
% Note you could also call the non-DCG player/1 directly,
% but it's useful to identify what the DCG player(X) is too.
% Same for all X's
% A target can be a partition
% target(X) --> [target, X],
target(X) --> ([target];['Target']), [X],
{zone(X),
(\+ X='Stack', \+ X='Battlefield', \+ X='Exile') }.
/*| ?- phrase(target(X), Y).
X = 'Library' ,
Y = [target,'Library'] ;*/
% A target can be a partition, naming the player.
% target(X,Y) --> [target,'player''s',Y],
target(X,Y) --> ([target];['Target']),['player''s',Y],
{ player(X), zone(Y),
(\+ Y='Stack', \+ Y='Battlefield', \+ Y='Exile') }.
/*| ?- phrase(target(X,Y), A).
X = 'Player 1' ,
Y = 'Library' ,
A = [target,'player''s','Library']
| ?- phrase(target('Player 2','Hand'), [target,'player''s','Hand']).
yes*/
% target(X,Y,Z) --> [target], zone(X,Y,Z).
target(X,Y,Z) --> ([target];['Target']), zone(X,Y,Z).
/*| ?- phrase(target(X,Y,Z), A).
X = 'Player 1' ,
Y = 'Hand' ,
Z = ['Prodigal Pyromancer','Prodigal Pyromancer','Goblin Balloon Brigade','Mountain','Lava Axe','Vulshok Berserker'] ,
A = [target,'Hand'] ;*/
% ^ alternative way to say "target zone", plus player/conents info.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%zone 12/03/11
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% A player's partitions
zone(X,Y) --> player(X),['s'],zone(X,Y,Z), [Z],
{ \+ Y='Stack', \+ Y='Battlefield', \+ Y='Exile' }.
/*| ?- phrase(zone(X,Y), Z).
X = 'Player 1' ,
Y = 'Library' ,
Z = [player,s,'Library',[]] ;
| ?- phrase(zone('Player 1','Library'), [_,_,_,D]).
D = [] ; % Power!!
| ?- phrase(zone(X,Y), [player,s,'Stack',D]).
no*/
% A target can be a shared zone. Wait. Can it? No, it can't.
% "the" is not a target (nor is "a").
zone(X,Y) --> [the,X], {zone(X,Y)}.
/*X = 'Stack' ,
Y = [] ,
A = [the,'Stack'] ;*/
% A player's partitions, naming "you": _your_ partition.
zone(X,Y) --> [your],zone(X,Y,Z), [Z],
{player(X),
\+ Y='Stack', \+ Y='Battlefield', \+ Y='Exile' }.
/*| ?- phrase(zone(X,Y), Z).
X = 'Player 1' ,
Y = 'Hand' ,
Z = [your,'Hand',['Prodigal Pyromancer','Prodigal Pyromancer',
'Goblin Balloon Brigade','Mountain','Lava Axe','Vulshok Berserker']] */
% Partitions by player
zone(X,Y,Z) --> [Y], {zone(X,Y,Z)},
{ \+ Y='Stack', \+ Y='Battlefield', \+ Y='Exile' }.
/*| ?- phrase(zone(X,Y,Z), A).
X = 'Player 1' ,
Y = 'Library' ,
Z = [] ,
A = ['Library'] ;
| ?- phrase(zone(X,'Exile',Z), A).
no */ % ^ used with "target zone" etc.
% Shared zones
zone(X,Y) --> [X], {zone(X,Y)}.
/*| ?- phrase(zone(X,Y), A).
X = 'Exile' ,
Y = [] ,
A = ['Exile']*/
% ^ Use?
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%player 12/03/11
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% A player is a player
player(X) --> [player], {player(X)}.
/*| ?- phrase(player('Player 1'), X).
X = [player]
| ?- phrase(player('Player 1'), [player]).
yes */
% Called with effect(X), [you] --> player(X)...
% to remove the explicit "you" before, eg "Gain control"...
you(X) --> [you], {player(X)}.
/*| ?- phrase(you(X), Y).
X = 'Player 1' ,
Y = [you] ;*/
your(X) --> [your], {player(X)}.
% ^ untested and caused problems.
%%%% Notes %%%%
%%%%%%%%%%%%%%%
/*
"You" and "your" are not really players, rather an Object's controller: 109.5
Also of course it is used to identify a player's zones, but
I can't find that explicitly declared in the rules.
Also, it's used to find a player's mana pool, life total and so on.
So I should define them like players, or pointers to players.
Doing so caused problems- check notes on 14-03-11-2
A player can also be a Planeswalker!
I'm not implementing them yet, so it's fudged, above
(especially where things target "creature or player" etc.
*/
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%object 12/03/11
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
/* 109.1. An object is an ability on the stack,
a card, a copy of a card, a token, a spell,
a permanent, or an emblem.
*/
% An object of a specific type
object(X,Y) --> object(X),
{ X = object(Name -_Id,_State),
check_type(Name, _, [Y], _)}.
/* |?- phrase(object(X,Y), A).
X = copy('Goblin Balloon Brigade',1,[]) ,
Y = 'Creature' ,
A = [spell] ;
X = copy('Mountain',1,[tapped]) ,
Y = 'Land' ,
A = [permanent] ;*/
% ^ hm. Again not quite correct MGL, always
% "Creature Spell" is OK, but "Land Peramanent? Hm. Yeah,
% OK, but not what I wanted.
% An object is a spell on the Stack
object(X) --> spell(X).
% spell(X) --> [spell],
spell(X) --> ([spell];[ability]), % not tested
{ X = object(_Name -_Id,_State),
zone('Stack', Objects),
member(X, Objects) }.
/*| ?- phrase(spell(X), A).
X = copy('Goblin Balloon Brigade',1,[]) ,
A = [spell] ;*/
% An object is a permanent, or token on the Battlefield
object(X) --> permanent(X). %[X],
permanent(X) --> [permanent],
{ X = object(_Name -_Id,_State),
zone('Battlefield', Objects),
member(X, Objects) }.
/* | ?- phrase(permanent(X), A).
X = copy('Mountain',1,[tapped]) ,
A = [permanent] ; */
% An object is an emblem in the Command zone)
object(X) --> emblem(X).
emblem(X) --> [emblem],
{ X = object(_Name -_Id,_State),
zone('Command', Objects),
member(X, Objects) }.
/* no emblems -> tests yet*/
% An object is a card in a zone
% (other than the Battlefield or Stack)
object(X,Y,Z) --> card(X,Y,Z).
% Call as for card/3 is not correct MGL.
% An object that is a spell can refer to itself
% by its card name, if its card name is part of one of its abilities.
this(X), [spell] --> object(X), [Name],
{X = object(Name - _Id, _State),
card([card_name Name, _, _, text_box Text, _, _, _, _]),
member(Ability, Text),
member(Name, Ability) }.
% ^ Should use determine_abilities/2
% An object that is an ability on the Stack can refer to itself
% by its card name, if its card name is part of its text.
/* this(X), [ability] --> object(X), [Name],
{X = object(Name - _Id, _State),
card([card_name Name, _, _, text_box Text, _, _, _, _]),
member(Ability, Text),
member(Name, Ability) }.
*/ % ^ Not like this- later.
% An object that is a permanent can refer to itself
% by its card name, if its card name is part of one of its abilities.
this(X), [permanent] --> object(X), [Name],
{X = object(Name - _Id, _State),
card([card_name Name, _, _, text_box Text, _, _, _, _]),
member(Ability, Text),
member(Name, Ability) }.
/*| ?- phrase(this(X), Z).
X = copy('Goblin Balloon Brigade',1,[]) ,
Z = ['Goblin Balloon Brigade'] ; */
% An object that is a card can have an ability that refers to
% a permanent or a spell with its card name, if its card name
% is part of one of its abilities. The card is in a zone, other
% than the stack (but not just in the database).
%this(Name) --> [Name],
this(Name) --> card(Name),
{card([card_name Name, _, _, text_box Text, _, _, _, _]),
member(Ability, Text),
member(Name, Ability) }.
/*| ?- phrase(this(X), Y).
X = 'Aether Adept' ,
Y = ['Aether Adept'] ;
...
X = 'Pyroclasm' ,
Y = ['Pyroclasm'] ;