Download Jar. Uses 4489K of libraries. Click here for Pure Java version (13723L/99K).
1 | !7 |
2 | |
3 | sS theFacts = [[ |
4 | |
5 | Fibonacci-Zahl n ist Fibonacci-Zahl n-1 plus Fibonacci-Zahl n-2 falls n > 2. |
6 | Es gibt keine Fibonacci-Zahl 0. |
7 | Fibonacci-Zahl 1 ist 1. |
8 | Fibonacci-Zahl 2 ist 1. |
9 | |
10 | // Technisches Zeug |
11 | gmtzfidalveipfyx feyhbrhdeovmbvaw amcmxkgwhivbouqs |
12 | pqnfhkzxoqkaoyqk sppxbuuqeetjmzuo |
13 | ]]; |
14 | |
15 | sS theRiddle = [[ |
16 | Was ist Fibonacci-Zahl 0? |
17 | Was ist Fibonacci-Zahl 1? |
18 | Was ist Fibonacci-Zahl 2? |
19 | Was ist Fibonacci-Zahl 3? |
20 | Was ist Fibonacci-Zahl 4? |
21 | ]]; |
22 | |
23 | static S concepts = [[ |
24 | ["feyhbrhdeovmbvaw", "Es gibt keine X."], |
25 | ["mtsrzasaoxrmicch", "X ist Y falls Z."], |
26 | ["fgvvrzypbkqomktd", "X ist Y."], |
27 | ["sppxbuuqeetjmzuo", "X plus Y"], |
28 | ["rgsamtbrhpcqowko", "Fibonacci-Zahl X"], |
29 | ["urfkhwfasdaqqqse", "Was ist X?"], |
30 | ["jxcubqjtqykhfvyo", "X - Y", "as in minus"], |
31 | ["wdbphzfoxwlrhdyl", "X > Y"], |
32 | ["pqnfhkzxoqkaoyqk", "Operation X should be expanded."], |
33 | ["amcmxkgwhivbouqs", "Etwas nicht existentes"], |
34 | ["yissyloatogavyuu", "Fibonacci-Zahl"], |
35 | ["gmtzfidalveipfyx", "Marker X implies label Y."], |
36 | ["wvuyakuvuelmxpwp", "X on this"], |
37 | ]]; |
38 | |
39 | !include #1007689 // Web v2 |
40 | |
41 | static int saveInterval = 60000; |
42 | static volatile new Web web; |
43 | static L<Lisp> facts; |
44 | static long lastSave, sizeSaved; |
45 | |
46 | extend Web { |
47 | volatile transient bool cancelled, calculating; |
48 | } |
49 | |
50 | p-tt { |
51 | setConsoleTitle(programTitle()); |
52 | load("web"); lastSave = sysNow(); |
53 | setFrameHeight(consoleFrame(), 400); |
54 | centerConsole(); |
55 | //magellan(); |
56 | //graphite(); |
57 | //mistAqua(); |
58 | //moderateTheme(); |
59 | sahara(); |
60 | swing { |
61 | setConsoleInput("Was ist Fibonacci-Zahl 500?"); |
62 | consoleAddAskButton(); |
63 | focusConsole(); |
64 | final JLabel lblBrainSize = jRightAlignedLabel(); |
65 | addToConsole2(withMargin(centerAndEast(lblBrainSize, |
66 | withLeftMargin(jbutton("Reset", "reset"))))); |
67 | awtEvery(lblBrainSize, 1000, r { |
68 | lblBrainSize.setText("Brain Size: " + toM(fileSize(programFile("web.structure")), 1) + " MB"); |
69 | }); |
70 | awtCalcEvery(lblBrainSize, 1000, 1000, r { |
71 | if (web.calculating) ret; |
72 | int webSize = web.count(); |
73 | if (shouldSave(webSize, false)) saveWeb(webSize); |
74 | }); |
75 | } |
76 | |
77 | aiEnhancements(); |
78 | aiConcepts_noAutoClear(); |
79 | useConceptsDump(concepts); |
80 | set englishToConceptLanguage_useBrackets; |
81 | facts = clParse(linesToCL(theFacts)); |
82 | print(theFacts); |
83 | useFacts(theFacts); |
84 | printNumberedLines(facts); // print parsed facts |
85 | |
86 | firstRiddle(); |
87 | |
88 | makeBot(); |
89 | notDone(); |
90 | } |
91 | |
92 | svoid firstRiddle { |
93 | print(); |
94 | for (S rid : toLinesFullTrim(theRiddle)) { |
95 | print("? " + rid); |
96 | print(" " + answer(rid)); |
97 | } |
98 | print(); |
99 | } |
100 | |
101 | static int webSize() { ret web.count(); } |
102 | |
103 | sbool shouldSave(int webSize, bool checkInterval) { |
104 | ret webSize != sizeSaved && |
105 | (!checkInterval || sysNow() >= lastSave+saveInterval); |
106 | } |
107 | |
108 | svoid saveWeb(int webSize) { |
109 | save("web"); |
110 | sizeSaved = webSize; |
111 | lastSave = sysNow(); |
112 | } |
113 | |
114 | static S answer(S rid) { |
115 | web.calculating = true; |
116 | try { |
117 | ret answerImpl(rid); |
118 | } finally { |
119 | web.calculating = false; |
120 | } |
121 | } |
122 | |
123 | static S answerImpl(S rid) { |
124 | if (match("web", rid)) { print(web); ret "OK"; } |
125 | if (match("visualize", rid)) { webToCAL(web).show(); ret "OK"; } |
126 | Web web = main.web; |
127 | Lisp riddle = clParse(englishToConceptLanguage(rid)); |
128 | //print("# " + riddle); |
129 | |
130 | if (!riddle.is("urfkhwfasdaqqqse", "mrhggsmuykeceghd")) ret "huh?"; // Was ist X? // Was ist the decimal representation of X? |
131 | Lisp mainConcept = riddle.get(0); |
132 | |
133 | // Make web |
134 | web.node(mainConcept); |
135 | web.relations(facts); |
136 | |
137 | int webSize = web.count(); |
138 | int cursor = 0; |
139 | while licensed { |
140 | if (web.cancelled) ret "cancelled"; |
141 | //print("Web size: " + webSize); |
142 | if (shouldSave(webSize, true)) { |
143 | printWithoutNL("S"); |
144 | saveWeb(webSize); |
145 | } else |
146 | printWithoutNL("."); |
147 | if ((++cursor % 60) == 0) print(); |
148 | |
149 | CriticalAction action = beginCriticalAction("Web Update"); |
150 | try { |
151 | web_expandMarkers2(web); |
152 | web_expandOperations2(web); |
153 | |
154 | for (LispStatement ls : lispStatementsByHead("mtsrzasaoxrmicch")) { |
155 | if (web.cancelled) ret "cancelled"; |
156 | Lisp rule = ls.term, x = rule.get(0); |
157 | //print("Pot size: " + l(web.getPot(ls.globalID))); |
158 | for (WebNode node : web.clearPot(ls.globalID)) { |
159 | for (Lisp lbl : cloneList(node.labels)) { |
160 | //print("Matching " + x + " and " + lbl); |
161 | Map<S, Lisp> matches = lispMatch(x, lbl, ll("n")); |
162 | if (matches != null) { |
163 | //print("Rule match: " + struct(matches)); |
164 | Lisp bla = lispReplaceVars(rule.get(2), matches); |
165 | if (checkACondition(bla)) { |
166 | bla = lispReplaceVars(rule.get(1), matches); |
167 | bla = lispCalculateDeep(bla); |
168 | bla = web_insertNumbers(web, bla); |
169 | //print("bla: " + bla); |
170 | bla = lispCalculateDeep(bla); |
171 | if (lispIsInt(bla)) { |
172 | node.addLabel(bla); // Found! |
173 | //pot.remove(node); |
174 | } else { |
175 | //print("Condition OK! Evaluating: " + bla); |
176 | web.node(bla); |
177 | // Place into pot again |
178 | web.getPot(ls.globalID).add(node); |
179 | } |
180 | } |
181 | } |
182 | } |
183 | } |
184 | //print("Node: " + node + ", condition: " + condition); |
185 | } |
186 | } finally { |
187 | action.done(); |
188 | } |
189 | |
190 | int n = web.count(); |
191 | if (n == webSize) break; |
192 | webSize = n; |
193 | } |
194 | print(); |
195 | |
196 | // print question again |
197 | if (cursor / 60 >= 10) |
198 | print("? " + rid); |
199 | |
200 | // Answer question |
201 | L<Lisp> l = listWithout(web.findNode(mainConcept).labels, mainConcept); |
202 | //print("Labels: " + l); |
203 | S s = chooseALabelToReturn(l); |
204 | s = or2(conceptLanguageToEnglish(unquote(s)), "I don't know"); |
205 | ret s; |
206 | } |
207 | |
208 | sS chooseALabelToReturn(L<Lisp> ll) { |
209 | L<S> l = map(f clUnparse, ll); |
210 | //print(" Labels: " + l); |
211 | S s = findInteger(l); |
212 | if (s == null) s = firstGlobalID(l); |
213 | //if (s == null) s = random(l); |
214 | if (s == null) ret s = first(l); |
215 | ret s; |
216 | } |
217 | |
218 | sbool checkACondition(Lisp l) false on exception { |
219 | ret lispCalculateDeep(l).is("true"); |
220 | } |
221 | |
222 | svoid cleanMeUp { |
223 | while (criticalActionsInFlight()) sleep(5); |
224 | if (sizeSaved != web.count()) |
225 | save("web"); |
226 | } |
227 | |
228 | svoid reset { |
229 | if (!confirmOKCancel("Really clear the Fibonacci brain?")) ret; |
230 | web.cancelled = true; |
231 | CriticalAction action = beginCriticalAction("Resetting Brain"); |
232 | try { |
233 | web = new Web; |
234 | sizeSaved = 0; |
235 | save("web"); |
236 | } finally { |
237 | action.done(); |
238 | } |
239 | clearConsole(); |
240 | firstRiddle(); |
241 | } |
Began life as a copy of #1007765
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, unoaxrwscvea, vouqrxazstgt
No comments. add comment
Snippet ID: | #1008139 |
Snippet name: | Demo 2 (deutsch): Fibonacci-Zahlen - translation of #1007765 |
Eternal ID of this version: | #1008139/9 |
Text MD5: | 1a40a03c1f6de29664b886616b7e086e |
Transpilation MD5: | 450757b3a7b99ed1129e840e9a910934 |
Author: | stefan |
Category: | javax / a.i. |
Type: | JavaX source code (desktop) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2017-04-26 12:25:02 |
Source code size: | 6713 bytes / 241 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 549 / 1092 |
Version history: | 8 change(s) |
Referenced in: | [show references] |