Giter Site home page Giter Site logo

screeps-path's Introduction

The General's pathfinder

This is a custom pathfinder for use in Screeps. It has support for custom cost functions (see path-room-data.js), can create paths that span several rooms, and is a good deal faster than the built-in pathfinder as well. Under the hood it's using a modified version of jump point search... JPS by design only works on uniform-cost grids, but Screeps' grids are weighted (plain, swamp, and road all cause different values of fatigue) so we need to modify the original algorithm a little bit.

The code itself is fairly well documented, but you won't find any API documentation except for looking at the code yourself.

Getting started:

let path = require('path_');
let WorldPosition = path.WorldPosition;
path.find(
	WorldPosition(Game.creeps.John.pos),
	{ target: WorldPosition(Game.spawns.Spawn1.pos) }
);

This pathfinder uses a replacement for RoomPosition called WorldPosition. Instead of tracking positions by coordinates and a room name, WorldPosition unifies the entire world map into a continuous coordinate plane. This allows us to easily calculate the distance between two positions when they aren't in the same room. You can convert a RoomPosition into a WorldPosition via WorldPosition(rp) and a WorldPosition back via wp.toRoomPosition().

Returned from find is a PathInfo object which keeps around some extra data about the path, like where the roads and swamps are. See path-info.js.

The first time you create a path you will need to have access to all the rooms it touches, but after the pathfinder has seen a room it will remember its terrain and you can search for paths through rooms in which you control no creeps or structures. This data is all stashed in Memory.terrain. See TerrainData in path-room-data.js for more information about that.

You can specify multiple targets by using the targets option parameter, or try findNearest for a replacement of RoomPosition.findClosestByPath with the added bonus of returning the path to whatever it found.

screeps-path's People

Contributors

laverdet avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.