diff --git a/Prog 3 A.iml b/Prog 3 A.iml
index ae1bd5f..01e8c30 100644
--- a/Prog 3 A.iml
+++ b/Prog 3 A.iml
@@ -7,6 +7,7 @@
+
diff --git a/TestHelloWorld/ExecutorTest.java b/TestHelloWorld/ExecutorTest.java
index c7d53ce..e9cbd78 100644
--- a/TestHelloWorld/ExecutorTest.java
+++ b/TestHelloWorld/ExecutorTest.java
@@ -1,6 +1,10 @@
import org.junit.jupiter.api.Test;
+import praktikum02.ErrorWriter;
+import praktikum02.Executor;
+import praktikum02.HelloWorldWriter;
+import praktikum02.OutWriter;
import static org.mockito.Mockito.*;
diff --git a/TestTriangle/TriangleCheckerTest.java b/TestTriangle/TriangleCheckerTest.java
index a7887e2..165242c 100644
--- a/TestTriangle/TriangleCheckerTest.java
+++ b/TestTriangle/TriangleCheckerTest.java
@@ -1,4 +1,5 @@
import org.junit.jupiter.api.Test;
+import praktikum02.TriangleChecker;
import static org.junit.jupiter.api.Assertions.*;
diff --git a/src/ErrorWriter.java b/src/praktikum02/ErrorWriter.java
similarity index 86%
rename from src/ErrorWriter.java
rename to src/praktikum02/ErrorWriter.java
index 3b181cf..0b5685d 100644
--- a/src/ErrorWriter.java
+++ b/src/praktikum02/ErrorWriter.java
@@ -1,3 +1,5 @@
+package praktikum02;
+
public class ErrorWriter implements HelloWorldWriter {
public void writeHelloWorld() {
diff --git a/src/Executor.java b/src/praktikum02/Executor.java
similarity index 95%
rename from src/Executor.java
rename to src/praktikum02/Executor.java
index c08b304..6378dff 100644
--- a/src/Executor.java
+++ b/src/praktikum02/Executor.java
@@ -1,3 +1,5 @@
+package praktikum02;
+
public class Executor {
public static void main(String[] args){
printHelloWorld(new ErrorWriter(), new ErrorWriter(), true);
diff --git a/src/HelloWorld.class b/src/praktikum02/HelloWorld.class
similarity index 100%
rename from src/HelloWorld.class
rename to src/praktikum02/HelloWorld.class
diff --git a/src/HelloWorldWriter.java b/src/praktikum02/HelloWorldWriter.java
similarity index 76%
rename from src/HelloWorldWriter.java
rename to src/praktikum02/HelloWorldWriter.java
index bc4efa5..716cebb 100644
--- a/src/HelloWorldWriter.java
+++ b/src/praktikum02/HelloWorldWriter.java
@@ -1,3 +1,4 @@
+package praktikum02;
public interface HelloWorldWriter
{
diff --git a/src/Main.java b/src/praktikum02/Main.java
similarity index 91%
rename from src/Main.java
rename to src/praktikum02/Main.java
index 16a8bd5..5819287 100644
--- a/src/Main.java
+++ b/src/praktikum02/Main.java
@@ -1,3 +1,5 @@
+package praktikum02;
+
//TIP To Run code, press or
// click the icon in the gutter.
public class Main {
diff --git a/src/OutWriter.java b/src/praktikum02/OutWriter.java
similarity index 86%
rename from src/OutWriter.java
rename to src/praktikum02/OutWriter.java
index c5b713e..1e010aa 100644
--- a/src/OutWriter.java
+++ b/src/praktikum02/OutWriter.java
@@ -1,3 +1,4 @@
+package praktikum02;
public class OutWriter implements HelloWorldWriter{
diff --git a/src/praktikum02/PasswordCheckers.java b/src/praktikum02/PasswordCheckers.java
new file mode 100644
index 0000000..9c5e37c
--- /dev/null
+++ b/src/praktikum02/PasswordCheckers.java
@@ -0,0 +1,29 @@
+package praktikum02;
+
+public class PasswordCheckers {
+
+ String pw = "twert5zezu";
+ public int lengthPw(String pw){
+ return pw.length();
+ }
+
+ public void numbersInPw(){
+ int tempNum = 0;
+ for(int i = 0;i > pw.length(); i++){
+ char c = pw.charAt(i);
+ counter(c);
+ }
+
+ return ;
+ }
+
+ public void signsInPw(){
+
+ }
+
+ public void counter(char c){
+ if(Character.isDigit(c)){
+
+ }
+ }
+}
diff --git a/src/praktikum03/teil1/BetterPhilosopher.java b/src/praktikum03/teil1/BetterPhilosopher.java
new file mode 100644
index 0000000..b6930f5
--- /dev/null
+++ b/src/praktikum03/teil1/BetterPhilosopher.java
@@ -0,0 +1,50 @@
+package praktikum03.teil1;
+
+public class BetterPhilosopher implements Runnable {
+ private int id;
+ private final Fork lowerFork;
+ private final Fork higherFork;
+
+ public BetterPhilosopher(int id, Fork left, Fork right) {
+ this.id = id;
+ // Sortieren der Gabel, keliner zuerst
+ if (left.getId() < right.getId()) {
+ this.lowerFork = left;
+ this.higherFork = right;
+ } else {
+ this.lowerFork = right;
+ this.higherFork = left;
+ }
+ }
+
+ @Override
+ public void run() {
+
+ //Gabel kleineren ID a
+ System.out.println("Philosopher " + id + " is trying to get fork " + lowerFork.getId());
+ while (!lowerFork.take()) {
+ Thread.yield();
+ }
+ System.out.println("Philosopher " + id + " got fork " + lowerFork.getId());
+
+ // Gabel größeren ID
+ System.out.println("Philosopher " + id + " is trying to get fork " + higherFork.getId());
+ while (!higherFork.take()) {
+ Thread.yield();
+ }
+ System.out.println("Philosopher " + id + " got fork " + higherFork.getId());
+
+ // Essen
+ System.out.println("Philosopher " + id + " is eating");
+ try {
+ Thread.sleep(2000); // Der Philosoph isst für 2 Sekunden
+ } catch (InterruptedException e) {
+ System.out.println("Philosopher" + id + "was interupted while eating");
+ }
+
+ // Gabeln freigeben
+ lowerFork.put();
+ higherFork.put();
+ System.out.println("Philosopher " + id + " finished eating");
+ }
+}
\ No newline at end of file
diff --git a/src/praktikum03/teil1/Fork.java b/src/praktikum03/teil1/Fork.java
new file mode 100644
index 0000000..54477bf
--- /dev/null
+++ b/src/praktikum03/teil1/Fork.java
@@ -0,0 +1,38 @@
+package praktikum03.teil1;
+
+public class Fork{
+ private boolean inUse = false;
+ private int id;
+
+ public Fork(int id) {
+ this.id = id;
+ }
+
+ public int getId() {
+ return this.id;
+ }
+
+ public synchronized boolean take() {
+
+ synchronized (this) {
+ if (!inUse) {
+ // Verzögerung von 1 Sekunde
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ System.out.println("Take Fork" + id + "was interupted");
+ }
+ inUse = true;
+ return true;
+ } else {
+ return false;
+ }
+ }
+ }
+
+ public synchronized void put() {
+ synchronized (this) {
+ inUse = false;
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/praktikum03/teil1/Philosopher.java b/src/praktikum03/teil1/Philosopher.java
new file mode 100644
index 0000000..0cac5a6
--- /dev/null
+++ b/src/praktikum03/teil1/Philosopher.java
@@ -0,0 +1,44 @@
+package praktikum03.teil1;
+
+public class Philosopher implements Runnable {
+ protected int id;
+ protected final Fork left;
+ protected final Fork right;
+
+ public Philosopher(int id, Fork left, Fork right) {
+ this.id = id;
+ this.left = left;
+ this.right = right;
+ }
+
+ @Override
+ public void run() {
+ // Linke Gabel
+ System.out.println("Philosopher " + id + " is trying to get fork " + left.getId());
+ while (!left.take()) {
+ Thread.yield(); // Bereit für ander Threads
+ }
+ System.out.println("Philosopher " + id + " got fork " + left.getId());
+
+ // Rechte Gabel
+ System.out.println("Philosopher " + id + " is trying to get fork " + right.getId());
+ while (!right.take()) {
+ Thread.yield();
+ }
+ System.out.println("Philosopher " + id + " got fork " + right.getId());
+
+ // Essen
+ System.out.println("Philosopher " + id + " is eating");
+ try {
+ Thread.sleep(2000); // 2 Sekunden
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ }
+
+ // Gabeln freigeben
+ left.put();
+ right.put();
+
+ System.out.println("Philosopher " + id + " finished eating");
+ }
+}
\ No newline at end of file
diff --git a/src/praktikum03/teil1/Table.java b/src/praktikum03/teil1/Table.java
new file mode 100644
index 0000000..bb79372
--- /dev/null
+++ b/src/praktikum03/teil1/Table.java
@@ -0,0 +1,31 @@
+package praktikum03.teil1;
+
+public class Table {
+
+ public static void main(String[] args) {
+ Fork[] forks = { new Fork(0), new Fork(1), new Fork(2), new Fork(3), new Fork(4)};
+
+ BetterPhilosopher[] philosophers = {
+ new BetterPhilosopher(0, forks[0], forks[1]),
+ new BetterPhilosopher(1, forks[1], forks[2]),
+ new BetterPhilosopher(2, forks[2], forks[3]),
+ new BetterPhilosopher(3, forks[3], forks[4]),
+ new BetterPhilosopher(4, forks[4], forks[0])
+ };
+
+ for(BetterPhilosopher philosopher : philosophers) {
+ Thread t = new Thread(philosopher);
+ t.start();
+ }
+
+ }
+}
+
+/*weil jeder Philosoph zwei Gabeln benötigt, um zu essen,
+und sie immer in einer bestimmten Reihenfolge aufnimmt:
+zuerst die linke, dann die rechte.
+Wenn alle Philosophen gleichzeitig ihre jeweils linke Gabel aufnehmen,
+sind alle linken Gabeln in Benutzung, und keiner kann die rechte Gabel erreichen.
+Dadurch warten alle Philosophen darauf, dass ein anderer seine Gabel freigibt,
+ was niemals passiert, da alle blockiert sind – das ist ein klassischer Deadlock.
+ */
\ No newline at end of file
diff --git a/src/praktikum03/teil2/SorterClient.java b/src/praktikum03/teil2/SorterClient.java
new file mode 100644
index 0000000..0a2969e
--- /dev/null
+++ b/src/praktikum03/teil2/SorterClient.java
@@ -0,0 +1,60 @@
+package praktikum03.teil2;
+
+import java.io.*;
+import java.net.InetSocketAddress;
+import java.net.Socket;
+import java.util.Scanner;
+
+public class SorterClient {
+
+ public static void main(String[] args) {
+ SorterClient client = new SorterClient();
+ client.run();
+ }
+
+ private void run() {
+ Scanner scanner = new Scanner(System.in);
+ while (scanner.hasNextLine()) {
+ String line = scanner.nextLine();
+ if (line.isEmpty()) {
+ break;
+ }
+
+ //Verbindung Server => Rückgabe sortierte Zeile
+ String sortedLine = communicateWithServer(line);
+
+ System.out.println("Sortierte Zeile vom Server: " + sortedLine);
+ }
+ scanner.close();
+ }
+
+ private String communicateWithServer(String line){
+
+ InetSocketAddress address = new InetSocketAddress("localhost", 12345);
+ try (Socket socket = new Socket()) {
+ socket.connect(address);
+
+ //Zeile an Server
+ sendLine(socket, line);
+
+ return receiveLine(socket);
+
+ } catch (IOException e) {
+ System.err.println("Fehler: " + e.getMessage());
+ return "";
+ }
+ }
+
+ //AUS SKRIPT*******************************
+ private void sendLine(Socket socket, String line) throws IOException {
+ OutputStream out = socket.getOutputStream();
+ PrintWriter writer = new PrintWriter(out, true);
+ writer.println(line);
+ }
+
+ private String receiveLine(Socket socket) throws IOException {
+ InputStream in = socket.getInputStream();
+ BufferedReader reader = new BufferedReader(new InputStreamReader(in));
+ return reader.readLine();
+ }
+}
\ No newline at end of file
diff --git a/src/praktikum03/teil2/SorterServer.java b/src/praktikum03/teil2/SorterServer.java
new file mode 100644
index 0000000..c0c80cf
--- /dev/null
+++ b/src/praktikum03/teil2/SorterServer.java
@@ -0,0 +1,79 @@
+package praktikum03.teil2;
+
+import java.io.*;
+import java.net.ServerSocket;
+import java.net.Socket;
+
+public class SorterServer implements Runnable {
+
+ private Socket socket;
+
+ // Konstruktor
+ public SorterServer(Socket socket) {
+ this.socket = socket;
+ }
+
+ @Override
+ public void run() {
+ try {
+ // Client empfangen
+ String word = receiveLine();
+ System.out.println("Empfangene Zeile: " + word);
+
+ // Buchstaben sort
+ String sortedWord = sort(word);
+
+ // Bearbeitung erfolgt
+ System.out.println(word + "->" + sortedWord);
+
+ // Antwort an Client
+ sendLine(sortedWord);
+
+ } catch (IOException e) {
+ System.err.println("Fehler bei der Kommunikation: " + e.getMessage());
+ } finally {
+ try {
+ socket.close();
+ } catch (IOException e) {
+ System.err.println("Fehler beim Schließen des Sockets: " + e.getMessage());
+ }
+ }
+ }
+
+ private String sort(String word) {
+ // Konvert. String Array, sortieren
+ char[] chars = word.toCharArray();
+ java.util.Arrays.sort(chars);
+ return new String(chars);
+ }
+
+ public static void main(String[] args) {
+
+ final int port = 12345;
+ try (ServerSocket serverSocket = new ServerSocket(port)) {
+ System.out.println("Server gestartet auf Port " + port);
+
+ while (true) {
+ Socket clientSocket = serverSocket.accept();
+ Thread thread = new Thread(new SorterServer(clientSocket));
+ thread.start();
+ }
+ } catch (IOException e) {
+ System.err.println("Fehler beim Starten des Servers: " + e.getMessage());
+ }
+ }
+
+
+ //AUS SKRIPT*******************************
+ private String receiveLine() throws IOException {
+ InputStream in = socket.getInputStream();
+ BufferedReader reader = new BufferedReader(new InputStreamReader(in));
+ return reader.readLine();
+ }
+
+ private void sendLine(String line) throws IOException {
+ OutputStream out = socket.getOutputStream();
+ PrintWriter writer = new PrintWriter(out, true); // Auto-flush
+ writer.println(line);
+ }
+}
\ No newline at end of file
diff --git a/src/praktikum04/EscapeBot.java b/src/praktikum04/EscapeBot.java
new file mode 100644
index 0000000..23a990a
--- /dev/null
+++ b/src/praktikum04/EscapeBot.java
@@ -0,0 +1,64 @@
+package praktikum04;
+
+import praktikum04.Bot;
+
+public class EscapeBot extends Bot {
+
+ private int step = 1; // Anzahl der Schritte in eine Richtung
+ private int direction = 0; // 0 = rechts, 1 = runter, 2 = links, 3 = hoch
+ private int movesInDirection = 0; // Schritte in aktueller Richtung
+ private int changes = 0; // Anzahl der Richtungswechsel
+
+ public EscapeBot(String[] args) {
+ super(args);
+ }
+
+ public static void main(String[] args) {
+ Bot bot = new EscapeBot(args);
+ bot.run();
+ }
+
+ @Override
+ protected char nextMove(View view) throws Exception {
+ int width = view.width;
+ int height = view.data.length() / width;
+ char[] field = view.data.toCharArray();
+
+ // Position des Rovers finden
+ int roverPos = view.data.indexOf('R');
+ int roverX = roverPos % width;
+ int roverY = roverPos / width;
+
+ // Position der Rakete finden
+ int rocketPos = view.data.indexOf('o');
+ if (rocketPos != -1) {
+ int rocketX = rocketPos % width;
+ int rocketY = rocketPos / width;
+
+ // Richtung zur Rakete bestimmen und bewegen
+ if (rocketX < roverX) return '<'; // Links bewegen
+ if (rocketX > roverX) return '>'; // Rechts bewegen
+ if (rocketY < roverY) return '^'; // Hoch bewegen
+ if (rocketY > roverY) return 'v'; // Runter bewegen
+ }
+
+ return spiralSearch(); // Falls Rakete nicht sichtbar ist, weitersuchen
+ }
+
+ private char spiralSearch() {
+ // Bewege dich in einer spiralförmigen Suche
+ char[] moves = {'>', 'v', '<', '^'}; // Reihenfolge: rechts, runter, links, hoch
+ char move = moves[direction];
+
+ movesInDirection++;
+ if (movesInDirection == step) {
+ movesInDirection = 0;
+ direction = (direction + 1) % 4;
+ changes++;
+ if (changes % 2 == 0) {
+ step++; // Nach zwei Richtungswechseln Schrittgröße erhöhen
+ }
+ }
+ return move;
+ }
+}
\ No newline at end of file
diff --git a/src/praktikum04/ManualBot.java b/src/praktikum04/ManualBot.java
new file mode 100644
index 0000000..dad4d1b
--- /dev/null
+++ b/src/praktikum04/ManualBot.java
@@ -0,0 +1,83 @@
+package praktikum04;
+
+import praktikum03.teil2.SorterClient;
+
+import java.io.IOException;
+import java.util.Scanner;
+
+
+public class ManualBot extends Bot{
+
+ ManualBot(String[] args) {
+ super(args);
+ }
+
+ public static void main(String[] args) {
+ Bot bot = new ManualBot(args);
+ bot.run();
+
+ }
+
+ /*public void run() {
+ Scanner scanner = new Scanner(System.in);
+ while (scanner.hasNextLine()) {
+ String line = scanner.nextLine();
+ if (line.isEmpty()) {
+ break;
+ }
+
+ int direction = nextMove();
+ System.out.println(direction);
+ }*/
+
+ @Override
+ protected char nextMove(View view) throws Exception {
+ System.out.println("Geben Sie den nächsten Befehl ein:");
+ //System.out.println("w = Vorwärts, s = Rückwärts, a = Linksdrehung, d = Rechtsdrehung, q = Abbruch");
+
+ String field = view.data;
+ int width = view.width;
+ System.out.println(field);
+ System.out.println(width);
+ System.out.println(field.length());
+
+ for(int i = 0 ; i < field.length(); i++){
+
+ int c = field.indexOf("o");
+ //System.out.println(i);
+ //System.out.println(c);
+ /*if(c>-1) {
+ System.out.println(" ist an stelle" + c);
+ }*/
+ if (c>-1){
+ System.out.println("Gefunden!!");
+ } else {
+ System.out.println("Suche weiter....");
+ }
+ }
+
+ // Eingabe des Nutzers lesen
+ Scanner scanner = new Scanner(System.in);
+ String input = scanner.nextLine();
+
+ // Eingabe validieren und Rückgabewert bestimmen
+ switch (input) {
+ case "w":
+ return '^'; // Vorwärts
+ case "s":
+ return 'v'; // Rückwärts
+ case "a":
+ return '<'; // Linksdrehung
+ case "d":
+ return '>'; // Rechtsdrehung
+ case "q":
+ System.out.println("Verbindung wird beendet...");
+ throw new Exception("Abbruch durch den Nutzer"); // Verbindung beenden
+ default:
+ System.out.println("Ungültige Eingabe. Bitte erneut versuchen.");
+ return nextMove(view); // Erneut aufrufen
+ }
+ }
+
+}
+
diff --git a/src/praktikum04/SnakeBot.java b/src/praktikum04/SnakeBot.java
new file mode 100644
index 0000000..4747048
--- /dev/null
+++ b/src/praktikum04/SnakeBot.java
@@ -0,0 +1,131 @@
+package praktikum04;
+
+import praktikum04.Bot;
+import java.util.*;
+
+public class SnakeBot extends Bot {
+ private List wagons = new ArrayList<>(); // Speichert die Positionen der Wagen
+ private Set collectedStones = new HashSet<>(); // Speichert bereits gesammelte Steine
+ private Set visitedPositions = new HashSet<>(); // Speichert besuchte Positionen
+ private Random random = new Random(); // Zufallsgenerator für Bewegung
+
+ public SnakeBot(String[] args) {
+ super(args);
+ }
+
+ public static void main(String[] args) {
+ Bot bot = new SnakeBot(args);
+ bot.run();
+ }
+
+ @Override
+ protected char nextMove(View view) throws Exception {
+ int width = view.width;
+ int height = view.data.length() / width;
+ char[] field = view.data.toCharArray();
+
+ // Position des Rovers finden
+ int roverPos = findRoverPosition(field);
+ if (roverPos == -1) {
+ System.out.println("FEHLER: Rover nicht gefunden! Scan-Daten: " + new String(field));
+ return '>';
+ }
+ int roverX = roverPos % width;
+ int roverY = roverPos / width;
+ System.out.println("Rover Position: (" + roverX + ", " + roverY + ")");
+ visitedPositions.add(roverPos);
+
+ // Positionen der Wagen aktualisieren
+ wagons.clear();
+ for (int i = 0; i < field.length; i++) {
+ if (field[i] == '*') wagons.add(i);
+ }
+
+ // Gesteinsproben suchen
+ int stonePos = view.data.indexOf('@');
+ if (stonePos != -1 && !collectedStones.contains(stonePos)) {
+ collectedStones.add(stonePos); // Markiere diesen Stein als gesammelt
+ int stoneX = stonePos % width;
+ int stoneY = stonePos / width;
+ System.out.println("Gesteinsprobe gefunden bei: (" + stoneX + ", " + stoneY + ")");
+
+ char move = getBestMove(roverX, roverY, stoneX, stoneY, roverPos, width, field);
+ if (move != ' ') {
+ System.out.println("Bewege mich in Richtung Stein: " + move);
+ return move;
+ }
+ }
+
+ // Falls keine neuen Gesteinsproben sichtbar sind, zufällig erkunden
+ char move = exploreRandomly(roverPos, width, field);
+ System.out.println("Keine neuen Steine in Sicht, erkunde zufällig: " + move);
+ return move;
+ }
+
+ private int findRoverPosition(char[] field) {
+ char[] roverSymbols = {'R', 'A', '^', '<', '>', 'v'};
+ for (char symbol : roverSymbols) {
+ int pos = new String(field).indexOf(symbol);
+ if (pos != -1) return pos;
+ }
+ return -1;
+ }
+
+ private char getBestMove(int roverX, int roverY, int targetX, int targetY, int roverPos, int width, char[] field) {
+ if (targetX < roverX && isSafeMove(roverPos - 1, field)) return '<';
+ if (targetX > roverX && isSafeMove(roverPos + 1, field)) return '>';
+ if (targetY < roverY && isSafeMove(roverPos - width, field)) return '^';
+ if (targetY > roverY && isSafeMove(roverPos + width, field)) return 'v';
+ return ' ';
+ }
+
+ private boolean isSafeMove(int newPos, char[] field) {
+ return newPos >= 0 && newPos < field.length && field[newPos] != '*' && field[newPos] != 'X' && field[newPos] != '#';
+ }
+
+ private char exploreRandomly(int roverPos, int width, char[] field) {
+ List possibleMoves = new ArrayList<>();
+ char[] moves = {'^', 'v', '<', '>'};
+
+ // Sammle alle möglichen Bewegungen
+ for (char move : moves) {
+ int newPos = getNewPosition(roverPos, move, width);
+ if (isSafeMove(newPos, field) && !visitedPositions.contains(newPos)) {
+ possibleMoves.add(move);
+ }
+ }
+
+ // Falls neue Bereiche verfügbar sind, wähle eine zufällige Richtung
+ if (!possibleMoves.isEmpty()) {
+ char chosenMove = possibleMoves.get(random.nextInt(possibleMoves.size()));
+ System.out.println("Zufällige neue Richtung gewählt: " + chosenMove);
+ return chosenMove;
+ }
+
+ // Falls keine neuen Bereiche verfügbar sind, sichere Bewegung wählen
+ return avoidCollisionAndMove(roverPos, width, field);
+ }
+
+ private char avoidCollisionAndMove(int roverPos, int width, char[] field) {
+ char[] moves = {'^', 'v', '<', '>'};
+ for (char move : moves) {
+ int newPos = getNewPosition(roverPos, move, width);
+ if (isSafeMove(newPos, field)) {
+ System.out.println("Sichere Richtung gefunden: " + move);
+ return move;
+ }
+ }
+ System.out.println("Keine sichere Richtung gefunden, bewege mich notfalls nach rechts.");
+ return '>';
+ }
+
+ private int getNewPosition(int currentPos, char move, int width) {
+ switch (move) {
+ case '^': return currentPos - width;
+ case 'v': return currentPos + width;
+ case '<': return currentPos - 1;
+ case '>': return currentPos + 1;
+ default: return -1;
+ }
+ }
+}
\ No newline at end of file