forked from lukemilby/lichess
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboard.go
79 lines (71 loc) · 1.72 KB
/
board.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
67
68
69
70
71
72
73
74
75
76
77
78
79
package lichess
import (
"fmt"
)
type Board struct {
GameId string
}
type BoardGameState struct {
Type string `json:"type"`
Id string `json:"id"`
Rated bool `json:"rated"`
Clock struct {
Initial int `json:"initial"`
Increment int `json:"Increment"`
}
Speed string `json:"speed"`
Perf struct {
Name string `json:"name"`
}
CreatedAt int `json:"createdAt"`
White struct {
Id string `json:"id"`
Name string `json:"name"`
Provisional bool `json:"provisional"`
Rating int `json:"rating"`
Title string `json:"title"`
}
Black struct {
Id string `json:"id"`
Name string `json:"name"`
Rating int `json:"rating"`
Title string `json:"title"`
}
InitialFen string `json:"initialFen"`
State struct {
Type string `json:"type"`
WTime int `json:"wtime"`
BTime int `json:"btime"`
Status string `json:"status"`
Winner string `json:"winner"`
}
Moves string `json:"moves"`
WTime int `json:"wtime"`
BTime int `json:"btime"`
Status string `json:"status"`
Winner string `json:"winner"`
}
func (c *Client) GetBoardGameState(game_id string) (*BoardGameState, error) {
boardGameState := new(BoardGameState)
req, err := c.newRequest("GET", fmt.Sprintf("/api/board/game/stream/%s", game_id), nil)
if err != nil {
return nil, err
}
_, err = c.do(req, &boardGameState)
if err != nil {
return nil, err
}
return boardGameState, err
}
func (c *Client) MakeBoardMove(board_id string, move string) (*Ok, error) {
ok := new(Ok)
req, err := c.newRequest("POST", fmt.Sprintf("/api/board/game/%s/move/%s", board_id, move), nil)
if err != nil {
return nil, err
}
_, err = c.do(req, &ok)
if err != nil {
return nil, err
}
return ok, err
}