This repository has been archived by the owner on Sep 20, 2020. It is now read-only.
forked from Anniepoo/prolog-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMonstersAndMazes.pl
132 lines (114 loc) · 3.1 KB
/
MonstersAndMazes.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
base_score(might, 11).
base_score(skill, 12).
base_score(wits, 16).
base_score(luck, 16).
base_score(will, 13).
base_score(grace, 11).
% Begin defining derived Predicates.
attribute(might).
attribute(wits).
attribute(skill).
attribute(luck).
attribute(will).
attribute(grace).
modifier(Attribute, Out_Mod) :-
attribute(Attribute),
base_score(Attribute, Score),
modifier2(Score, Out_Mod).
modifier2(1, -4).
modifier2(2, -4).
modifier2(3, -3).
modifier2(4, -3).
modifier2(5, -2).
modifier2(6, -2).
modifier2(7, -1).
modifier2(8, -1).
modifier2(X, 0) :- X >= 9, X =< 12.
modifier2(X, 1) :- X >= 13, X =< 14.
modifier2(X, 2) :- X >= 15, X =< 16.
modifier2(X, 3) :- X >=17, X =< 18.
modifier2(X, 4) :- X >= 19, X =< 20.
:- discontiguous(score/2).
score(melee_score, Score) :- melee_score(Score).
melee_score(Score) :-
modifier(might, X),
modifier(skill, Y),
modifier(luck, Z),
Score is X + Y + Z, !.
score(missile_score, Score) :- missile_score(Score).
missile_score(Score) :-
modifier(skill, X),
modifier(wits, Y),
modifier(luck, Z),
Score is X + Y + Z, !.
score(initiative_score, Score) :- initiative_score(Score).
initiative_score(Score) :-
modifier(skill, X),
modifier(luck, Y),
Score is 10 + X + Y, !.
score(defense_class, Score) :- defense_class(Score).
defense_class(Score) :-
modifier(luck, X),
armor(Y),
Score is 12 + X + Y.
score(hits_total, Score) :- hits_total(Score).
hits_total(Score) :-
modifier(skill, Y),
Score is 10 + Y.
score(effective_defense, Score) :- effective_defense(Score).
effective_defense(Score) :-
armor(Armor),
defense_class(Defense),
modifier(wits, Wits),
Score is Armor + Defense + Wits.
score(athletic_prowess, Score) :- athletic_prowess(Score).
athletic_prowess(Score) :-
modifier(might, Might),
modifier(skill, Skill),
modifier(luck, Luck),
Score is Might + Skill + Luck.
score(danger_evasion, Score) :- danger_evasion(Score).
danger_evasion(Score) :-
modifier(wits, Wits),
modifier(skill, Skill),
modifier(luck, Luck),
Score is Wits + Skill + Luck.
score(mystic_fort, Score) :- mystic_fort(Score).
mystic_fort(Score) :-
modifier(will, Will),
modifier(wits, Wits),
modifier(luck, Luck),
Score is Will + Wits + Luck.
score(physical_vigor, Score) :- physical_vigor(Score).
physical_vigor(Score) :-
modifier(might, Might),
modifier(will, Will),
modifier(luck, Luck),
Score is Might + Will + Luck.
score(charisma, Score) :- charisma(Score).
charisma(Score) :-
modifier(will, Will),
modifier(grace, Grace),
modifier(luck, Luck),
Score is Will + Grace + Luck.
score(thievery, Score) :- thievery(Score).
thievery(Score) :-
modifier(wits, Wits),
modifier(luck, Luck),
Score is Wits + Luck.
score(armor, Score) :- armor(Score).
armor(Score) :-
Score is 0.
d20_check(Type, Result) :-
score(Type, Score),
random_between(1, 20, Die),
Result is Score + Die,
!,
format("Result was ~p!", Result).
d20_check(Type, Result, Threshold) :-
d20_check(Type, Result),
(Threshold =< Result,
format("~n Result successful."), !) |
format("~n Roll failed."), !.
rollables(Bag) :-
findall(X, score(X, _), Bag).