Crow is a collection of graph-traversal and pathfinding libraries. It includes algorithms such as breadth-first search, Dijkstra's algorithm, and A*. It can be used anywhere JavaScript is available; on the server or in the browser (though it's only been tested on the browser).
Generally speaking, you follow three steps to use Crow in your application:
For a better step-by-step, check out the [[Basic Usage]] wiki node.
See the test.html in test/ for more examples. There's even a helper that converts a 2d array of 1s and 0s into a graph.
See these examples in action by running the interactive test suite! Head down to the Testing section below for more details on starting the test server on your own box; or, visit the official one.
This example features questionable maze generation using the A* algorithm to generate a simple 16x16 maze. Also, it's more of a gridworld than an actual maze...
This example features multiple tile types (sand and grass; sand is twice as slow as grass) and both Dijkstra's Algorithm and A*.
This example demonstrates two things -- how to implement fog of war in your game (by giving nodes an attribute known
or visible
or foggy
and making it appear walkable, even if it's a wall),
and how to make a drawable maze using click events and tables.
There's two ways you can include Crow into your app -- either as a simple script tag or include with one of the automatically compiled scripts, or as a library in Google Closure.
If you run bundle install
and then bundle exec rake
(assuming you have the build-time requirements given lower down), three files will be generated for you at dist/js:
whitespace_only
. Safest, but least compression.simple_optimizations
. Renames local variables and the like, but public API is untouched. Little better compression.advanced_optimizations
. Pretty much everything gets renamed here, and because I haven't exported the public API yet, it's useless except as a demonstration of the compression unless you are also using the Google Closure compiler. Once I export the public API it should become an actual usable artifact.You can either import just the pieces you need, like goog.require('crow.Graph') and goog.require('crow.AStarAlgorithm'), or you can simply include the whole library, with goog.require('crow.All') and let the compiler figure it out.
This section outlines what you must have installed and/or present in order to use this library.
There are numerous build-time requirements, but any Linux user should already have most of them:
None! This library has no external dependencies.
In addition to the build-time dependencies, there are a couple other dependencies required to run tests (since there are server-side components):
Run rake test:runner
and then head over to localhost:4567. All will be explained when you get there.
To just generate the tests, run rake test:build
.
The tests are written using QUnit (and jQuery). Some of the tests have "circles" which are generated using Canvas. As such, to get the full experience you'll need to be using a browser with Canvas.
See http://semver.org/ (and Graph.version)
Not in effect until it hits alpha...