Documentation ¶
Overview ¶
Package model contains Go Board and Game specific types
Index ¶
- func GameNames(games []Game) (names []string)
- type Board
- type Color
- type Date
- type Filter
- func (f Filter) DateMax(d Date) Filter
- func (f Filter) DateMin(d Date) Filter
- func (f Filter) HandicapMax(h Handicap) Filter
- func (f Filter) HandicapMin(h Handicap) Filter
- func (f *Filter) Matches(g *Game) bool
- func (f Filter) RankMax(r Rank) Filter
- func (f Filter) RankMin(r Rank) Filter
- func (f Filter) SizeMax(s Size) Filter
- func (f Filter) SizeMin(s Size) Filter
- type Game
- type GameSorter
- type Group
- type Groups
- type Handicap
- type Komi
- type LessGame
- type Player
- type Point
- type Points
- type Rank
- type Size
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Board ¶
type Board struct { Size int Move int Last Point KO *Point Groups Groups // id > group Members map[Point]int // point > group Stones map[Point]Color // point > color Captures struct { Black int // white stones White int // black stones } }
Board supports a straight forward Go game with capturing and KO + suicide detection
Example (EndlessPlay) ¶
b := model.NewBoard(model.Size(3)) // setup for _, a := range endlessPlaySetup { _, _ = b.Place(a.c, a.p) } fmt.Println(b) // loop for _, a := range endlessPlayLoop { _, _ = b.Place(a.c, a.p) } fmt.Println(b)
Output: +abc+ a ● | b●◯●| c◯ ◯| {3 3} w0 b0 +abc+ a ●+| b●◯●| c◯ ◯| {3 2} w4 b4
Example (Suicide) ¶
b := model.NewBoard(model.Size(4)) // setup for _, a := range []struct { c model.Color p model.Point }{ {c: B, p: P(1, 2)}, {c: B, p: P(1, 4)}, {c: B, p: P(2, 1)}, {c: B, p: P(2, 2)}, {c: B, p: P(2, 3)}, {c: B, p: P(2, 4)}, {c: W, p: P(3, 1)}, {c: W, p: P(3, 2)}, {c: W, p: P(3, 3)}, {c: W, p: P(3, 4)}, {c: W, p: P(4, 1)}, {c: W, p: P(4, 3)}, } { _, _ = b.Place(a.c, a.p) } // suicides for _, a := range []struct { c model.Color p model.Point }{ {c: B, p: P(4, 2)}, {c: B, p: P(4, 4)}, {c: W, p: P(1, 1)}, {c: W, p: P(1, 3)}, } { if r, err := b.Place(a.c, a.p); err == nil || len(r) != 0 { fmt.Println(fmt.Sprintf("suicide %s %v expected", a.c, a.p)) } } fmt.Println(b)
Output: +abcd+ a ●◯◯| b●●◯ | c ●◯◯| d●●◯ | {4 3} w0 b0
func (*Board) PlaceIGS ¶
PlaceIGS stone
Example ¶
b := model.NewBoard(model.X13) for _, a := range []struct { c model.Color i string }{ {c: B, i: "L10"}, {c: W, i: "D4"}, {c: B, i: "K3"}, {c: W, i: "D10"}, {c: B, i: "J11"}, {c: W, i: "N13"}, {c: B, i: "A13"}, {c: W, i: "A1"}, {c: B, i: "N1"}, } { _, err := b.PlaceIGS(a.c, a.i) if err != nil { panic(err) } } fmt.Println(b) _, err := b.PlaceIGS(W, "N1") fmt.Println(err)
Output: +abcdefghjklmn+ a● ◯| b | c ● | d ◯ ● | e | f | g | h | j | k ◯ | l ● | m | n◯ ●| {13 13} w0 b0 {13 13} is occupied
func (*Board) PlaceSGF ¶
PlaceSGF stone
Example ¶
b := model.NewBoard(model.X9) for _, a := range []struct { c model.Color i string }{ {c: B, i: "gd"}, {c: W, i: "df"}, {c: B, i: "gg"}, {c: W, i: "ec"}, {c: B, i: "cc"}, {c: W, i: "jj"}, {c: B, i: "aj"}, {c: W, i: "aa"}, {c: B, i: "ja"}, } { _, err := b.PlaceSGF(a.c, a.i) if err != nil { panic(err) } } fmt.Println(b) _, err := b.PlaceSGF(W, "ja") fmt.Println(err)
Output: +abcdefghj+ a◯ ●| b | c ● ◯ | d ● | e | f ◯ | g ● | h | j● ◯| {9 1} w0 b0 {9 1} is occupied
type Date ¶
Date alias time.Time with JSON date format
func (Date) After ¶
After delegates to time.Time.After
Example ¶
package main import ( "fmt" "github.com/dgf/gotv/model" ) func main() { today := model.Today() yesterday := today.Add(0, 0, -1) fmt.Printf("> %v\n", today.After(yesterday)) fmt.Printf("< %v\n", yesterday.After(today)) }
Output: > true < false
func (Date) Before ¶
Before delegates to time.Time.Before
Example ¶
package main import ( "fmt" "github.com/dgf/gotv/model" ) func main() { today := model.Today() tomorrow := today.Add(0, 0, 1) fmt.Printf("< %v\n", today.Before(tomorrow)) fmt.Printf("> %v\n", tomorrow.Before(today)) }
Output: < true > false
func (Date) MarshalJSON ¶
MarshalJSON calls String
Example ¶
package main import ( "encoding/json" "fmt" "github.com/dgf/gotv/model" ) func main() { date := model.ToDate("2017-07-23") data := map[string]model.Date{"date": date} if b, err := json.Marshal(data); err != nil { panic(err) } else { fmt.Print(string(b)) } }
Output: {"date":"2017-07-23"}
type Filter ¶
type Filter struct {
// contains filtered or unexported fields
}
Filter games between min and max values
func (Filter) HandicapMax ¶
HandicapMax filters maximum Handicap
func (Filter) HandicapMin ¶
HandicapMin filters minimum Handicap
type Game ¶
type Game struct { Date Date `json:"date"` Place string `json:"place"` Name string `json:"name"` Black Player `json:"black"` White Player `json:"white"` Size Size `json:"size"` Handicap Handicap `json:"handicap"` Komi Komi `json:"komi"` Result string `json:"result"` }
Game details
type GameSorter ¶
type GameSorter []LessGame
GameSorter sort games
func GameOrder ¶
func GameOrder(less ...LessGame) GameSorter
GameOrder returns a Sorter that sorts using the less functions, in order.
func (GameSorter) Sort ¶
func (s GameSorter) Sort(games []Game)
Sort sorts the argument slice according to the less functions passed to OrderedBy.
type LessGame ¶
LessGame partial game comparison
ByDateDesc oldest first
ByHandicap lowest first
ByHandicapDesc highest first
var ByRank LessGame = func(g1, g2 *Game) bool { return MaxRank(g1.Black, g1.White) > MaxRank(g2.Black, g2.White) }
ByRank highest first
type Points ¶
type Points []Point
Points sortable point slice
func DiffPoints ¶
DiffPoints of two point slices
Example ¶
package main import ( "fmt" "github.com/dgf/gotv/model" ) func P(x, y int) model.Point { return model.Point{X: x, Y: y} } func main() { a := model.Points{P(1, 2), P(3, 4)} b := model.Points{P(4, 3), P(1, 2)} fmt.Println(model.DiffPoints(a, b)) }
Output: [{3 4} {4 3}]
type Rank ¶
type Rank int
Rank sorted as int
const ( NR Rank = iota Kyu30 Kyu29 Kyu28 Kyu27 Kyu26 Kyu25 Kyu24 Kyu23 Kyu22 Kyu21 Kyu20 Kyu19 Kyu18 Kyu17 Kyu16 Kyu15 Kyu14 Kyu13 Kyu12 Kyu11 Kyu10 Kyu9 Kyu8 Kyu7 Kyu6 Kyu5 Kyu4 Kyu3 Kyu2 Kyu1 Dan1 Dan2 Dan3 Dan4 Dan5 Dan6 Dan7 Dan8 Dan9 Pro1 Pro2 Pro3 Pro4 Pro5 Pro6 Pro7 Pro8 Pro9 )
rank constants NR = 0, 30 Kyu = 1, ...
func ToRank ¶
ToRank decodes rank
Example ¶
package main import ( "fmt" "github.com/dgf/gotv/model" ) func main() { fmt.Printf("%s\n", model.ToRank("unknown")) fmt.Printf("%s\n", model.ToRank("5 Kyu")) fmt.Printf("%s\n", model.ToRank("4 Dan")) fmt.Printf("%s\n", model.ToRank("3 Pro")) fmt.Printf("%s\n", model.ToRank("10 Pro")) }
Output: NR 5 Kyu 4 Dan 3 Pro NR