Skip to content

Commit 7f4bc3b

Browse files
committed
go away and 3d movement
1 parent 1d4eb20 commit 7f4bc3b

File tree

2 files changed

+56
-2
lines changed

2 files changed

+56
-2
lines changed

src/main/java/com/falsepattern/jfunge/interpreter/instructions/Funge98.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,44 @@ public static void unloadFinger(ExecutionContext ctx) {
7373
@Instr('v')
7474
public static void south(ExecutionContext ctx) {ctx.IP().delta.set(0, 1, 0);}
7575

76+
@Instr('h')
77+
public static void high(ExecutionContext ctx) {
78+
if (ctx.dimensions() == 3)
79+
ctx.IP().delta.set(0, 0, 1);
80+
else
81+
ctx.interpret('r');
82+
}
83+
84+
@Instr('l')
85+
public static void low(ExecutionContext ctx) {
86+
if (ctx.dimensions() == 3)
87+
ctx.IP().delta.set(0, 0, -1);
88+
else
89+
ctx.interpret('r');
90+
}
91+
92+
@Instr('?')
93+
public static void away(ExecutionContext ctx) {
94+
var random = Math.abs(ctx.IP().nextRandom());
95+
if (ctx.dimensions() == 3) {
96+
switch (random % 6) {
97+
case 0: east(ctx); break;
98+
case 1: south(ctx); break;
99+
case 2: west(ctx); break;
100+
case 3: north(ctx); break;
101+
case 4: high(ctx); break;
102+
case 5: low(ctx); break;
103+
}
104+
} else {
105+
switch (random % 4) {
106+
case 0: east(ctx); break;
107+
case 1: south(ctx); break;
108+
case 2: west(ctx); break;
109+
case 3: north(ctx); break;
110+
}
111+
}
112+
}
113+
76114
@Instr('<')
77115
public static void west(ExecutionContext ctx) {ctx.IP().delta.set(-1, 0, 0);}
78116

src/main/java/com/falsepattern/jfunge/ip/InstructionPointer.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,40 @@
55
import gnu.trove.map.TObjectIntMap;
66
import gnu.trove.map.hash.TObjectIntHashMap;
77
import lombok.Getter;
8+
import lombok.SneakyThrows;
89
import org.joml.Vector3i;
910

11+
import java.security.SecureRandom;
12+
1013
public class InstructionPointer implements Copiable<InstructionPointer> {
1114
public final Vector3i position;
1215
public final Vector3i delta;
1316
public final Vector3i storageOffset;
1417
public final StackStack stackStack;
1518
public final InstructionManager instructionManager;
1619
public final TObjectIntMap<String> customStorage;
17-
@Getter
18-
private boolean dead = false;
20+
1921
public boolean stringMode = false;
2022
public int UUID;
2123

24+
private final SecureRandom rng;
25+
26+
@Getter
27+
private boolean dead = false;
28+
29+
@SneakyThrows
2230
public InstructionPointer() {
2331
position = new Vector3i();
2432
delta = new Vector3i(1, 0, 0);
2533
storageOffset = new Vector3i();
2634
stackStack = new StackStack();
2735
instructionManager = new InstructionManager();
2836
customStorage = new TObjectIntHashMap<>();
37+
rng = SecureRandom.getInstanceStrong();
38+
UUID = 0;
2939
}
3040

41+
@SneakyThrows
3142
private InstructionPointer(InstructionPointer original) {
3243
position = new Vector3i(original.position);
3344
delta = new Vector3i(original.delta);
@@ -37,13 +48,18 @@ private InstructionPointer(InstructionPointer original) {
3748
stringMode = original.stringMode;
3849
instructionManager = original.instructionManager.deepCopy();
3950
customStorage = new TObjectIntHashMap<>(original.customStorage);
51+
rng = SecureRandom.getInstanceStrong();
4052
UUID = 0;
4153
}
4254

4355
public void die() {
4456
dead = true;
4557
}
4658

59+
public int nextRandom() {
60+
return rng.nextInt();
61+
}
62+
4763
@Override
4864
public InstructionPointer deepCopy() {
4965
return new InstructionPointer(this);

0 commit comments

Comments
 (0)