1 | static bool ctxDoNextActionInRule(WoodyRule rule) { |
2 | L<CtxCase> actions = ctxCases(rule.body); |
3 | if (nempty(actions)) { |
4 | S actionSelector = rule.properties.get('ACTIONSELECTOR); |
5 | if (empty(actionSelector)) actionSelector = 'TILLEND; |
6 | bool random = eqOneOf(actionSelector, 'RANDOMLOOP, 'RANDOM); |
7 | //bool loop = eqOneOf(actionSelector, 'RANDOMLOOP); |
8 | S name = rule.longName(); |
9 | BitSet bs = conversation->randomLoopMap.get(name); |
10 | if (bs == null) { |
11 | conversation->randomLoopMap.put(name, bs = new BitSet); |
12 | conversation->change(); |
13 | } |
14 | new L<Int> candidates; |
15 | for i over actions: if (!bs.get(i)) candidates.add(i); |
16 | |
17 | // start over with all candidates |
18 | if (empty(candidates)) { |
19 | bs.clear(); |
20 | conversation->change(); |
21 | for i over actions: candidates.add(i); |
22 | } |
23 | int idx = random ? random(candidates) : first(candidates); |
24 | bs.set(idx); |
25 | candidates.remove((Int) idx); |
26 | conversation->change(); |
27 | CtxCase action = actions.get(idx); |
28 | ctxProcessAction(action.action); |
29 | S a = mapGet(action.properties, 'ANALYZER); |
30 | print("doNextAction analyzer=" + a); |
31 | if (a != null) ctxContext().activeAnalyzer = a; |
32 | ctxContext().nextRule = rule.properties.get('GOTO); |
33 | S goTo = action.properties.get('GOTO); |
34 | if (goTo != null) ctxContext().nextRule = goTo; |
35 | |
36 | print("Candidates left: " + l(candidates) + " of " + l(actions)); |
37 | if (empty(candidates) && l(actions) > 1) { |
38 | print("No more candidates. nextRule=" + ctxContext().nextRule); |
39 | if (/*loop &&*/ ctxContext().nextRule == null) |
40 | ctxContext().thinkagain = true; |
41 | } |
42 | |
43 | true; |
44 | } |
45 | false; |
46 | } |
download show line numbers debug dex old transpilations
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1008936 |
Snippet name: | ctxDoNextActionInRule |
Eternal ID of this version: | #1008936/18 |
Text MD5: | 558c03ea9b37fe39a0032504a2548256 |
Author: | stefan |
Category: | javax / a.i. |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2017-07-19 00:04:01 |
Source code size: | 1696 bytes / 46 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 436 / 503 |
Version history: | 17 change(s) |
Referenced in: | [show references] |