项目作者: zntfdr

项目描述 :
A path-finding library powered by GameplayKit 👾
高级语言: Swift
项目地址: git://github.com/zntfdr/Connection.git
创建时间: 2020-02-10T03:36:13Z
项目社区:https://github.com/zntfdr/Connection

开源协议:MIT License

下载


Connection




Build status


Swift Package Manager

MacOS + iOS + iPadOS + tvOS

Twitter: @zntfdr

Welcome to Connection, a Swift path-finding library. Its primary goal is to extend Apple’s GameplayKit framework.

Features

  • Weighted connections.
  • Total path weight.
  • Associated values support.
  • Find the shortest path between multiple origins and destinations.

Usage

Connection defines two new generic classes: Node and Graph, which are, respectively, GKGraphNode and GKGraph counterparts.

  1. import Connection
  2. // Create nodes.
  3. let nodeA = Node(value: "A")
  4. let nodeB = Node(value: "B")
  5. let nodeC = Node(value: "C")
  6. // Make connections.
  7. nodeA.addConnection(to: nodeB, bidirectional: false, weight: 1)
  8. nodeB.addConnection(to: nodeC, bidirectional: true, weight: 2)
  9. // Create graph.
  10. let graph = Graph([nodeA, nodeB, nodeC])
  11. // Find path.
  12. let shortestAtoCPath = graph.findPath(from: nodeA, to: nodeC)
  13. print(shortestAtoCPath) // ["A", "B", "C"]

You can find many more examples in the Tests folder.

Installation

Connection is distributed using the Swift Package Manager. To install it into a project, follow this tutorial and use this repository URL: https://github.com/zntfdr/Connection.git.

Credits

Connection was built by Federico Zanetello as a component of Bangkok Metro.

If you’d like to dive deeper into iOS path-finding algorithms, please read this two-part serie:

Contributions and Support

All users are welcome and encouraged to become active participants in the project continued development — by fixing any bug that they encounter, or by improving the documentation wherever it’s found to be lacking.

If you’d like to make a change, please open a Pull Request, even if it just contains a draft of the changes you’re planning, or a test that reproduces an issue.

Thank you and please enjoy using Connection!