Tournament Calculator is a simple utility that can be used to predict results of matches between players in a game. Currently, it is configured to generate possible outcomes between professional Starcraft II players using publicly available data from the Team Liquid wiki and Aligulac's player performance database.
This repository includes both a server and a client (in this case, a driver script). The server uses gin-gonic
for api routing and Gorm
for data persistence in a local SQLite
database file.
- Clone this repository and
cd
into the root directory go build -o server ./server; go build -o client ./client;
- Ensure you have a
.env
file in your project root with format mirroring that ofsample.env
- Server port can be anything that works for your system;
gin-gonic
's standard port is8080
. - Generate an API key for Aligulac queries from Aligulac's API docs if you don't already have one
- Server port can be anything that works for your system;
You'll need two terminal tabs running, one for the server and the other for the client. The server will create a tournament.db
file and seed it with GameMap
and Player
data the first time that it's run.
- After building the
server
andclient
executables, from the repository root run:./server/server
to start the database server running in the background./client/client
to perform a randomized match calculation using two players from Aligulac's top 50go test -v -bench=. ./...
to run all table and bench tests
The URL root for the server will be localhost:PORT
where PORT
is specified in your .env
file. The default port for Gin is 8080
.
GET
/ping
- returns apong
message to ensure that the server responding
GET
/api/v1/player
- retrieves a list of allplayer
sGET
/api/v1/player/:id
- retrieves a specificplayer
by idPOST
/api/v1/player
- creates aplayer
object according to the shape of thePlayer
struct, which has aRating
struct nested inside:
type Player struct {
Base
Tag string `json:"tag" gorm:"type:varchar(15)"`
Race string `json:"race" gorm:"type:varchar(1)"`
Rating Rating `json:"current_rating" gorm:"embedded;embeddedPrefix:rating_"`
}
type Rating struct {
CurrentRating float32 `json:"rating" gorm:"column:rating_rating"`
VsProtoss float32 `json:"tot_vp" gorm:"column:rating_vs_protoss"`
VsTerran float32 `json:"tot_vt" gorm:"column:rating_vs_terran"`
VsZerg float32 `json:"tot_vz" gorm:"column:rating_vs_zerg"`
}
type Base struct {
ID uint `json:"id" gorm:"primaryKey"`
CreatedAt time.Time `json:"created_at" gorm:"type:datetime"`
UpdatedAt time.Time `json:"updated_at" gorm:"type:datetime"`
}
GET
/api/v1/gameMap
- retrieves a list of allgameMap
sGET
/api/v1/gameMap/:id
- retrieves a specificgameMap
by idPOST
/api/v1/gameMap
- creates agameMap
object according to the shape of theGameMap
struct:
type GameMap struct {
Base
Name string `json:"name" gorm:"type:varchar(100)"`
Height uint8 `json:"height" gorm:"type:uint"`
Width uint8 `json:"width" gorm:"type:uint"`
RushDistance uint8 `json:"rush_distance" gorm:"type:uint"`
TvZ float32 `json:"tvz" gorm:"type:float"`
ZvP float32 `json:"zvp" gorm:"type:float"`
PvT float32 `json:"pvt" gorm:"type:float"`
}
GET
/api/v1/match
- retrieves a list of allmatch
sGET
/api/v1/match/:id
- retrieves a specificmatch
by idPOST
/api/v1/match
- creates amatch
object according to the shape of theMatch
struct:
type Match struct {
Base
Player1ID uint `json:"player1_id"`
Player1 Player `json:"player1" gorm:"foreignKey:Player1ID"`
Player2ID uint `json:"player2_id"`
Player2 Player `json:"player2" gorm:"foreignKey:Player2ID"`
}
GET
/api/v1/result
- retrieves a list of allresult
sGET
/api/v1/result/:id
- retrieves a specificresult
by idPOST
/api/v1/result
- creates aresult
object according to the shape of theResult
struct:
type Result struct {
Base
MatchID uint `json:"match_id"`
WinnerID uint `json:"winner_id"`
Winner Player `json:"winner" gorm:"foreignKey:WinnerID"`
WinnerPercentage float32 `json:"winner_percentage"`
LoserID uint `json:"loser_id"`
Loser Player `json:"loser" gorm:"foreignKey:LoserID"`
}
\tournament-calculator
|--\client
|----client.go
|----client
|--\helpers
|----helpers.go
|----map_pool.go
|----helpers_test.go
|--\models
|----models.go
|--\server
|----\db
|------handler.go
|------tournament.db
|----\handlers
|------map_handlers.go
|------match_handlers.go
|------ping_handlers.go
|------player_handlers.go
|------result_handlers.go
|----\routes
|------routes.go
|----server.go
|----server
|--\utils
|----matchmaker.go
|----simulation.go
|----simulation_test.go
|--.env
|--.gitignore
|--go.mod
|--go.sum
|--proposal.md
|--README.md
|--sample.env