The problem is as follows:
Assume that you have an N*N chess board with a knight in some cell called "start" point, and an arbitrary cell called "target" point.
Calculate the shortest path for the knight from start to target (the knight may move two cells vertically and one cell horizontally, or two cells horizontally and one cell vertically).
- Clone the project:
git clone git@github.com:Javad-Alipanah/ksp.git && cd ksp
- Build:
make static
- Run:
sudo docker-compose up -d
Now the GraphQL endpoint is available at localhost
To see the project logs run:
sudo docker-compose logs [-f]
The project has a GraphQL endpoint by default at localhost from which you can interact with the application and calculate the answer for different outputs.
If you are not familiar with GraphQL you can visit here for introductory info.
If you visit the project root at localhost you can see an interactive console from which you can execute these queries and mutations:
query {
boards {
# subfield selection
}
}
Full Example:
query {
boards {
id
size
start {
x
y
}
target {
x
y
}
path {
x
y
}
}
}
query {
board(id: $someId) {
# subfield selection
}
}
Full Example:
query {
board(id: 4) {
id
size
start {
x
y
}
target {
x
y
}
path {
x
y
}
}
}
Note: The path calcultaion is asynchronous; so when you create or update a board, the returned path is always empty. You must qury the board to get the calculated shortest path. If the path is still empty then no route from "start" to "target" exists.
mutation {
createBoard(input:{size: $size, start: {x: $x1, y: $y1}, target: {x: $x2, y: $y2}}) {
# subfield selection
}
}
Full Example:
mutation {
createBoard(input:{size: 4, start: {x: 1, y:1}, target: {x: 2, y:2}}) {
id
size
start {
x
y
}
target {
x
y
}
path {
x
y
}
}
}
mutation {
updateBoard(board: $partialBoardJsonWithIdProvided) {
# subfield selection
}
}
Full Example:
mutation {
updateBoard(board:{id: 6, size: 6}) {
id
size
start {
x
y
}
target {
x
y
}
path {
x
y
}
}
}
Note: No subfield selection is allowed. The only returned data is either an error or a boolean indicating whether the delete succeded or not.
mutation {
deleteBoard(id: $someId)
}
Example:
mutation {
deleteBoard(id: 6)
}
-
Create the Board:
mutation { createBoard( board: { size: 15, start: { x: 3, y: 7 }, target: { x: 6, y: 0 } } ) { id } }
-
Query the Board:
query { board(id: $idFromPrevStep) { path { x y } } }
-
Verify the Output:
{ "data": { "board": { "path": [ { "x": 3, "y": 7 }, { "x": 4, "y": 5 }, { "x": 5, "y": 3 }, { "x": 4, "y": 1 }, { "x": 6, "y": 0 } ] } } }