Algorithm API
On this page
Botfather’s Algorithm API is a collection of algorithms we think are useful for script creators.
Examples
Algorithm.dijkstra(graph, start_node, dest_node);
graph(object): The graph (See description)start_node(string): Name of the start nodedest_node(string): Name of the destination node
This method uses Dijkstra’s algorithm to find the shortest path from a start_node to a dest_node in a graph.
Such a graph could be anything, for instance, the map in an online game or the sitemap of a website.
Graph example
Note: Each edge’s destination node must exist as a node. If a node does not exist, the method doesn’t report it (yet).
var graph = {
north_adams: {
greenfield: 38,
pittsfield: 22,
},
pittsfield: {
north_adams: 22,
lee: 12,
},
lee: {
pittsfield: 12,
springfield: 41,
},
springfield: {
lee: 41,
northampton: 19,
worcester: 55,
},
northampton: {
springfield: 19,
greenfield: 21,
},
greenfield: {
north_adams: 38,
northampton: 21,
fitchburg: 49,
worcester: 61,
},
fitchburg: {
greenfield: 49,
worcester: 27,
},
worcester: {
fitchburg: 27,
greenfield: 61,
springfield: 55,
},
};
Algorithm.dijkstra(graph, "north_adams", "worcester");
In this example, .dijkstra will return this array: ["north_adams", "greenfield", "worcester"].