forked from ppaml-op3/insomnia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtugOfWar.ism
101 lines (76 loc) · 2 KB
/
tugOfWar.ism
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
import "examples/Prelude.ism" (module Prelude)
PLAYER = model type {
sig pulling_power : Real
}
PLAYER_M = module type {
sig pulling_power : Real
}
PERSON = model type {
sig strength : Real
PullingPower : PLAYER
}
PERSON_M = module type {
sig strength : Real
PullingPower : PLAYER
}
NormalPerson : PERSON = model {
val strength ~ Prelude.normal { μ = 10.0 , σ² = 2.0 }
PullingPower = model {
val lazy ~ Prelude.flip 0.1
val pulling_power = let
(laziness_factor : Real) = case lazy of
Prelude.True -> 0.5
Prelude.False -> 1.0
in laziness_factor Prelude.*. strength
}
}
----------------------------------------
Winner = module {
data Winner = FirstPlayerWins | SecondPlayerWins
}
MATCH_RESULT = model type {
sig winner : Winner.Winner
}
TugOfWarMatch = (P1 : PLAYER, P2 : PLAYER) -> (model {
Player1 ~ P1
Player2 ~ P2
val winner = case Player1.pulling_power Prelude.<. Player2.pulling_power of
Prelude.True -> Winner.SecondPlayerWins
Prelude.False -> Winner.FirstPlayerWins
} : MATCH_RESULT)
----------------------------------------
HULK = module type {
sig strength : Real
}
HULK_OR_BRUCE = model type {
Hulk : HULK
Bruce : PERSON_M
PullingPower : PLAYER
}
HulkOrBruce : HULK_OR_BRUCE = model {
val hulk_strength ~ Prelude.normal { μ = 100.0 , σ² = 20.0 }
Hulk = module {
val strength = hulk_strength
}
Bruce ~ NormalPerson
PullingPower = model {
val isAngry ~ Prelude.flip 0.3
BPP ~ Bruce.PullingPower
-- Bruce may be lazy, Hulk isn't
val pulling_power ~ case isAngry of
Prelude.True -> return Hulk.strength
Prelude.False -> return BPP.pulling_power
}
}
----------------------------------------
Normal_Matchup = model {
Jill ~ NormalPerson
Hank ~ NormalPerson
Result ~ TugOfWarMatch (Jill.PullingPower , Hank.PullingPower)
}
Earth616_Matchup = model {
Peter ~ NormalPerson
H ~ HulkOrBruce
Result ~ TugOfWarMatch (Peter.PullingPower , H.PullingPower)
}
query sample Earth616_Matchup 10