private Move searchNextCloud(Unicorn me, IBoard board) { BFS bfs = new BFS(); Node end = bfs.search(new OnlyPositionNode(board, me.pos), new NextToCloud(board)); List<Node> path = PathUtils.getPath(end); if (path.size() <= 1) return Move.STAY; V nextPos = (V) path.get(1).getState(); V direction = V.sub(nextPos, me.pos); return Board.getDirectionToMoveMapping().get(direction); }
@Override public boolean test(Node currentNode) { V currentUnicornPos = (V) currentNode.getState(); for (V d : Board.getDirections()) { for (GameObject obj : board.at(V.add(currentUnicornPos, d))) { if (obj instanceof Cloud) { return true; } } } return false; }