forked from Tilps/chess
-
Notifications
You must be signed in to change notification settings - Fork 0
/
doc.go
49 lines (41 loc) · 1.17 KB
/
doc.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
/*
Package chess is a go library designed to accomplish the following:
- chess game / turn management
- move validation
- PGN encoding / decoding
- FEN encoding / decoding
Using Moves
game := chess.NewGame()
moves := game.ValidMoves()
game.Move(moves[0])
Using Algebraic Notation
game := chess.NewGame()
game.MoveStr("e4")
Using PGN
pgn, _ := chess.PGN(pgnReader)
game := chess.NewGame(pgn)
Using FEN
fen, _ := chess.FEN("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1")
game := chess.NewGame(fen)
Random Game
package main
import (
"fmt"
"github.com/notnil/chess"
)
func main() {
game := chess.NewGame()
// generate moves until game is over
for game.Outcome() == chess.NoOutcome {
// select a random move
moves := game.ValidMoves()
move := moves[rand.Intn(len(moves))]
game.Move(move)
}
// print outcome and game PGN
fmt.Println(game.Position().Board().Draw())
fmt.Printf("Game completed. %s by %s.\n", game.Outcome(), game.Method())
fmt.Println(game.String())
}
*/
package chess