You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.2 KiB
50 lines
1.2 KiB
/* |
|
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" |
|
"math/rand" |
|
|
|
"git.nightmare.haus/rudi/chessv2" |
|
) |
|
|
|
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
|
|
|