Skip to content

This project explores graph traversal using Breadth-First Search (BFS) to find the shortest path a knight can take on a standard 8×8 chessboard. Each square is treated as a node in an implicit graph, and knight moves represent edges. The goal is to compute the minimum-move path from a starting position to a target square.

License

Notifications You must be signed in to change notification settings

singharyan006/knights-travails

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

♞ Knight's Travails

Odin Project


📖 Overview

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.


🧠 What This Project Teaches

  • 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

🚀 Getting Started

1. Clone the repository

git clone https://github.com/singharyan006/knights-travails.git
cd knights-travails

2. Run the test script

node test.js

3.💡Sample Output

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]

⚙️ Tech Used

  • JavaScript (ES5+)
  • Node.js (runtime to test the script)
  • No external libraries — only core JS features

🧩 Real-World Relevance: DSA in Action

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

🔮 Future Improvements

  • ✅ 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


🧑‍💻 Author

Built with ❤️ by Aryan Singh
Project built as part of The Odin Project


About

This project explores graph traversal using Breadth-First Search (BFS) to find the shortest path a knight can take on a standard 8×8 chessboard. Each square is treated as a node in an implicit graph, and knight moves represent edges. The goal is to compute the minimum-move path from a starting position to a target square.

Topics

Resources

License

Stars

Watchers

Forks