Thoughts On A Fluent Pathfinding API

2017-01-05
Daily
1
Find.Path.From(startingLocation).To(targetLocation)

For those not familiar with the term fluent interface, it was popularized by Martin Fowler and Eric Evans. Martin covers the description and origin of the term in his bliki post FluentInterface.

Most developers have likely encountered fluent interfaces, or written one without even konwing it. I recently stumbled upon the idea and term, while thinking about better ways to design game engine libriares. Below are some rough ideas for a fluent pathfinding api.

1
2
3
4
5
6
7
8
9
10
Find.Path.From(startingLocation).To(waypointOne).To(waypointTwo).To(waypointThree);
Find.Path.To(destination).From(origin);
Find.Path.AdjacentTo(target).From(startingPosition);
Find.Path.From(start).To(target).UsingMoveSet(characterMoves).UsingAlgorithm(aStar);
Find.Path.UsingPathableSpace(grid).From(cellA).To(cellB);
Find.AllPoints.Within(3).Moves().From(new Point(0,0)).UsingMoveSet(Chess.Knight)
Find.AllPoints.WithinSingleMove().Of(knightOne);
Find.AllPoints.Within(2).ManhattanDistance().From(position);
Find.AllPoints.Within(2).ManhattanDistance().From(position).RequireLineOfSight();
Find.AllPoints.PathableTo().From(position).UsingMoveSet(characterMoves);

Like or hate this post let me known on Twitter @josh_strunk
This post is part of the Daily series. Written daily these posts are quick to read, fast to write and designed to provide inspiration. Daily posts are not to be used as technical references or guides. They are not rigorously researched, edited, or updated.