NETS is a hybrid puzzle game that combines a JavaFX GUI with a high-performance C++ Computational Engine. The goal is to rotate network tiles to connect all clients (PCs) to a central server (Power Source) without leaving loose ends or creating closed loops.
This project demonstrates the practical application of Design and Analysis of Algorithms (DAA) concepts, including Graph Theory, Greedy Algorithms, Minimum Spanning Trees, and Complexity Analysis.
- Hybrid Architecture: Java for the interactive UI and C++ for heavy algorithmic processing.
- Procedural Level Generation: Uses Randomized Prim's Algorithm to generate unique, solvable puzzles every time.
-
High-Performance Engine: Optimized C++ backend using bitwise operations, cache-friendly data structures (1D grid), and
$O(1)$ graph lookups. - Advanced AI Visualizer: A specialized mode to watch the AI's search process in real-time with smooth, directional animations.
- Multiple Solvers: Includes Backtracking (BT), Dynamic Programming (DP), and Divide & Conquer (D&C) implementations.
- Real-time Graph Analysis: Instant feedback on connectivity, loops, and loose ends using DFS.
- Dynamic Difficulty: Supports board sizes from 3x3 up to 15x15.
- Frontend / UI: Java 17+, JavaFX 21
- Backend / Engine: C++17 (Highly optimized for cache locality and bitwise speed)
- Build Tools: Maven (Java), Make/G++ (C++)
- Communication: JSON-based Inter-Process Communication (IPC) via StdIO
-
1D Grid Flattening: The board representation was moved from a 2D
vector<vector<Tile>>to a 1Dvector<Tile>. This significantly improves cache hits and reduces memory allocation overhead during recursive solving. -
Bitwise Port Matching: Replaced expensive
vector<Direction>allocations withuint8_tbitmasks. Constraint checking now uses$O(1)$ bitwise AND/SHIFT operations. -
Graph Optimization: Replaced
std::mapandstd::setin the Graph structure with flattenedstd::vectorandvector<bool>, reducing graph traversal overhead from$O(\log V)$ to$O(1)$ .
- Directional Animations: The AI Visualizer now uses intelligent rotation logic:
- TRY steps rotate Clockwise (Right) to show the search path.
- UNDO steps rotate Counter-Clockwise (Left) to show backtracking.
- Smooth Transitions: Implemented JavaFX
Timelineanimations for all tile rotations, providing a polished and "alive" feel to the game. - Polished Sidebar: Optimized the step-details panel to prevent text truncation and provide clearer algorithm labeling (e.g., "DP" for Dynamic Programming).
nets/
├── cpp/ # C++ Engine Source Code
│ ├── GameLogic.hpp # Core game rules
│ ├── GraphBuilder.hpp # Adjacency List construction (Optimized)
│ ├── CpuStrategy.hpp # Greedy AI logic
│ ├── DacSolver.hpp # Divide-and-conquer global solver
│ ├── BtSolver.hpp # BT solver (Backtracking)
│ ├── DpSolver.hpp # DP solver (Dynamic Programming)
│ ├── SortUtils.hpp # Merge Sort (D&C) for tiles
│ └── ConnectivityCheck.hpp # DFS & Cycle Detection (O(1) lookups)
├── netgame/ # Java Application Source Code
│ ├── pom.xml # Maven dependencies
│ └── src/main/java/com/nets/
│ ├── controller/ # Game Logic & IPC Controller
│ ├── model/ # Data Models (GameState, Tile, VisualStep)
│ └── view/ # JavaFX GUI & Animation Components
├── nets_engine.cpp # C++ Entry Point (Optimized main loop)
├── Makefile # C++ Build Script
├── README.md # Project Documentation
├── qna.md # Detailed Algorithm Analysis
└── workflow.md # Execution Flow Documentation
- Randomized Prim's Algorithm: Generates a perfect Spanning Tree (no cycles, fully connected) from the center outwards. This ensures every puzzle has at least one valid solution.
- Depth First Search (DFS): Used to traverse the grid and count:
- Connected Components: Should be 1 for a win.
- Loose Ends: Wires pointing to empty space or mismatched ports.
- Cycles: Closed loops, which are forbidden.
- Greedy Approach (CPU): Evaluates possible rotations and picks the one that minimizes the Heuristic Cost.
- DP Solver: Explores the state space using memoized recursion and a compact frontier state. Uses optimized bitmasks for ultra-fast constraint checking.
- D&C Solver: Splits the board into sub-regions and combines them via cut-edge constraints.
- Visualizer Mode: Records every "TRY" and "UNDO" operation from the engine and replays them in the UI with directional animations.
- Java Development Kit (JDK) 17 or higher.
- Maven 3.x installed and added to PATH.
- G++ Compiler (supporting C++17).
- Make build tool.
The project includes a Makefile that handles both the C++ compilation and the Java launch.
First, compile the high-performance engine:
make
# Generates nets_engine.exeThis command will compile the Java application and launch the GUI:
make gameTo remove compiled binaries and temporary files:
make clean- Launch the Game: Select your grid size (e.g., 5x5).
- Objective: Rotate tiles to create a single connected network powering all PCs.
- Controls:
- Left Click: Rotate a tile 90° clockwise.
- Locked Tiles: The Power Source (Server) is locked and cannot be rotated.
- Win Condition:
- All PCs are powered (green wires).
- No loose ends.
- No closed loops.
For a deeper dive into the architecture and execution flow, refer to:
- WORKFLOW.md: Step-by-step execution details from startup to termination.
- QnA.md: Academic defense, algorithmic analysis, and complexity details.