diff options
| author | syeyoung <42869671+cyoung06@users.noreply.github.com> | 2020-12-15 00:40:58 +0900 |
|---|---|---|
| committer | syeyoung <42869671+cyoung06@users.noreply.github.com> | 2020-12-15 00:40:58 +0900 |
| commit | 496efb764360cd26fa40982532048aa18ae4c6be (patch) | |
| tree | 483665c7501a5855ce439fbeff1c3d8ac8b15618 /src/main/java/kr/syeyoung/dungeonsguide/dungeon/actions/tree | |
| parent | ff817d0a37b907ff1f5132b04e737413b020ecd1 (diff) | |
| download | Skyblock-Dungeons-Guide-496efb764360cd26fa40982532048aa18ae4c6be.tar.gz Skyblock-Dungeons-Guide-496efb764360cd26fa40982532048aa18ae4c6be.tar.bz2 Skyblock-Dungeons-Guide-496efb764360cd26fa40982532048aa18ae4c6be.zip | |
dungeon actions and secrets
Diffstat (limited to 'src/main/java/kr/syeyoung/dungeonsguide/dungeon/actions/tree')
| -rw-r--r-- | src/main/java/kr/syeyoung/dungeonsguide/dungeon/actions/tree/ActionTree.java | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/actions/tree/ActionTree.java b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/actions/tree/ActionTree.java new file mode 100644 index 00000000..1db6767c --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/actions/tree/ActionTree.java @@ -0,0 +1,49 @@ +package kr.syeyoung.dungeonsguide.dungeon.actions.tree; + +import kr.syeyoung.dungeonsguide.dungeon.actions.Action; +import kr.syeyoung.dungeonsguide.dungeon.actions.ActionRoot; +import kr.syeyoung.dungeonsguide.dungeon.roomfinder.DungeonRoom; +import lombok.Data; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +@Data +public class ActionTree { + private ActionTree parent; + private Action current; + private Set<ActionTree> children; + + + public static ActionTree buildActionTree(Set<Action> actions, DungeonRoom dungeonRoom) { + ActionRoot root = new ActionRoot(); + root.setPreRequisite(actions); + ActionTree tree = new ActionTree(); + tree.setParent(null); + tree.setCurrent(root); + HashSet<ActionTree> set = new HashSet(); + for (Action action : actions) { + set.add(buildActionTree(tree, action, dungeonRoom, new HashMap<Action, ActionTree>())); + } + tree.setChildren(set); + return tree; + } + + private static ActionTree buildActionTree(ActionTree parent, Action action, DungeonRoom dungeonRoom, Map<Action, ActionTree> alreadyBuilt) { + if (action == null) return null; + if (alreadyBuilt.containsKey(action)) return alreadyBuilt.get(action); + + ActionTree tree = new ActionTree(); + alreadyBuilt.put(action, tree); + tree.setParent(parent); + tree.setCurrent(action); + HashSet<ActionTree> set = new HashSet(); + for (Action action2 : action.getPreRequisites(dungeonRoom)) { + set.add(buildActionTree(tree, action2, dungeonRoom, alreadyBuilt)); + } + tree.setChildren(set); + return tree; + } +} |
