-
Notifications
You must be signed in to change notification settings - Fork 0
/
player-jcreed.sml
142 lines (107 loc) · 3.53 KB
/
player-jcreed.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
structure Jcreed :> LAYER =
struct
structure GS = GameState
structure K = Kompiler
datatype src = datatype K.src
datatype card = datatype Card.card
open CardHelp
val L = LTG.LeftApply
val R = LTG.RightApply
fun init gs = ()
infix 9 --
val op -- = Apply
val $ = Var
fun \ x exp = Lambda (x, exp)
infix 1 `
fun a ` b = a b
datatype todo =
List of Macros.turn list * todo
| Move of (src * int) * todo
| Call of int * todo
| Fn of GS.gamestate -> todo
| Nil
infixr 2 @@
val op @@ = Move
infixr 2 @@>
val op @@> = Call
infixr 2 @@>>
val op @@>> = List
val counter = ref 0
val debugs = ref 50
val battery = 0
val slosh = 1
val slosh2 = 2
val small = 0
val big = 1
val med = 2
val loc = 3
val cThresh = 47000
val aThresh = 58200
val codeseg = ref 4
val codes = ref []
fun install x = let
val n = !codeseg
val _ = codeseg := !codeseg + 1
val _ = codes := (K.rrs_ref x n, n) :: !codes
in
n
end
fun dprint x = (if !debugs > 0 then (debugs := !debugs - 1; eprint (Int.toString (!counter) ^ " " ^ x ^ "\n")) else ())
fun also [] x = x
| also (h::tl) x = h @@ also tl x
fun andthen (x, y) = (\ "_" ` y) -- x
(* fun andthen (x, y) = put x y *)
infixr 0 andthen
val helpSmall = install (help ` Int battery ` Int battery ` get (Int small))
val slosher = install (put (help ` Int battery ` Int battery ` get (Int big)) (help ` Int battery ` Int battery ` get (Int big)))
val ass = install (attack ` Int battery ` (get (Int loc)) ` get (Int med))
val script = ref Nil
fun charge sweep gs = let
val (_, vits) = GS.myside gs
val v = Array.sub (vits , battery)
val attacker = ass (* if sweep then sweeper else ass *)
val plan = if sweep
then attacker @@> [L(Succ, loc)] @@>> Fn (charge true)
else attacker @@> (zero, loc) @@ Fn (charge true)
in
if v < 10000
then (dprint ("Rebooting!"); (revive ` Int 0, 1)
@@ (help ` Int slosh ` Int battery ` Int 5000, 1)
@@ (help ` Int slosh2 ` Int battery ` Int 5000, 1) @@ Fn main)
else if (v <= cThresh)
then helpSmall @@> Fn (charge sweep)
else if (v < aThresh)
then slosher @@> Fn (charge sweep)
else (dprint("Attacking"); plan)
end
and main gs = (Int 255, loc) @@ (Int 11112, med) @@ (Int cThresh, big) @@ (Int 9999, small) @@ also (!codes) (Fn (charge false))
and prefix gs = Macros.doubleshot 255 2 3 @@>> Fn main
fun valtos (LTG.VInt i) = Int.toString i
| valtos (LTG.VFn f) = let val s = LTG.ftos f in substring(s, 0, Int.min(size s - 1, 10)) end
fun tt entry gs = let
fun f Nil = go ` entry gs
| f (List(t::ts, next)) = (script := List (ts, next); t)
| f (List([], next)) = go next
| f (Move((p,n), next)) = go ` List (K.compile p n, next)
| f (Fn f) = go ` f gs
| f (Call(i, next)) = (script := next; R (i, Zero))
and go x = (script := x; f (!script))
val (vals, vits) = GS.myside gs
fun showscores () =
if ((Array.sub(vits,0) > 45000) orelse Array.sub(vits, 1) > 10000 )
then let
val vitsmap = List.tabulate (8, fn x => (Int.toString (Array.sub (vits,x))))
val valsmap = List.tabulate (8, fn x => (valtos (Array.sub (vals,x))))
in
dprint ("f=["^(String.concatWith "," valsmap)^"]\n");
dprint ("v=["^(String.concatWith "," vitsmap)^"]\n")
end
else ()
val _ = counter := (!counter) + 1
in
showscores();
f (!script)
end
fun taketurn gs = tt main gs
end
structure Player = LayerFn(Jcreed)