diff --git a/javascript/computer_science/project_knights_travails.md b/javascript/computer_science/project_knights_travails.md index 987da6f2bb..d0629cfdbd 100644 --- a/javascript/computer_science/project_knights_travails.md +++ b/javascript/computer_science/project_knights_travails.md @@ -11,6 +11,21 @@ All the possible places you can end up after one move look like this: ![Knights Travails board](https://cdn.statically.io/gh/TheOdinProject/curriculum/d30038e0aaca1f35e58e205e37a21b2c9d31053d/javascript/computer_science/project_knights_travails/imgs/01.png) Note: The picture is only to explain the problem, There is no need to create a GUI. +In this problem, the chessboard can be represented as a graph: + +Each square on the board is a node (or vertex). +A knight’s valid moves from any square represent the edges (or connections) between the vertices. +Thus, the problem of finding the shortest path for the knight’s movement becomes a graph traversal problem. The goal is to traverse the graph (the chessboard) to find the shortest route between two nodes (the start and end positions). + +#### Vertices and Edges + +The vertices in this graph are each of the possible positions on the chessboard, represented by a pair of coordinates like `[x, y]`, where x and y are between 0 and 7. +The edges are the valid knight moves between vertices. For example, from `[0,0]`, a knight can move to `[2,1]`, `[1,2]`, and so on. Each of these moves represents a connection between the vertex `[0,0]` and the other reachable vertices. + +#### Graph Representation + +While solving this problem, you don’t need to explicitly create a graph object with vertices and edges. Instead, you can think of the graph as implicit. The knight starts on a specific vertex, and the algorithm will dynamically explore all possible moves (edges) to other vertices (positions on the board) as it traverses the board. + ### Assignment Your task is to build a function `knightMoves` that shows the shortest possible way to get from one square to another by outputting all squares the knight will stop on along the way.