-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from ivan1993spb/dev
Update 4/19/2024
- Loading branch information
Showing
79 changed files
with
5,219 additions
and
915 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,35 +5,38 @@ on: push | |
jobs: | ||
|
||
build: | ||
runs-on: ubuntu-18.04 | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: 1.19.5 | ||
go-version: 1.21.5 | ||
|
||
- name: Go Mod | ||
run: go mod download | ||
|
||
# TODO: Add Go format step. | ||
#- name: Go Format | ||
# run: gofmt -s -w . && git diff --exit-code | ||
- name: Go Format | ||
run: gofmt -s -w . && git diff --exit-code | ||
|
||
- name: Go Tidy | ||
run: go mod tidy && git diff --exit-code | ||
|
||
# TODO: Add a propper vetting step go vet ./... | ||
- name: Go Vet | ||
run: go vet | ||
|
||
# TODO: Add a staticcheck step. | ||
#- uses: dominikh/[email protected] | ||
# with: | ||
# version: "2022.1" | ||
# install-go: false | ||
- name: golangci-lint | ||
uses: golangci/golangci-lint-action@v3 | ||
with: | ||
version: v1.55.2 | ||
|
||
# TODO: add go lint | ||
- name: Go staticcheck | ||
uses: dominikh/[email protected] | ||
with: | ||
version: "2023.1" | ||
install-go: false | ||
|
||
- name: Go Build | ||
run: go build -v ./... | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
on: push | ||
name: Validate OpenAPI specification | ||
jobs: | ||
validate: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: swagger-validator | ||
uses: mbowman100/swagger-validator-action@master | ||
with: | ||
files: api/openapi.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,13 @@ | ||
/snake-bot | ||
/*.html | ||
*.yaml | ||
*.json | ||
*.base64 | ||
*.jwt | ||
*.diff | ||
*.patch | ||
*.log | ||
*.test | ||
*.out | ||
*.svg | ||
!examples/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,59 @@ | ||
|
||
# The snake bot | ||
# Snake-Bot | ||
|
||
- **MVP** | ||
- clumsy | ||
- copypasta | ||
- no comments | ||
- no tests | ||
- bugs | ||
### Install Snake-Bot | ||
|
||
``` | ||
curl -X POST -H 'X-Snake-Bot-Token: hOayYn7Jbbq1TwDzJTsKX_eDb8Ww7LFEu0l6egnViGtCBCNbAPHo00b1uVCly9Rd' localhost:8080/config | ||
go install github.com/ivan1993spb/snake-bot@latest | ||
``` | ||
|
||
https://en.wikipedia.org/wiki/Dijkstra%27s_algorithm | ||
### Start Snake-Server | ||
|
||
``` | ||
docker run --rm -d -p 8080:8080 ivan1993spb/snake-server:latest --enable-web | ||
# Create a game | ||
curl -X POST -d limit=15 -d width=100 -d height=60 -d enable_walls=true localhost:8080/api/games | ||
``` | ||
|
||
### Start Snake-Bot | ||
|
||
``` | ||
# Generate a secret for JWT | ||
openssl rand -base64 -out secret.base64 32 | ||
snake-bot -snake-server localhost:8080 -jwt-secret secret.base64 -address :9090 | ||
``` | ||
|
||
### Generate JWT | ||
|
||
``` | ||
python3 scripts/getjwt.py --subject admin --jwt-secret secret.base64 > token.jwt | ||
token=`cat token.jwt` | ||
header="Authorization: Bearer ${token}" | ||
``` | ||
|
||
### Call the API | ||
|
||
``` | ||
# Get config | ||
curl -X GET -H "$header" localhost:9090/api/bots | ||
# Add 1 bot in game 1 | ||
curl -X POST -H "$header" -d game=1 -d bots=1 localhost:9090/api/bots | ||
cd examples | ||
curl -X POST -H "$header" --data-binary @bots.yaml -H 'Content-Type: text/yaml' localhost:9090/api/bots | ||
curl -X POST -H "$header" --data-binary @bots.json -H 'Content-Type: application/json' localhost:9090/api/bots | ||
``` | ||
|
||
### Watch the result | ||
|
||
[![Demo](demo.gif)](http://localhost:8080) | ||
|
||
### How it works | ||
|
||
[wiki: Dijkstra's algorithm](https://en.wikipedia.org/wiki/Dijkstra%27s_algorithm) | ||
|
||
### License | ||
|
||
See [LICENSE](LICENSE). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.