diff --git a/README.md b/README.md index ba96c051..dffc3a95 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,34 @@ Under Development By Team Agile Oracles +## About This Project + +**AgileOraclesExperimentProject** is a collaborative Java learning sandbox for Team Agile Oracles. It gives every team member their own personal package to experiment, practice, and grow their Java skills — sprint by sprint. + +### Tech Stack +- **Language:** Java 17 +- **Build Tool:** Maven +- **Entry Point:** `org.example.litedesk.Main` + +### Project Structure + +The project contains **23 individual member packages** under `org.example`, each named after the contributor (e.g., `fromatyab`, `fromibrahim`, `fromkawther`). Work is typically organized into sprint sub-packages (e.g., `sprint2`, `sprint3`). + +### What's Inside + +| Area | Examples | +|------|---------| +| **Data Structures** | Stack, Queue, HashMap implementations | +| **Algorithms** | Bubble Sort, Selection Sort, Recursion | +| **Pattern Printing** | Pyramids, Staircases, Number challenges | +| **Mini Applications** | ERP systems, Customer Complaint Manager, Maze Game Bot | +| **Menus & CLI Apps** | Multi-role menus (Customer / Admin / Support Staff) | + +### Notable Classes +> Each member also has their own `Main` class as an individual entry point for their experiments. + +--- + ## Contribution Guidelines ### Step 1 diff --git a/src/main/java/org/example/fromatyab/MazeGameBot.java b/src/main/java/org/example/fromatyab/MazeGameBot.java index b4b0e9f9..85c0b67f 100644 --- a/src/main/java/org/example/fromatyab/MazeGameBot.java +++ b/src/main/java/org/example/fromatyab/MazeGameBot.java @@ -12,31 +12,92 @@ public static void main(String[] args) throws InterruptedException { int[] initialPlayerPosition = getPLayerLocation(maze); ArrayList listOfMoves = new ArrayList<>(); - // Predefined list of moves - listOfMoves.add(new int[]{9, 2}); - listOfMoves.add(new int[]{8, 2}); - listOfMoves.add(new int[]{7, 2}); - listOfMoves.add(new int[]{6, 2}); - listOfMoves.add(new int[]{5, 2}); - listOfMoves.add(new int[]{4, 2}); - listOfMoves.add(new int[]{4, 3}); - listOfMoves.add(new int[]{4, 4}); + // Step 1. Identify UP, DOWN, LEFT and RIGHT (conditional if the path is available) + int[] up = new int[]{initialPlayerPosition[0]-1, initialPlayerPosition[1]}; // [9, 2] + int[] down = new int[]{initialPlayerPosition[0]+1, initialPlayerPosition[1]}; // [11, 2] + int[] left = new int[]{initialPlayerPosition[0], initialPlayerPosition[1]-1}; // [10, 1] + int[] right = new int[]{initialPlayerPosition[0], initialPlayerPosition[1]+1}; // [10, 3] + System.out.printf("Location of @ is (%d,%d)\n", initialPlayerPosition[0], initialPlayerPosition[1]); + System.out.printf("Identified moves: UP (%d,%d), DOWN (%d,%d), LEFT (%d,%d), RIGHT (%d,%d)\n", + up[0], up[1], + down[0], down[1], + left[0], left[1], + right[0], right[1] + ); + + // Step 2. Push all valid locations into stack (Valid locations where 0 is found) + // For UP + int rowToPush = up[0]-1; + int colToPush = up[1]-1; + try { + if (maze[rowToPush][colToPush] == '0') { + // Push this location to stack + System.out.printf("Pushing [%d, %d] in STACK\n", rowToPush+1, colToPush+1); + } else { + System.out.printf("NOT Pushing [%d, %d] in STACK\n", rowToPush+1, colToPush+1); + } + } catch (ArrayIndexOutOfBoundsException e) { + System.out.printf("We are outside. There is nothing UP here at [%d, %d]\n", rowToPush, colToPush); + } - System.out.println("Before the change:"); - displayMaze(maze); + // For DOWN + rowToPush = down[0]-1; + colToPush = down[1]-1; + try { + if (maze[rowToPush][colToPush] == '0') { + // Push this location to stack + System.out.printf("Pushing [%d, %d] in STACK\n", rowToPush+1, colToPush+1); + } else { + System.out.printf("NOT Pushing [%d, %d] in STACK\n", rowToPush+1, colToPush+1); + } + } catch (ArrayIndexOutOfBoundsException e) { + System.out.printf("We are outside. There is nothing DOWN here at [%d, %d]\n", rowToPush, colToPush); + } - // Processing - int[] currPlayerPosition = initialPlayerPosition; - for (int[] currMove: listOfMoves) { - Thread.sleep(2000); - currPlayerPosition = makeMove(maze, currPlayerPosition, currMove); + // For LEFT + rowToPush = left[0]-1; + colToPush = left[1]-1; + try { + if (maze[rowToPush][colToPush] == '0') { + // Push this location to stack + System.out.printf("Pushing [%d, %d] in STACK\n", rowToPush+1, colToPush+1); + } else { + System.out.printf("NOT Pushing [%d, %d] in STACK\n", rowToPush+1, colToPush+1); + } + } catch (ArrayIndexOutOfBoundsException e) { + System.out.printf("We are outside. There is nothing LEFT here at [%d, %d]\n", rowToPush, colToPush); + } - printEmptyLines(); - displayMaze(maze); + // For RIGHT + rowToPush = right[0]-1; + colToPush = right[1]-1; + try { + if (maze[rowToPush][colToPush] == '0') { + // Push this location to stack + System.out.printf("Pushing [%d, %d] in STACK\n", rowToPush+1, colToPush+1); + } else { + System.out.printf("NOT Pushing [%d, %d] in STACK\n", rowToPush+1, colToPush+1); + } + } catch (ArrayIndexOutOfBoundsException e) { + System.out.printf("We are outside. There is nothing RIGHT here at [%d, %d]\n", rowToPush, colToPush); } + +// System.out.println("Before the change:"); +// displayMaze(maze); + + // Processing + int[] currPlayerPosition = initialPlayerPosition; + +// for (int[] currMove: listOfMoves) { +// Thread.sleep(2000); +// currPlayerPosition = makeMove(maze, currPlayerPosition, currMove); +// +// printEmptyLines(); +// displayMaze(maze); +// } } public static int[] makeMove(char[][] maze, int[] sourcePosition, int[] targetPosition) { diff --git a/src/main/java/org/example/fromatyab/SnakeGame.java b/src/main/java/org/example/fromatyab/SnakeGame.java new file mode 100644 index 00000000..f2aea7cf --- /dev/null +++ b/src/main/java/org/example/fromatyab/SnakeGame.java @@ -0,0 +1,132 @@ +package org.example.fromatyab; + +import java.util.LinkedList; +import java.util.Queue; +import java.util.Scanner; + +public class SnakeGame { + private static final int SIZE = 15; + private char[][] map = new char[SIZE][SIZE]; + private Queue snakeBody = new LinkedList<>(); + private int headRow, headCol; + + public SnakeGame() { + initializeMap(); + initializeSnake(); + } + + private void initializeMap() { + for (int i = 0; i < SIZE; i++) { + for (int j = 0; j < SIZE; j++) { + map[i][j] = '.'; + } + } + } + + private void initializeSnake() { + // Initial snake position in the middle, horizontal + headRow = SIZE / 2; + headCol = (SIZE / 2) + 2; // Head is at the right end of the 5 units + + for (int i = -2; i <= 2; i++) { + int row = SIZE / 2; + int col = (SIZE / 2) + i; + snakeBody.offer(new int[]{row, col}); + map[row][col] = 'o'; + } + } + + public void displayMap() { + System.out.print(" "); + for (int j = 0; j < SIZE; j++) System.out.print("- "); + System.out.println(); + for (int i = 0; i < SIZE; i++) { + System.out.print("| "); + for (int j = 0; j < SIZE; j++) { + System.out.print(map[i][j] + " "); + } + System.out.println("|"); + } + System.out.print(" "); + for (int j = 0; j < SIZE; j++) System.out.print("- "); + System.out.println(); + } + + public void clearDisplay() { + // As requested, use a for loop to make space before asking for another input + for (int i = 0; i < 30; i++) { + System.out.println(); + } + } + + public boolean move(String direction) { + int nextRow = headRow; + int nextCol = headCol; + + switch (direction.toLowerCase()) { + case "up": + nextRow--; + break; + case "down": + nextRow++; + break; + case "left": + nextCol--; + break; + case "right": + nextCol++; + break; + default: + System.out.println("Invalid move! Use up, down, left, right or exit."); + return true; + } + + // Check boundaries + if (nextRow < 0 || nextRow >= SIZE || nextCol < 0 || nextCol >= SIZE) { + System.out.println("Ouch! You hit a wall at (" + nextRow + "," + nextCol + "). Game Over."); + return false; + } + + // Remove tail first to allow moving into the spot the tail just vacated + int[] tail = snakeBody.poll(); + if (tail != null) { + map[tail[0]][tail[1]] = '.'; + } + + // Check if hitting itself + if (map[nextRow][nextCol] == 'o') { + System.out.println("Ouch! You hit yourself. Game Over."); + return false; + } + + // Update snake head + headRow = nextRow; + headCol = nextCol; + snakeBody.offer(new int[]{headRow, headCol}); + map[headRow][headCol] = 'o'; + + return true; + } + + public static void main(String[] args) { + SnakeGame game = new SnakeGame(); + Scanner scanner = new Scanner(System.in); + boolean running = true; + + while (running) { + game.clearDisplay(); + System.out.println("--- Snake Game (15x15) ---"); + game.displayMap(); + System.out.print("Enter move (up/down/left/right/exit): "); + String input = scanner.nextLine().trim(); + + if (input.equalsIgnoreCase("exit")) { + running = false; + } else { + running = game.move(input); + } + } + System.out.println("Thanks for playing!"); + scanner.close(); + } +}