https://github.com/jasonnam/connection
A path-finding library powered by GameplayKit 👾
https://github.com/jasonnam/connection
gameplaykit ios macos package path-finding pathfinding pathfinding-algorithm spm swift
Last synced: 5 months ago
JSON representation
A path-finding library powered by GameplayKit 👾
- Host: GitHub
- URL: https://github.com/jasonnam/connection
- Owner: jasonnam
- License: mit
- Created: 2020-02-10T03:36:13.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2021-01-18T14:02:42.000Z (over 4 years ago)
- Last Synced: 2024-04-23T10:26:50.413Z (12 months ago)
- Topics: gameplaykit, ios, macos, package, path-finding, pathfinding, pathfinding-algorithm, spm, swift
- Language: Swift
- Size: 37.1 KB
- Stars: 75
- Watchers: 2
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Connection
Welcome to **Connection**, a Swift path-finding library. Its primary goal is to extend Apple's [`GameplayKit`](https://developer.apple.com/documentation/gameplaykit) framework.
## Features
- [x] Weighted connections.
- [x] Total path weight.
- [x] Associated values support.
- [x] Find the shortest path between multiple origins and destinations.## Usage
Connection defines two new generic classes: `Node` and `Graph`, which are, respectively, [`GKGraphNode`](https://developer.apple.com/documentation/gameplaykit/gkgraphnode) and [`GKGraph`](https://developer.apple.com/documentation/gameplaykit/gkgraph) counterparts.```swift
import Connection// Create nodes.
let nodeA = Node(value: "A")
let nodeB = Node(value: "B")
let nodeC = Node(value: "C")// Make connections.
nodeA.addConnection(to: nodeB, bidirectional: false, weight: 1)
nodeB.addConnection(to: nodeC, bidirectional: true, weight: 2)// Create graph.
let graph = Graph([nodeA, nodeB, nodeC])// Find path.
let shortestAtoCPath = graph.findPath(from: nodeA, to: nodeC)print(shortestAtoCPath) // ["A", "B", "C"]
```
You can find many more examples in the [`Tests`](https://github.com/zntfdr/Connection/tree/master/Tests) folder.## Installation
Connection is distributed using the [Swift Package Manager](https://swift.org/package-manager). To install it into a project, follow [this tutorial](https://developer.apple.com/documentation/swift_packages/adding_package_dependencies_to_your_app) and use this repository URL: `https://github.com/zntfdr/Connection.git`.
## Credits
Connection was built by [Federico Zanetello](https://twitter.com/zntfdr) as a component of [Bangkok Metro](http://yourmetro.app).
If you'd like to dive deeper into iOS path-finding algorithms, please read this two-part serie:
- [Dijkstra’s Algorithm In Swift](https://www.fivestars.blog/code/dijkstra-algorithm-swift.html#swift-time)
- [The Right Way To Write Dijkstra’s Algorithm In Swift 👾](https://www.fivestars.blog/code/dijkstra-algorithm-swift-2.html)## 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](https://github.com/zntfdr/Connection/pull/new), 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**!