Skip to content

Commit

Permalink
Merge pull request #28968 from PivtoranisV/knights_travails_update
Browse files Browse the repository at this point in the history
Project Knights Travails: Adding additional information about the Graphs data structure
  • Loading branch information
wise-king-sullyman authored Oct 18, 2024
2 parents 27d9ccf + 99b5d0a commit 455aae5
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions javascript/computer_science/project_knights_travails.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 455aae5

Please sign in to comment.