@Override public Object execute(TransitionSystem ts, Unifier un, Term[] terms) throws Exception { try { WorldModel model = ((MinerArch) ts.getUserAgArch()).getModel(); if (model == null) { ts.getLogger().log(Level.SEVERE, "no model to get near_least_visited!"); } else { if (oldTarget != null && model.inGrid(oldTarget)) { model.remove(WorldModel.TARGET, oldTarget); } NumberTerm x = (NumberTerm) terms[0]; NumberTerm y = (NumberTerm) terms[1]; Location t = new Location((int) x.solve(), (int) y.solve()); if (model.inGrid(t)) { model.add(WorldModel.TARGET, t); oldTarget = t; } } return true; } catch (Throwable e) { ts.getLogger().log(Level.SEVERE, "jia.set_target error: " + e, e); } return false; }
@Override public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception { NumberTerm size = (NumberTerm) args[0]; // tamanho da cartela NumberTerm max = (NumberTerm) args[1]; // TETO para um numero sorteado Term[] terms = new Term[1]; terms[0] = args[1]; box.clear(); Random r = new Random(); while (box.size() < size.solve()) box.add((int) r.evaluate(ts, terms) + 1); // box.add(r.nextInt((int)max.solve()) + 1); //garantir a não repetição dos números da // cartela ListTerm result = new ListTermImpl(); for (Integer i : box) { Term t = new NumberTermImpl(i); result.add(t); // converter a cartela em um feedback para o agente } return un.unifies(result, args[2]); }