-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathliad.go
106 lines (89 loc) · 2.35 KB
/
liad.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package main
import (
"fmt"
"os"
"strings"
"github.com/dechristopher/octad"
)
func main() {
fmt.Print("\033[H\033[2J")
for {
var err error
var game *octad.Game
var position, tm, rights, enp, hm, m string
fmt.Println("\nLi(bre oct)ad Test Harness v0.0.1")
fmt.Printf("Enter OFEN or press enter for new game:")
_, err = fmt.Scanf("%s %s %s %s %s %s",
&position, &tm, &rights, &enp, &hm, &m)
if err != nil {
game, err = octad.NewGame()
} else {
ofen := fmt.Sprintf("%s %s %s %s %s %s",
position, tm, rights, enp, hm, m)
ofen = strings.TrimSpace(ofen)
parsedOFEN, err := octad.OFEN(ofen)
if err != nil {
fmt.Println(err.Error())
continue
}
game, err = octad.NewGame(parsedOFEN)
}
if err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
fmt.Print("\033[H\033[2J")
for game.Outcome() == octad.NoOutcome {
fmt.Print("\033[H\033[2J")
fmt.Println(game.OFEN())
if len(game.Moves()) > 0 {
fmt.Printf("last move: %s", game.Moves()[len(game.Moves())-1].String())
if game.Position().EnPassantSquare() != octad.NoSquare {
fmt.Printf(", enp: %s", game.Position().EnPassantSquare().String())
}
if game.Position().InCheck() {
fmt.Printf(", in check at %s", game.Position().CheckSquare())
}
}
fmt.Println(game.Position().Board().Draw())
// Print all legal moves
for _, move := range game.ValidMoves() {
fmt.Print(move.String() + " ")
}
var move string
fmt.Printf("\nEnter move for %s: ", game.Position().Turn().String())
_, err := fmt.Scanln(&move)
if err != nil {
continue
}
if move == "-" {
break
} else if move == "u" {
game.UndoMove()
} else {
err = game.MoveStr(move)
}
if err != nil {
fmt.Println(err.Error())
}
}
fmt.Println(game.Position().Board().Draw())
fmt.Printf("Game completed. %s by %s.\n", game.Outcome(), game.Method())
fmt.Println(game.String())
//// create file
//f, err := os.Create("test.svg")
//if err != nil {
// log.Fatal(err)
//}
//defer f.Close()
//
//// write board SVG to file
//blue := color.RGBA{R: 0, G: 64, B: 255, A: 1}
//mark := image.MarkSquares(blue, octad.C1, octad.C2)
//if err := image.SVG(f, game.Position().Board(), mark); err != nil {
// log.Fatal(err)
//}
}
}
// Illegal move example:
//"b1b2","d4c2","d1c2","b4b3","a1b3","c4a4","c2c3","b4c3"