-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer-deflection.sml
169 lines (132 loc) · 4.26 KB
/
player-deflection.sml
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
structure Deflection :> LAYER =
struct
open LTG;
open Kompiler;
open AbstractEval;
structure GS = GameState
infix 9 --
val op -- = Apply
val $ = Var
fun \ x exp = Lambda (x, exp)
infixr 1 `
fun a ` b = a b
fun printside (values, vitalities) =
let
val _ = eprint "values :\n"
val _ = Util.for 0 255 (fn i => eprint ((valtos ` Array.sub(values, i) ) ^ " "))
val _ = eprint "\n"
val _ = eprint "vitalities :\n"
val _ = Util.for 0 255 (fn i => eprint ((Int.toString ` Array.sub(vitalities, i) ) ^ " "))
val _ = eprint "\n"
in () end
fun iscode(v) =
case v of
VFn(VI) => false
| VFn(f) => true
| VInt(i) => false
fun isnumber(v) =
case v of
VInt(i) => true
| _ => false
fun array2list a =
List.tabulate(Array.length a, fn i => Array.sub(a,i))
val n = ref 0
fun doevals gs =
let
val myside = GS.myside gs
val theirside = GS.theirside gs
val (values, vitalities) = theirside
val vlist = array2list(values)
fun aux code = (
let
val _ = eprint "found some code\n"
val _ = eprint ` valtos code ^ "\n"
val _ = eprint "it has the following effects\n"
val abscode = AV ` abstractify code
val reseffects =
evalwithstate1 30 NORMAL (theirside, myside) abscode
val _ = eprint `
StringUtil.delimit ", " (map effect2str reseffects)
val _ = eprint "\n"
in () end
)
val codes = List.filter iscode vlist
val _ = map aux codes
val _ = eprint "\n"
in
()
end
fun examinenumbers gs =
let
fun printnum (i, v) = case v of
VInt n => eprint ` Int.toString i ^ ": " ^ Int.toString n ^ ", "
| _ => ()
val myside = GS.myside gs
val theirside = GS.theirside gs
val (values, vitalities) = theirside
val _ = eprint "numbers:\n"
val _ = Array.appi printnum values
val _ = eprint "\n"
in () end
fun dohelp helperslot j =
[]
fun buildapplier slot =
[LeftApply (K, slot),
LeftApply (S, slot),
RightApply (slot, Get) ]
(* assume that the slot starts with I *)
fun copyapplier slot =
[RightApply (slot, Zero),
LeftApply (Succ, slot),
LeftApply (Get, slot)]
val prog1 = \ "x" ` Card (Help) -- (Card Get -- (Int 2)) -- (Card Get -- (Int 4)) -- $"x"
val opening =
(Macros.fastnum 0 8192) @
( compile prog1 1) @
(buildapplier 1) @
(copyapplier 3) @
(Macros.fastnum 2 1) @
(Macros.fastnum 4 0)
val nextthing =
[RightApply (3, Zero)] @
(copyapplier 3) @
[ LeftApply (Succ,2),
LeftApply (Succ,4)]
val instructions = ref opening
fun countins prog = List.length (compile prog 0)
val _ = eprint ` "opening inses: " ^ Int.toString (List.length opening) ^ "\n"
val reviving = ref false
fun updateinstructions gs =
let
val myside = GS.myside gs
val theirside = GS.theirside gs
val (theirvalues, theirvitalities) = theirside
in
if List.null (!instructions)
then instructions := nextthing
else ()
end
fun init gs = ()
fun taketurn gs =
let
val () = n := !n + 1
val _ = eprint ` "\nturn " ^ Int.toString (!n) ^ ": "
val myside = GS.myside gs
val theirside = GS.theirside gs
(* val _ = printside myside *)
val _ = doevals gs
val _ = examinenumbers gs
val () = updateinstructions gs
val (ins,inses) = (List.hd (!instructions), List.tl (!instructions))
val _ = instructions := inses
val _ = case ins
of LeftApply (Revive, n) => ()
(* reviving := false;
instructions := (!oldinscontext)
*)
| _ => ()
in
ins
end
end
structure Player = LayerFn(Deflection)