Knight’s Travails is a pathfinding challenge that simulates a knight's movements on a standard 8×8 chessboard. The knight can move in “L” shapes, and this project calculates the shortest path it can take from a starting square to a target square using Breadth-First Search (BFS).
This project demonstrates how graph traversal algorithms and core data structures like arrays and objects can be applied to real-world problems.
- Thinking of a chessboard as an implicit graph
- Applying Breadth-First Search (BFS) to find shortest paths
- Using queues, visited tracking, and path reconstruction
- Embracing problem-solving with only core JavaScript constructs — arrays, objects, factory functions
git clone https://github.com/singharyan006/knights-travails.git
cd knights-travails
node test.js
You made it in 2 moves! Here's your path:
[0,0]
[1,2]
[3,3]
You made it in 6 moves! Here's your path:
[0,0]
[2,1]
[4,2]
[6,3]
[7,5]
[5,6]
[7,7]
- JavaScript (ES5+)
- Node.js (runtime to test the script)
- No external libraries — only core JS features
This project shows how Data Structures and Algorithms (DSA) solve real-world problems:
- 🧠 Graphs model relationships between locations (like maps, boards, networks).
- 🚀 BFS finds optimal routes — just like in GPS apps, logistics systems, or multiplayer game AIs.
- 📥 Queues simulate step-by-step exploration — useful in simulations, scheduling, and job processing.
- 🔄 Visited tracking prevents loops — crucial for memory optimization and performance.
By solving the knight’s traversal problem, we simulate the kind of logical reasoning used in:
- 🗺️ Route optimization
- 🧠 AI decision-making
- 🎮 Game development
- 🌐 Networking and pathfinding systems
- ✅ Add CLI input using
readline-sync
to allow custom user input - 🔄 Add a visual board representation (text-based)
- 🧪 Write unit tests for core logic using Jest
- ♻️ Animate paths step-by-step in the console
- 🌐 Build a web-based UI version using React or Canvas
- 📦 Refactor into modules with a more scalable architecture
Built with ❤️ by Aryan Singh
Project built as part of The Odin Project