From 932399472cb653f5a8fdc1095fa941656a729650 Mon Sep 17 00:00:00 2001 From: syeyoung Date: Sun, 25 Jul 2021 22:27:22 +0900 Subject: Creating Fake Dungeons. --- .../dungeonsguide/dungeon/MapProcessor.java | 6 ++--- .../DungeonSpecificDataProviderRegistry.java | 2 +- .../dungeon/roomfinder/RoomMatcher.java | 30 ++++++++++++++++------ 3 files changed, 26 insertions(+), 12 deletions(-) (limited to 'src/main/java/kr/syeyoung/dungeonsguide/dungeon') diff --git a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/MapProcessor.java b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/MapProcessor.java index a86a5326..3bea78f8 100755 --- a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/MapProcessor.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/MapProcessor.java @@ -60,11 +60,11 @@ public class MapProcessor { @Getter private final BiMap mapIconToPlayerMap = HashBiMap.create(); - @Getter + @Getter @Setter private Dimension unitRoomDimension; - @Getter + @Getter @Setter private Dimension doorDimension; // width: width of door, height: gap between rooms - @Getter + @Getter @Setter private Point topLeftMapPoint; @Setter diff --git a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/doorfinder/DungeonSpecificDataProviderRegistry.java b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/doorfinder/DungeonSpecificDataProviderRegistry.java index a92d7a03..6ee6f9ee 100755 --- a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/doorfinder/DungeonSpecificDataProviderRegistry.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/doorfinder/DungeonSpecificDataProviderRegistry.java @@ -23,7 +23,7 @@ import java.util.Map; import java.util.regex.Pattern; public class DungeonSpecificDataProviderRegistry { - private static final Map doorFinders = new HashMap(); + public static final Map doorFinders = new HashMap(); static { doorFinders.put(Pattern.compile("The Catacombs (?:F[0-9]|E0)"), new CatacombDataProvider()); diff --git a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/roomfinder/RoomMatcher.java b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/roomfinder/RoomMatcher.java index d7bc1c64..9c20bdf9 100755 --- a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/roomfinder/RoomMatcher.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/roomfinder/RoomMatcher.java @@ -67,24 +67,36 @@ public class RoomMatcher { shape = ShortUtils.topLeftifyInt(shape); List roomInfoList = DungeonRoomInfoRegistry.getByShape(shape); + int lowestcost = Integer.MAX_VALUE; + DungeonRoomInfo bestMatch = null; for (DungeonRoomInfo roomInfo : roomInfoList) { - if (tryMatching(roomInfo, rotation)) { - match = roomInfo; - this.rotation = rotation; - return match; + int cost = tryMatching(roomInfo, rotation); +// if () { +// match = roomInfo; +// this.rotation = rotation; +// return match; +// } + if (cost < lowestcost) { + lowestcost = cost; + bestMatch = roomInfo; + if (cost == 0) break; } } + match = bestMatch; + this.rotation = rotation; + return bestMatch; } return null; } - private boolean tryMatching(DungeonRoomInfo dungeonRoomInfo, int rotation) { - if (dungeonRoomInfo.getColor() != dungeonRoom.getColor()) return false; + private int tryMatching(DungeonRoomInfo dungeonRoomInfo, int rotation) { + if (dungeonRoomInfo.getColor() != dungeonRoom.getColor()) return Integer.MAX_VALUE; int[][] res = dungeonRoomInfo.getBlocks(); for (int i = 0; i < rotation; i++) res = ArrayUtils.rotateCounterClockwise(res); + int wrongs = 0; for (int z = 0; z < res.length; z ++) { for (int x = 0; x < res[0].length; x++) { int data = res[z][x]; @@ -92,11 +104,13 @@ public class RoomMatcher { Block b = dungeonRoom.getRelativeBlockAt(x,0,z); if (b == null || Block.getIdFromBlock(b) != data) { - return false; + wrongs++; + + if (wrongs > 10) return wrongs; } } } - return true; + return wrongs; } private static final int offset = 3; -- cgit