Skip to content

Commit

Permalink
Merge pull request #125 from sbodenstein:swift_build_doc_improve
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 285902182
Change-Id: I08c775e4fa435663e45aaa25b86e7a201dbc2da6
  • Loading branch information
open_spiel@google.com authored and open_spiel@google.com committed Dec 17, 2019
2 parents 4ae841e + 05c7298 commit 376c2cd
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions docs/swift.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,53 @@ swift build # builds the OpenSpiel library
swift test # runs all unit tests
```

A simple example of using the OpenSpiel package:
```
import OpenSpiel
let game = TicTacToe()
var state = game.initialState
state.apply(TicTacToe.Action(x: 1, y: 1))
print(state)
```

## Using XCode

To use OpenSpiel as a dependency for an XCode project, you need to use the [Swift Package Manager](https://swift.org/package-manager/) and use it to generate an XCode project. Create an executable package called `foo`:
```
mkdir foo
cd foo
swift package init --type executable
```
Now open the file `Package.swift` that was generated, and add OpenSpiel as a dependency. The contents are now:
```
// swift-tools-version:5.1
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "foo",
dependencies: [
.package(url: "https://github.com/deepmind/open_spiel.git", .branch("master")),
],
targets: [
.target(
name: "foo",
dependencies: ["OpenSpiel"]),
.testTarget(
name: "fooTests",
dependencies: ["foo"]),
]
)
```
An XCode project can be generated from this package:
```
swift package generate-xcodeproj
open foo.xcodeproj
```
Set the build system to the Legacy Build System (File → Project Settings → Build System) required by [Swift for Tensorflow](https://github.com/tensorflow/swift/blob/master/Installation.md#installation), and you are ready to build using XCode.

## A tour through the code

* `Spiel.swift` contains the primary abstractions common to all games, such as
Expand Down

0 comments on commit 376c2cd

Please sign in to comment.