mech-pig / tic-tac-toe

Tic-tac-toe as a service

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Tic-Tac-Toe as a service

Play tic-tac-toe via API.

Quickstart

The simplest way to try the service is by using docker. In the Makefile you can find a bunch of commands to spin up the app and the required dependencies.

To start a complete environment you can execute:

make ctx-run

This command creates a postgres database using docker-compose, then it performs the required schema migrations and finally starts the http server exposing it on port 8080 by default.

You can check the OpenAPI docs at http://localhost:8080/docs.

To stop the environmen you can use:

make ctx-down

The following example requests are perfomed using httpie:

start a new game

http POST :8080/games

HTTP/1.1 201 Created
content-length: 97
content-type: application/json
date: Fri, 11 Feb 2022 12:12:35 GMT
server: uvicorn

{
    "id": "6bd0831e6e164d448630551d800e3591",
    "state": {
        "marks": {},
        "next_player": 1,
        "status": "ONGOING"
    }
}

add mark

http POST :8080/games/6bd0831e6e164d448630551d800e3591/mark player:=1 cell=BOTTOM_LEFT

HTTP/1.1 200 OK
content-length: 112
content-type: application/json
date: Fri, 11 Feb 2022 13:16:23 GMT
server: uvicorn

{
    "id": "6bd0831e6e164d448630551d800e3591",
    "state": {
        "marks": {
            "BOTTOM_LEFT": 1
        },
        "next_player": 2,
        "status": "ONGOING"
    }
}

get game

http GET :8080/games/6bd0831e6e164d448630551d800e3591

HTTP/1.1 200 OK
content-length: 112
content-type: application/json
date: Fri, 11 Feb 2022 13:17:42 GMT
server: uvicorn

{
    "id": "6bd0831e6e164d448630551d800e3591",
    "state": {
        "marks": {
            "BOTTOM_LEFT": 1
        },
        "next_player": 2,
        "status": "ONGOING"
    }
}

In the examples folder there are some scripts that simulate a complete game.

About

Tic-tac-toe as a service


Languages

Language:Python 90.1%Language:Makefile 5.1%Language:Dockerfile 2.8%Language:Nix 1.0%Language:PLpgSQL 0.9%