Mercurial > repos > icfp2013
annotate src/requests.tp @ 48:855c05c9cae1
Updated myproblems.json. Some solver fixes
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 11 Aug 2013 04:03:51 -0700 |
parents | e9e01cd64993 |
children | 8409af16d6e5 |
rev | line source |
---|---|
10
79c1db5e7ebd
sending broken file for mike to check error
William Morgan <bill@mrgn.org>
parents:
diff
changeset
|
1 #{ |
18 | 2 |
20 | 3 strJoin <- :str arr { |
4 acc <- "" | |
5 arr foreach: :i el { | |
6 if: i = 0 { | |
7 acc <- (string: el) | |
8 } else: { | |
9 acc <- acc . ", " . (string: el) | |
10 } | |
11 } | |
12 acc | |
13 //arr fold: "" with: :acc el {acc . el} | |
14 } | |
15 | |
18 | 16 quote <- :str { |
24
e1109e33b796
some work that probably needs to be trashed on requests.tp
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
17 "\"" . str . "\"" |
18 | 18 } |
19 | |
24
e1109e33b796
some work that probably needs to be trashed on requests.tp
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
20 println <- :str { |
23 | 21 print: str . "\n" |
22 } | |
23 | |
30
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
24 fixArgs <- :args { |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
25 args map: :el { |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
26 "\"0x" . (hex: el) . "\"" |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
27 } |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
28 } |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
29 |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
30 |
25
bb80f86c5048
Added code for sending and decoding the responses of evalRequests
Mike Pavone <pavone@retrodev.com>
parents:
24
diff
changeset
|
31 evalId <- :id args { |
30
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
32 args <- fixArgs: args |
12
7d8b8f82cbef
Help Bill work around some compiler bugs
Mike Pavone <pavone@retrodev.com>
parents:
10
diff
changeset
|
33 #{ |
7d8b8f82cbef
Help Bill work around some compiler bugs
Mike Pavone <pavone@retrodev.com>
parents:
10
diff
changeset
|
34 string <- { |
20 | 35 idStr <- (quote: "id") . ":" . (quote: id) |
30
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
36 argsStr <- (quote: "arguments") . ":[" . (strJoin: "," args) . "]" |
18 | 37 "{" . idStr . "," . argsStr . "}" |
12
7d8b8f82cbef
Help Bill work around some compiler bugs
Mike Pavone <pavone@retrodev.com>
parents:
10
diff
changeset
|
38 } |
30
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
39 sendWithKey <- :key { |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
40 print: "Sending: " . string . "\n" |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
41 cli <- http client: "icfpc2013.cloudapp.net" |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
42 resp <- cli post: string toPath: "/eval?auth=" . key withType: "application/json" |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
43 evalResponse: resp |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
44 } |
12
7d8b8f82cbef
Help Bill work around some compiler bugs
Mike Pavone <pavone@retrodev.com>
parents:
10
diff
changeset
|
45 } |
7d8b8f82cbef
Help Bill work around some compiler bugs
Mike Pavone <pavone@retrodev.com>
parents:
10
diff
changeset
|
46 } |
10
79c1db5e7ebd
sending broken file for mike to check error
William Morgan <bill@mrgn.org>
parents:
diff
changeset
|
47 |
25
bb80f86c5048
Added code for sending and decoding the responses of evalRequests
Mike Pavone <pavone@retrodev.com>
parents:
24
diff
changeset
|
48 evalProgram <- :program args { |
30
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
49 args <- fixArgs: args |
25
bb80f86c5048
Added code for sending and decoding the responses of evalRequests
Mike Pavone <pavone@retrodev.com>
parents:
24
diff
changeset
|
50 #{ |
bb80f86c5048
Added code for sending and decoding the responses of evalRequests
Mike Pavone <pavone@retrodev.com>
parents:
24
diff
changeset
|
51 string <- { |
bb80f86c5048
Added code for sending and decoding the responses of evalRequests
Mike Pavone <pavone@retrodev.com>
parents:
24
diff
changeset
|
52 progStr <- (quote: "program") . ":" . (quote: program) |
bb80f86c5048
Added code for sending and decoding the responses of evalRequests
Mike Pavone <pavone@retrodev.com>
parents:
24
diff
changeset
|
53 argsStr <- (quote: "arguments") . ":[" . (strJoin: "," args) . "]" |
bb80f86c5048
Added code for sending and decoding the responses of evalRequests
Mike Pavone <pavone@retrodev.com>
parents:
24
diff
changeset
|
54 "{" . progStr . "," . argsStr . "}" |
bb80f86c5048
Added code for sending and decoding the responses of evalRequests
Mike Pavone <pavone@retrodev.com>
parents:
24
diff
changeset
|
55 } |
bb80f86c5048
Added code for sending and decoding the responses of evalRequests
Mike Pavone <pavone@retrodev.com>
parents:
24
diff
changeset
|
56 sendWithKey <- :key { |
bb80f86c5048
Added code for sending and decoding the responses of evalRequests
Mike Pavone <pavone@retrodev.com>
parents:
24
diff
changeset
|
57 print: "Sending: " . string . "\n" |
bb80f86c5048
Added code for sending and decoding the responses of evalRequests
Mike Pavone <pavone@retrodev.com>
parents:
24
diff
changeset
|
58 cli <- http client: "icfpc2013.cloudapp.net" |
bb80f86c5048
Added code for sending and decoding the responses of evalRequests
Mike Pavone <pavone@retrodev.com>
parents:
24
diff
changeset
|
59 resp <- cli post: string toPath: "/eval?auth=" . key withType: "application/json" |
bb80f86c5048
Added code for sending and decoding the responses of evalRequests
Mike Pavone <pavone@retrodev.com>
parents:
24
diff
changeset
|
60 evalResponse: resp |
bb80f86c5048
Added code for sending and decoding the responses of evalRequests
Mike Pavone <pavone@retrodev.com>
parents:
24
diff
changeset
|
61 } |
bb80f86c5048
Added code for sending and decoding the responses of evalRequests
Mike Pavone <pavone@retrodev.com>
parents:
24
diff
changeset
|
62 } |
bb80f86c5048
Added code for sending and decoding the responses of evalRequests
Mike Pavone <pavone@retrodev.com>
parents:
24
diff
changeset
|
63 } |
bb80f86c5048
Added code for sending and decoding the responses of evalRequests
Mike Pavone <pavone@retrodev.com>
parents:
24
diff
changeset
|
64 |
31
8a2925ab0d4a
working guess request and response.
William Morgan <bill@mrgn.org>
parents:
30
diff
changeset
|
65 guess <- :id :prog { |
15
18ec9131f594
one more compiler bug for mike.
William Morgan <bill@mrgn.org>
parents:
14
diff
changeset
|
66 #{ |
18ec9131f594
one more compiler bug for mike.
William Morgan <bill@mrgn.org>
parents:
14
diff
changeset
|
67 string <- { |
17
566960135ea1
Small bit of cleanup now that the string escaping bug is fixed.
Mike Pavone <pavone@retrodev.com>
parents:
16
diff
changeset
|
68 idStr <- "\"id\":\"" . id . "\"" |
566960135ea1
Small bit of cleanup now that the string escaping bug is fixed.
Mike Pavone <pavone@retrodev.com>
parents:
16
diff
changeset
|
69 progStr <- "\"program\":\"" . prog . "\"" |
566960135ea1
Small bit of cleanup now that the string escaping bug is fixed.
Mike Pavone <pavone@retrodev.com>
parents:
16
diff
changeset
|
70 "{" . idStr . "," . progStr . "}" |
15
18ec9131f594
one more compiler bug for mike.
William Morgan <bill@mrgn.org>
parents:
14
diff
changeset
|
71 } |
31
8a2925ab0d4a
working guess request and response.
William Morgan <bill@mrgn.org>
parents:
30
diff
changeset
|
72 sendWithKey <- :key { |
8a2925ab0d4a
working guess request and response.
William Morgan <bill@mrgn.org>
parents:
30
diff
changeset
|
73 print: "Sending: " . string . "\n" |
8a2925ab0d4a
working guess request and response.
William Morgan <bill@mrgn.org>
parents:
30
diff
changeset
|
74 cli <- http client: "icfpc2013.cloudapp.net" |
8a2925ab0d4a
working guess request and response.
William Morgan <bill@mrgn.org>
parents:
30
diff
changeset
|
75 resp <- cli post: string toPath: "/guess?auth=" . key withType: "application/json" |
8a2925ab0d4a
working guess request and response.
William Morgan <bill@mrgn.org>
parents:
30
diff
changeset
|
76 guessResponse: resp |
8a2925ab0d4a
working guess request and response.
William Morgan <bill@mrgn.org>
parents:
30
diff
changeset
|
77 } |
15
18ec9131f594
one more compiler bug for mike.
William Morgan <bill@mrgn.org>
parents:
14
diff
changeset
|
78 } |
18ec9131f594
one more compiler bug for mike.
William Morgan <bill@mrgn.org>
parents:
14
diff
changeset
|
79 } |
18ec9131f594
one more compiler bug for mike.
William Morgan <bill@mrgn.org>
parents:
14
diff
changeset
|
80 |
25
bb80f86c5048
Added code for sending and decoding the responses of evalRequests
Mike Pavone <pavone@retrodev.com>
parents:
24
diff
changeset
|
81 evalResponse <- :httpResp { |
bb80f86c5048
Added code for sending and decoding the responses of evalRequests
Mike Pavone <pavone@retrodev.com>
parents:
24
diff
changeset
|
82 _code <- httpResp statusCode |
bb80f86c5048
Added code for sending and decoding the responses of evalRequests
Mike Pavone <pavone@retrodev.com>
parents:
24
diff
changeset
|
83 bod <- httpResp body |
bb80f86c5048
Added code for sending and decoding the responses of evalRequests
Mike Pavone <pavone@retrodev.com>
parents:
24
diff
changeset
|
84 print: "Response code: " . (string: _code) . "\n" |
bb80f86c5048
Added code for sending and decoding the responses of evalRequests
Mike Pavone <pavone@retrodev.com>
parents:
24
diff
changeset
|
85 print: bod . "\n" |
bb80f86c5048
Added code for sending and decoding the responses of evalRequests
Mike Pavone <pavone@retrodev.com>
parents:
24
diff
changeset
|
86 decoded <- json decode: bod |
bb80f86c5048
Added code for sending and decoding the responses of evalRequests
Mike Pavone <pavone@retrodev.com>
parents:
24
diff
changeset
|
87 _status <- "error" |
bb80f86c5048
Added code for sending and decoding the responses of evalRequests
Mike Pavone <pavone@retrodev.com>
parents:
24
diff
changeset
|
88 if: _code = 200 { |
bb80f86c5048
Added code for sending and decoding the responses of evalRequests
Mike Pavone <pavone@retrodev.com>
parents:
24
diff
changeset
|
89 _status <- decoded get: "status" withDefault: "error" |
30
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
90 if: _status = "ok" { |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
91 _outputs <- (decoded get: "outputs" withDefault: #[]) map: :num { |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
92 (num from: 2) parseHex64 |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
93 } |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
94 #{ |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
95 status <- { "ok" } |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
96 outputs <- { _outputs } |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
97 string <- { |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
98 str <- "OK:" |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
99 foreach: _outputs :idx val { |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
100 str <- str . "\n" . (string: idx) . ": 0x" . (hex: val) |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
101 } |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
102 str |
25
bb80f86c5048
Added code for sending and decoding the responses of evalRequests
Mike Pavone <pavone@retrodev.com>
parents:
24
diff
changeset
|
103 } |
30
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
104 print <- { |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
105 print: string . "\n" |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
106 } |
22
a4837071b73d
some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents:
21
diff
changeset
|
107 } |
30
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
108 } else: { |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
109 _message <- decoded get: "message" withDefault: "" |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
110 #{ |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
111 status <- { "error" } |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
112 message <- { _message } |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
113 string <- { |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
114 "Error: " . _message |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
115 } |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
116 print <- { |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
117 print: string . "\n" |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
118 } |
25
bb80f86c5048
Added code for sending and decoding the responses of evalRequests
Mike Pavone <pavone@retrodev.com>
parents:
24
diff
changeset
|
119 } |
22
a4837071b73d
some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents:
21
diff
changeset
|
120 } |
24
e1109e33b796
some work that probably needs to be trashed on requests.tp
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
121 } else: { |
30
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
122 #{print <- print: "HTTP response gave error! code was: " . _code . "\n"} |
46
e9e01cd64993
Fix decoding of JSON problem array
Mike Pavone <pavone@retrodev.com>
parents:
41
diff
changeset
|
123 |
22
a4837071b73d
some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents:
21
diff
changeset
|
124 } |
a4837071b73d
some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents:
21
diff
changeset
|
125 } |
a4837071b73d
some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents:
21
diff
changeset
|
126 |
26 | 127 guessResponse <- :httpResp { |
128 _code <- httpResp statusCode | |
129 bod <- httpResp body | |
130 print: "Response code: " . (string: _code) . "\n" | |
131 print: bod . "\n" | |
132 decoded <- json decode: bod | |
133 _status <- "error" | |
134 if: _code = 200 { | |
135 _status <- decoded get: "status" withDefault: "error" | |
30
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
136 if: _status = "win" { |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
137 #{ |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
138 status <- { "win" } |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
139 string <- { "OK: win" } |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
140 print <- { |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
141 print: string . "\n" |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
142 } |
26 | 143 } |
30
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
144 } else: { if: _status = "mismatch" { |
26 | 145 |
30
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
146 _values <- (decoded get: "values" withDefault: #[]) map: :num { |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
147 (num from: 2) parseHex64 |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
148 } |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
149 #{ |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
150 status <- { "mismatch" } |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
151 values <- { _values } |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
152 string <- { |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
153 str <- "OK:" |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
154 foreach: _values :idx val { |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
155 str <- str . "\n" . (string: idx) . ": 0x" . (hex: val) |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
156 } |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
157 str |
26 | 158 } |
30
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
159 print <- { |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
160 print: string . "\n" |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
161 } |
26 | 162 } |
30
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
163 } else: { |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
164 _message <- decoded get: "message" withDefault: "" |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
165 #{ |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
166 status <- { "error" } |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
167 message <- { _message } |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
168 string <- { |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
169 "Error: " . _message |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
170 } |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
171 print <- { |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
172 print: string . "\n" |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
173 } |
26 | 174 } |
30
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
175 }} // end if |
26 | 176 } else: { |
30
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
177 #{print <- print: "HTTP response gave error! code was: " . _code . "\n"} |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
178 } |
26 | 179 } |
180 | |
41
4750da71cae6
parsing myproblems.json, needs fix
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
181 _problem <- :decoded { |
46
e9e01cd64993
Fix decoding of JSON problem array
Mike Pavone <pavone@retrodev.com>
parents:
41
diff
changeset
|
182 _id <- decoded get: "id" withDefault: -1 |
e9e01cd64993
Fix decoding of JSON problem array
Mike Pavone <pavone@retrodev.com>
parents:
41
diff
changeset
|
183 _size <- decoded get: "size" withDefault: -1 |
e9e01cd64993
Fix decoding of JSON problem array
Mike Pavone <pavone@retrodev.com>
parents:
41
diff
changeset
|
184 _ops <- decoded get: "operators" withDefault: #[] |
e9e01cd64993
Fix decoding of JSON problem array
Mike Pavone <pavone@retrodev.com>
parents:
41
diff
changeset
|
185 _timeLeft <- decoded get: "timeLeft" withDefault: 301 |
e9e01cd64993
Fix decoding of JSON problem array
Mike Pavone <pavone@retrodev.com>
parents:
41
diff
changeset
|
186 _challenge <- decoded get: "challenge" withDefault: "" |
48
855c05c9cae1
Updated myproblems.json. Some solver fixes
Mike Pavone <pavone@retrodev.com>
parents:
46
diff
changeset
|
187 _solved <- decoded get: "solved" withDefault: false |
36
c42d3c8b1d75
problem response json is parsed, also works with training problems. tested.
William Morgan <bill@mrgn.org>
parents:
35
diff
changeset
|
188 #{ |
46
e9e01cd64993
Fix decoding of JSON problem array
Mike Pavone <pavone@retrodev.com>
parents:
41
diff
changeset
|
189 id <- { _id } |
e9e01cd64993
Fix decoding of JSON problem array
Mike Pavone <pavone@retrodev.com>
parents:
41
diff
changeset
|
190 size <- { _size } |
e9e01cd64993
Fix decoding of JSON problem array
Mike Pavone <pavone@retrodev.com>
parents:
41
diff
changeset
|
191 operators <- { _ops } |
48
855c05c9cae1
Updated myproblems.json. Some solver fixes
Mike Pavone <pavone@retrodev.com>
parents:
46
diff
changeset
|
192 solved <- { _solved } |
46
e9e01cd64993
Fix decoding of JSON problem array
Mike Pavone <pavone@retrodev.com>
parents:
41
diff
changeset
|
193 timeLeft <- { _timeLeft } |
36
c42d3c8b1d75
problem response json is parsed, also works with training problems. tested.
William Morgan <bill@mrgn.org>
parents:
35
diff
changeset
|
194 // training problems have a challenge, real ones do not.: |
46
e9e01cd64993
Fix decoding of JSON problem array
Mike Pavone <pavone@retrodev.com>
parents:
41
diff
changeset
|
195 challenge <- { _challenge } |
e9e01cd64993
Fix decoding of JSON problem array
Mike Pavone <pavone@retrodev.com>
parents:
41
diff
changeset
|
196 string <- { |
36
c42d3c8b1d75
problem response json is parsed, also works with training problems. tested.
William Morgan <bill@mrgn.org>
parents:
35
diff
changeset
|
197 str <- "problem '" . id . "' has size '" . size . "' and operators:" |
c42d3c8b1d75
problem response json is parsed, also works with training problems. tested.
William Morgan <bill@mrgn.org>
parents:
35
diff
changeset
|
198 foreach: operators :idx val { |
c42d3c8b1d75
problem response json is parsed, also works with training problems. tested.
William Morgan <bill@mrgn.org>
parents:
35
diff
changeset
|
199 str <- str . "\n " . (string: idx) . ": " . val |
c42d3c8b1d75
problem response json is parsed, also works with training problems. tested.
William Morgan <bill@mrgn.org>
parents:
35
diff
changeset
|
200 } |
48
855c05c9cae1
Updated myproblems.json. Some solver fixes
Mike Pavone <pavone@retrodev.com>
parents:
46
diff
changeset
|
201 str <- str . "\nsolved?: " . (if: solved { "true" } else: { "false" }) |
36
c42d3c8b1d75
problem response json is parsed, also works with training problems. tested.
William Morgan <bill@mrgn.org>
parents:
35
diff
changeset
|
202 str . "\ntimeLeft: " . timeLeft |
c42d3c8b1d75
problem response json is parsed, also works with training problems. tested.
William Morgan <bill@mrgn.org>
parents:
35
diff
changeset
|
203 } |
c42d3c8b1d75
problem response json is parsed, also works with training problems. tested.
William Morgan <bill@mrgn.org>
parents:
35
diff
changeset
|
204 print <- { |
c42d3c8b1d75
problem response json is parsed, also works with training problems. tested.
William Morgan <bill@mrgn.org>
parents:
35
diff
changeset
|
205 print: string . "\n" |
c42d3c8b1d75
problem response json is parsed, also works with training problems. tested.
William Morgan <bill@mrgn.org>
parents:
35
diff
changeset
|
206 } |
c42d3c8b1d75
problem response json is parsed, also works with training problems. tested.
William Morgan <bill@mrgn.org>
parents:
35
diff
changeset
|
207 } |
35 | 208 } |
209 | |
41
4750da71cae6
parsing myproblems.json, needs fix
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
210 problem <- :bod { |
4750da71cae6
parsing myproblems.json, needs fix
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
211 decoded <- json decode: bod |
4750da71cae6
parsing myproblems.json, needs fix
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
212 _problem: decoded |
4750da71cae6
parsing myproblems.json, needs fix
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
213 } |
4750da71cae6
parsing myproblems.json, needs fix
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
214 |
4750da71cae6
parsing myproblems.json, needs fix
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
215 problems <- :bod { |
4750da71cae6
parsing myproblems.json, needs fix
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
216 decoded <- json decode: bod |
46
e9e01cd64993
Fix decoding of JSON problem array
Mike Pavone <pavone@retrodev.com>
parents:
41
diff
changeset
|
217 decoded map: :el{ |
48
855c05c9cae1
Updated myproblems.json. Some solver fixes
Mike Pavone <pavone@retrodev.com>
parents:
46
diff
changeset
|
218 p <- _problem: el |
855c05c9cae1
Updated myproblems.json. Some solver fixes
Mike Pavone <pavone@retrodev.com>
parents:
46
diff
changeset
|
219 //print: p |
855c05c9cae1
Updated myproblems.json. Some solver fixes
Mike Pavone <pavone@retrodev.com>
parents:
46
diff
changeset
|
220 p |
41
4750da71cae6
parsing myproblems.json, needs fix
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
221 } |
4750da71cae6
parsing myproblems.json, needs fix
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
222 } |
4750da71cae6
parsing myproblems.json, needs fix
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
223 |
25
bb80f86c5048
Added code for sending and decoding the responses of evalRequests
Mike Pavone <pavone@retrodev.com>
parents:
24
diff
changeset
|
224 main <- :args { |
41
4750da71cae6
parsing myproblems.json, needs fix
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
225 print: "Program Start." |
36
c42d3c8b1d75
problem response json is parsed, also works with training problems. tested.
William Morgan <bill@mrgn.org>
parents:
35
diff
changeset
|
226 testId0 <- "wdThP1AgVrS2rp7q6qt9mLqp" // TRAINING PROGRAM ID! not real one. response in data folder. |
c42d3c8b1d75
problem response json is parsed, also works with training problems. tested.
William Morgan <bill@mrgn.org>
parents:
35
diff
changeset
|
227 testId1 <- "QwhG7ZpaVsfXiLRvbJfIfxl8" // TRAINING PROGRAM ID! not real one. response in data folder. |
c42d3c8b1d75
problem response json is parsed, also works with training problems. tested.
William Morgan <bill@mrgn.org>
parents:
35
diff
changeset
|
228 someProblem <- "{\"id\":\"QwhG7ZpaVsfXiLRvbJfIfxl8\",\"size\":15,\"operators\":[\"and\",\"if0\",\"shl1\",\"shr16\",\"tfold\"]}" |
c42d3c8b1d75
problem response json is parsed, also works with training problems. tested.
William Morgan <bill@mrgn.org>
parents:
35
diff
changeset
|
229 someProgram <- "(lambda (input) (shl1 input))" |
c42d3c8b1d75
problem response json is parsed, also works with training problems. tested.
William Morgan <bill@mrgn.org>
parents:
35
diff
changeset
|
230 |
31
8a2925ab0d4a
working guess request and response.
William Morgan <bill@mrgn.org>
parents:
30
diff
changeset
|
231 //print: ((evalId: "someId" #[1u64 2u64 3u64]) string) . "\n" |
8a2925ab0d4a
working guess request and response.
William Morgan <bill@mrgn.org>
parents:
30
diff
changeset
|
232 //print: ((guess: "someId" "someProg") string) . "\n" |
41
4750da71cae6
parsing myproblems.json, needs fix
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
233 //print: ((problem: someProblem) string) . "\n" |
4750da71cae6
parsing myproblems.json, needs fix
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
234 |
46
e9e01cd64993
Fix decoding of JSON problem array
Mike Pavone <pavone@retrodev.com>
parents:
41
diff
changeset
|
235 file <- os open: "data/myproblems.json" (os O_RDONLY) |
41
4750da71cae6
parsing myproblems.json, needs fix
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
236 fstr <- (os read: file 400 * 1024) // file was 276k before bonus problems... |
4750da71cae6
parsing myproblems.json, needs fix
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
237 os close: file |
4750da71cae6
parsing myproblems.json, needs fix
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
238 |
4750da71cae6
parsing myproblems.json, needs fix
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
239 print: (((problems: fstr) get: 0) string ) |
4750da71cae6
parsing myproblems.json, needs fix
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
240 |
4750da71cae6
parsing myproblems.json, needs fix
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
241 |
22
a4837071b73d
some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents:
21
diff
changeset
|
242 |
25
bb80f86c5048
Added code for sending and decoding the responses of evalRequests
Mike Pavone <pavone@retrodev.com>
parents:
24
diff
changeset
|
243 if: (args length) > 1 { |
bb80f86c5048
Added code for sending and decoding the responses of evalRequests
Mike Pavone <pavone@retrodev.com>
parents:
24
diff
changeset
|
244 key <- args get: 1 |
31
8a2925ab0d4a
working guess request and response.
William Morgan <bill@mrgn.org>
parents:
30
diff
changeset
|
245 |
30
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
246 //print: ((evalProgram: "(lambda (input) (shl1 input))" #[1u64 0xEFFFFFFFFFFFFFu64]) sendWithKey: key) |
36
c42d3c8b1d75
problem response json is parsed, also works with training problems. tested.
William Morgan <bill@mrgn.org>
parents:
35
diff
changeset
|
247 //print: ((evalId: testId0 #[1u64 0xEFFFFFFFFFFFFFu64]) sendWithKey: key) |
41
4750da71cae6
parsing myproblems.json, needs fix
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
248 //print: ((guess: testId0 someProgram) sendWithKey: key) |
4750da71cae6
parsing myproblems.json, needs fix
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
249 println: "derp" |
22
a4837071b73d
some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents:
21
diff
changeset
|
250 } |
12
7d8b8f82cbef
Help Bill work around some compiler bugs
Mike Pavone <pavone@retrodev.com>
parents:
10
diff
changeset
|
251 } |
10
79c1db5e7ebd
sending broken file for mike to check error
William Morgan <bill@mrgn.org>
parents:
diff
changeset
|
252 } |