-
Notifications
You must be signed in to change notification settings - Fork 0
/
start.go
66 lines (59 loc) · 1.44 KB
/
start.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package handlers
import (
"encoding/json"
"net/http"
"github.com/redestro/zeronet/server/pkg/sessions"
)
type response struct {
Token string `json:"token"`
Moves [9]int `json:"moves"`
Board [9]string `json:"board"`
}
// StartHuman starts session for human player vs AI
func StartHuman(w http.ResponseWriter, r *http.Request) {
db := sessions.GetDB()
session := sessions.Create(db, "human")
response := response{
session.Token,
session.Moves,
session.Board,
}
res, _ := json.Marshal(response)
w.Write([]byte(res))
}
// StartAI starts session for AI vs AI
func StartAI(w http.ResponseWriter, r *http.Request) {
db := sessions.GetDB()
session := sessions.Create(db, "ai")
response := response{
session.Token,
session.Moves,
session.Board,
}
res, _ := json.Marshal(response)
w.Write([]byte(res))
}
// StartRevHuman starts session for AI vs human player
func StartRevHuman(w http.ResponseWriter, r *http.Request) {
db := sessions.GetDB()
session := sessions.Create(db, "humanRev")
response := response{
session.Token,
session.Moves,
session.Board,
}
res, _ := json.Marshal(response)
w.Write([]byte(res))
}
// StartHuman2 starts session for human player vs human player
func StartHuman2(w http.ResponseWriter, r *http.Request) {
db := sessions.GetDB()
session := sessions.Create(db, "human2")
response := response{
session.Token,
session.Moves,
session.Board,
}
res, _ := json.Marshal(response)
w.Write([]byte(res))
}