annotate src/requests.tp @ 40:1cadb591eef1

Fix bug that was causing the solver to not find certain matches
author Mike Pavone <pavone@retrodev.com>
date Sun, 11 Aug 2013 00:37:34 -0700
parents c42d3c8b1d75
children 4750da71cae6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10
79c1db5e7ebd sending broken file for mike to check error
William Morgan <bill@mrgn.org>
parents:
diff changeset
1 #{
18
a0e66161bde0 for bug investigation
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
2
20
92db3d1e8809 strJoin finally works.
William Morgan <bill@mrgn.org>
parents: 19
diff changeset
3 strJoin <- :str arr {
92db3d1e8809 strJoin finally works.
William Morgan <bill@mrgn.org>
parents: 19
diff changeset
4 acc <- ""
92db3d1e8809 strJoin finally works.
William Morgan <bill@mrgn.org>
parents: 19
diff changeset
5 arr foreach: :i el {
92db3d1e8809 strJoin finally works.
William Morgan <bill@mrgn.org>
parents: 19
diff changeset
6 if: i = 0 {
92db3d1e8809 strJoin finally works.
William Morgan <bill@mrgn.org>
parents: 19
diff changeset
7 acc <- (string: el)
92db3d1e8809 strJoin finally works.
William Morgan <bill@mrgn.org>
parents: 19
diff changeset
8 } else: {
92db3d1e8809 strJoin finally works.
William Morgan <bill@mrgn.org>
parents: 19
diff changeset
9 acc <- acc . ", " . (string: el)
92db3d1e8809 strJoin finally works.
William Morgan <bill@mrgn.org>
parents: 19
diff changeset
10 }
92db3d1e8809 strJoin finally works.
William Morgan <bill@mrgn.org>
parents: 19
diff changeset
11 }
92db3d1e8809 strJoin finally works.
William Morgan <bill@mrgn.org>
parents: 19
diff changeset
12 acc
92db3d1e8809 strJoin finally works.
William Morgan <bill@mrgn.org>
parents: 19
diff changeset
13 //arr fold: "" with: :acc el {acc . el}
92db3d1e8809 strJoin finally works.
William Morgan <bill@mrgn.org>
parents: 19
diff changeset
14 }
92db3d1e8809 strJoin finally works.
William Morgan <bill@mrgn.org>
parents: 19
diff changeset
15
18
a0e66161bde0 for bug investigation
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
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
a0e66161bde0 for bug investigation
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
18 }
a0e66161bde0 for bug investigation
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
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
fcd7ae66a9ee cleanup.
William Morgan <bill@mrgn.org>
parents: 22
diff changeset
21 print: str . "\n"
fcd7ae66a9ee cleanup.
William Morgan <bill@mrgn.org>
parents: 22
diff changeset
22 }
fcd7ae66a9ee cleanup.
William Morgan <bill@mrgn.org>
parents: 22
diff changeset
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
92db3d1e8809 strJoin finally works.
William Morgan <bill@mrgn.org>
parents: 19
diff changeset
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
a0e66161bde0 for bug investigation
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
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"}
a4bffcd381cd eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents: 26
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
18a043613dae added guess response.
William Morgan <bill@mrgn.org>
parents: 25
diff changeset
127 guessResponse <- :httpResp {
18a043613dae added guess response.
William Morgan <bill@mrgn.org>
parents: 25
diff changeset
128 _code <- httpResp statusCode
18a043613dae added guess response.
William Morgan <bill@mrgn.org>
parents: 25
diff changeset
129 bod <- httpResp body
18a043613dae added guess response.
William Morgan <bill@mrgn.org>
parents: 25
diff changeset
130 print: "Response code: " . (string: _code) . "\n"
18a043613dae added guess response.
William Morgan <bill@mrgn.org>
parents: 25
diff changeset
131 print: bod . "\n"
18a043613dae added guess response.
William Morgan <bill@mrgn.org>
parents: 25
diff changeset
132 decoded <- json decode: bod
18a043613dae added guess response.
William Morgan <bill@mrgn.org>
parents: 25
diff changeset
133 _status <- "error"
18a043613dae added guess response.
William Morgan <bill@mrgn.org>
parents: 25
diff changeset
134 if: _code = 200 {
18a043613dae added guess response.
William Morgan <bill@mrgn.org>
parents: 25
diff changeset
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
18a043613dae added guess response.
William Morgan <bill@mrgn.org>
parents: 25
diff changeset
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
18a043613dae added guess response.
William Morgan <bill@mrgn.org>
parents: 25
diff changeset
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
18a043613dae added guess response.
William Morgan <bill@mrgn.org>
parents: 25
diff changeset
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
18a043613dae added guess response.
William Morgan <bill@mrgn.org>
parents: 25
diff changeset
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
18a043613dae added guess response.
William Morgan <bill@mrgn.org>
parents: 25
diff changeset
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
18a043613dae added guess response.
William Morgan <bill@mrgn.org>
parents: 25
diff changeset
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
18a043613dae added guess response.
William Morgan <bill@mrgn.org>
parents: 25
diff changeset
179 }
18a043613dae added guess response.
William Morgan <bill@mrgn.org>
parents: 25
diff changeset
180
36
c42d3c8b1d75 problem response json is parsed, also works with training problems. tested.
William Morgan <bill@mrgn.org>
parents: 35
diff changeset
181 problem <- :bod {
c42d3c8b1d75 problem response json is parsed, also works with training problems. tested.
William Morgan <bill@mrgn.org>
parents: 35
diff changeset
182 decoded <- json decode: bod
c42d3c8b1d75 problem response json is parsed, also works with training problems. tested.
William Morgan <bill@mrgn.org>
parents: 35
diff changeset
183 #{
c42d3c8b1d75 problem response json is parsed, also works with training problems. tested.
William Morgan <bill@mrgn.org>
parents: 35
diff changeset
184 id <- decoded get: "id" withDefault: -1
c42d3c8b1d75 problem response json is parsed, also works with training problems. tested.
William Morgan <bill@mrgn.org>
parents: 35
diff changeset
185 size <- decoded get: "size" withDefault: -1
c42d3c8b1d75 problem response json is parsed, also works with training problems. tested.
William Morgan <bill@mrgn.org>
parents: 35
diff changeset
186 operators <- decoded get: "operators" withDefault: #[]
c42d3c8b1d75 problem response json is parsed, also works with training problems. tested.
William Morgan <bill@mrgn.org>
parents: 35
diff changeset
187 //solved <- decoded get: "solved" withDefault: false // todo: B ool up ean this son of a j
c42d3c8b1d75 problem response json is parsed, also works with training problems. tested.
William Morgan <bill@mrgn.org>
parents: 35
diff changeset
188 timeLeft <- decoded get: "timeLeft" withDefault: 301
c42d3c8b1d75 problem response json is parsed, also works with training problems. tested.
William Morgan <bill@mrgn.org>
parents: 35
diff changeset
189 // training problems have a challenge, real ones do not.:
c42d3c8b1d75 problem response json is parsed, also works with training problems. tested.
William Morgan <bill@mrgn.org>
parents: 35
diff changeset
190 challenge <- decoded get: "challenge" withDefault: ""
c42d3c8b1d75 problem response json is parsed, also works with training problems. tested.
William Morgan <bill@mrgn.org>
parents: 35
diff changeset
191 string <- {
c42d3c8b1d75 problem response json is parsed, also works with training problems. tested.
William Morgan <bill@mrgn.org>
parents: 35
diff changeset
192 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
193 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
194 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
195 }
c42d3c8b1d75 problem response json is parsed, also works with training problems. tested.
William Morgan <bill@mrgn.org>
parents: 35
diff changeset
196 str . "\ntimeLeft: " . timeLeft
c42d3c8b1d75 problem response json is parsed, also works with training problems. tested.
William Morgan <bill@mrgn.org>
parents: 35
diff changeset
197 }
c42d3c8b1d75 problem response json is parsed, also works with training problems. tested.
William Morgan <bill@mrgn.org>
parents: 35
diff changeset
198 print <- {
c42d3c8b1d75 problem response json is parsed, also works with training problems. tested.
William Morgan <bill@mrgn.org>
parents: 35
diff changeset
199 print: string . "\n"
c42d3c8b1d75 problem response json is parsed, also works with training problems. tested.
William Morgan <bill@mrgn.org>
parents: 35
diff changeset
200 }
c42d3c8b1d75 problem response json is parsed, also works with training problems. tested.
William Morgan <bill@mrgn.org>
parents: 35
diff changeset
201 }
35
9d5c3b078c78 other training problem.
William Morgan <bill@mrgn.org>
parents: 31
diff changeset
202 }
9d5c3b078c78 other training problem.
William Morgan <bill@mrgn.org>
parents: 31
diff changeset
203
25
bb80f86c5048 Added code for sending and decoding the responses of evalRequests
Mike Pavone <pavone@retrodev.com>
parents: 24
diff changeset
204 main <- :args {
36
c42d3c8b1d75 problem response json is parsed, also works with training problems. tested.
William Morgan <bill@mrgn.org>
parents: 35
diff changeset
205 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
206 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
207 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
208 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
209
31
8a2925ab0d4a working guess request and response.
William Morgan <bill@mrgn.org>
parents: 30
diff changeset
210 //print: ((evalId: "someId" #[1u64 2u64 3u64]) string) . "\n"
8a2925ab0d4a working guess request and response.
William Morgan <bill@mrgn.org>
parents: 30
diff changeset
211 //print: ((guess: "someId" "someProg") string) . "\n"
36
c42d3c8b1d75 problem response json is parsed, also works with training problems. tested.
William Morgan <bill@mrgn.org>
parents: 35
diff changeset
212 print: ((problem: someProblem) string) . "\n"
22
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
213
25
bb80f86c5048 Added code for sending and decoding the responses of evalRequests
Mike Pavone <pavone@retrodev.com>
parents: 24
diff changeset
214 if: (args length) > 1 {
bb80f86c5048 Added code for sending and decoding the responses of evalRequests
Mike Pavone <pavone@retrodev.com>
parents: 24
diff changeset
215 key <- args get: 1
31
8a2925ab0d4a working guess request and response.
William Morgan <bill@mrgn.org>
parents: 30
diff changeset
216
30
a4bffcd381cd eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents: 26
diff changeset
217 //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
218 //print: ((evalId: testId0 #[1u64 0xEFFFFFFFFFFFFFu64]) sendWithKey: key)
c42d3c8b1d75 problem response json is parsed, also works with training problems. tested.
William Morgan <bill@mrgn.org>
parents: 35
diff changeset
219 print: ((guess: testId0 someProgram) sendWithKey: key)
c42d3c8b1d75 problem response json is parsed, also works with training problems. tested.
William Morgan <bill@mrgn.org>
parents: 35
diff changeset
220
22
a4837071b73d some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents: 21
diff changeset
221 }
12
7d8b8f82cbef Help Bill work around some compiler bugs
Mike Pavone <pavone@retrodev.com>
parents: 10
diff changeset
222 }
10
79c1db5e7ebd sending broken file for mike to check error
William Morgan <bill@mrgn.org>
parents:
diff changeset
223 }