public String checkCyclicRoleReference(Role role, String refID) { String result = null; List<String> hierarchy = new ArrayList<String>(); hierarchy.add(role.getName()); Role owner = getRole(refID); String refName = owner.getName(); // name of role attempting to add to while (owner != null) { hierarchy.add(owner.getName()); if (owner.equals(role)) { result = constructCyclicAttributeErrorMessage(hierarchy, "role", refName); break; } owner = owner.getOwnerRole(); } return result; }
@Override public Agent divine() { List<Agent> aliveAgentList = getLatestDayGameInfo().getAliveAgentList(); aliveAgentList.remove(this.getMe()); if (!isAgainstSeer) { return randomSelect(aliveAgentList); } else { double flag = Math.random(); if (0.00D <= flag && flag < 0.05D) { List<Agent> againstSeer = new ArrayList<>(); for (Agent agent : this.comingoutRole.keySet()) { Role role = this.comingoutRole.get(agent); if (role.equals(Role.SEER) && !agent.equals(this.getMe())) { againstSeer.add(agent); } } if (againstSeer.size() > 0) { return randomSelect(againstSeer); } } else if (0.05 <= flag && flag < 0.75D) { List<Agent> anotherDivinedAgent = new ArrayList(); for (int i = 0; i < this.anotherJudgeList.size(); i++) { Judge judge = anotherJudgeList.get(i); if (!anotherDivinedAgent.contains(judge.getTarget())) { anotherDivinedAgent.add(judge.getTarget()); } } if (anotherDivinedAgent.size() > 0) { return randomSelect(anotherDivinedAgent); } } return randomSelect(aliveAgentList); } }