/** * returns a move based on the policy of the predator * * @param others = array list of positions with the position of the predator */ @Override public void doMove(ArrayList<Position> others, boolean isPrey) { preyPos = new Position(others.get(0)); int linIndex = policy.getLinearIndexFromPositions(myPos, preyPos); double[] prob = policy.getStateActionPairValues(linIndex); double[] probCum = new double[Action.nrActions]; probCum[0] = prob[0]; for (int i = 1; i < Action.nrActions; i++) { probCum[i] = probCum[i - 1] + prob[i]; } probCum[Action.nrActions - 1] = 1.0; double p = Math.random(); int action = -1; for (int i = 0; i < Action.nrActions; i++) { if (p <= probCum[i]) { action = i; break; } } myPos.adjustPosition(policy.getMove(myPos, preyPos, Action.getAction(action), false)); }