Issue porting dart dungeon generator into Java

Hi all,

Recently I found a dungeon generator written in dart and have attempted to port it into Java. Here’s the dart source: https://github.com/munificent/hauberk/blob/db360d9efa714efb6d937c31953ef849c7394a39/lib/src/content/dungeon.dart

So far I’ve managed to successfully randomly place rooms and grow a maze around them. But I’ve hit an issue with the connectRegions method. More specifically lines 211 and 229. I’m struggling to interpret them into Java.

Here’s my current method: http://pastebin.com/W9WTEkQT

My methods spits out an array index out of bounds error at line 48 of the pastebin link. I’m probably doing something very stupid, another pair of eyes would help.

Any ideas where I’m going wrong?

Edit: Wrote this on mobile, line numbers were wrong. Corrected now.

Could you please map out what 49 is in reference to in the dart code?

Sorry, I meant in my method in the pastebin link. And I meant to say line 48 in my code.

Paste the error output please.

Exception in thread "AWT-EventQueue-0" java.lang.IndexOutOfBoundsException: Index: 70, Size: 70
	at java.util.ArrayList.rangeCheck(Unknown Source)
	at java.util.ArrayList.get(Unknown Source)
	at com.mac.rsrl.core.world.Dungeon.lambda$0(Dungeon.java:37)
	at java.util.stream.ReferencePipeline$3$1.accept(Unknown Source)
	at java.util.HashMap$KeySpliterator.forEachRemaining(Unknown Source)
	at java.util.stream.AbstractPipeline.copyInto(Unknown Source)
	at java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
	at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(Unknown Source)
	at java.util.stream.AbstractPipeline.evaluate(Unknown Source)
	at java.util.stream.ReferencePipeline.collect(Unknown Source)
	at com.mac.rsrl.core.world.Dungeon.connectRegions(Dungeon.java:167)
	at com.mac.rsrl.core.world.Dungeon.generateDungeon(Dungeon.java:100)
	at com.mac.rsrl.core.world.Dungeon.<init>(Dungeon.java:70)
	at com.mac.rsrl.screen.GameScreen.<init>(GameScreen.java:34)
	at com.mac.rsrl.screen.StartScreen.input(StartScreen.java:25)
	at com.mac.rsrl.ApplicationMain.input(ApplicationMain.java:49)
	at com.mac.rsrl.ApplicationMain$1.keyPressed(ApplicationMain.java:31)
	at java.awt.Component.processKeyEvent(Unknown Source)
	at java.awt.Component.processEvent(Unknown Source)
	at java.awt.Container.processEvent(Unknown Source)
	at java.awt.Window.processEvent(Unknown Source)
	at java.awt.Component.dispatchEventImpl(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Window.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.KeyboardFocusManager.redispatchEvent(Unknown Source)
	at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(Unknown Source)
	at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(Unknown Source)
	at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(Unknown Source)
	at java.awt.DefaultKeyboardFocusManager.dispatchEvent(Unknown Source)
	at java.awt.Component.dispatchEventImpl(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Window.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
	at java.awt.EventQueue.access$500(Unknown Source)
	at java.awt.EventQueue$3.run(Unknown Source)
	at java.awt.EventQueue$3.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
	at java.awt.EventQueue$4.run(Unknown Source)
	at java.awt.EventQueue$4.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
	at java.awt.EventQueue.dispatchEvent(Unknown Source)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.run(Unknown Source)

The line referenced in the error refers to the pastebin link above.

               connectors.removeIf((pos) -> {
--                    List<Integer> regionss = connectorRegions.get(pos).stream().map((region) -> 
++                    List<Integer> regionss = connectorRegions.get(pos - 1).stream().map((region) -> 
merged.get(region)).collect(Collectors.toList());