Include algebraic notation
This commit is contained in:
parent
677c50d007
commit
72da5d3afd
|
@ -13,6 +13,7 @@ import (
|
|||
type Board struct {
|
||||
tiles [8][8]*Piece
|
||||
turn Color
|
||||
moves []string
|
||||
}
|
||||
|
||||
func NewBoard() *Board {
|
||||
|
@ -131,6 +132,18 @@ func (b *Board) SetPiece(name PieceName, color Color, position string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (b *Board) AlgebraicNotation() string {
|
||||
var text string
|
||||
for i, m := range b.moves {
|
||||
if i%2 == 0 {
|
||||
text += fmt.Sprintf("%d. %s", i/2+1, m)
|
||||
} else {
|
||||
text += fmt.Sprintf(" %s ", m)
|
||||
}
|
||||
}
|
||||
return text
|
||||
}
|
||||
|
||||
func (b *Board) Parse(pgn string) error {
|
||||
var (
|
||||
moves = strings.Split(pgn, " ")
|
||||
|
@ -205,7 +218,7 @@ func (b *Board) Move(position string) error {
|
|||
err = fmt.Errorf("invalid move: %s", position)
|
||||
}
|
||||
} else {
|
||||
err = fmt.Errorf("invalid move: %s", position)
|
||||
return fmt.Errorf("invalid move: %s", position)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
|
@ -218,6 +231,8 @@ func (b *Board) Move(position string) error {
|
|||
b.turn = Light
|
||||
}
|
||||
|
||||
b.moves = append(b.moves, position)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
8
main.go
8
main.go
|
@ -1,6 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"strings"
|
||||
"time"
|
||||
|
@ -70,9 +71,9 @@ func tickGameStart(c *sn.Client) {
|
|||
continue
|
||||
}
|
||||
|
||||
text := fmt.Sprintf("`%s`\n\n%s", b.AlgebraicNotation(), imgUrl)
|
||||
var cId int
|
||||
parentId := n.Item.Id
|
||||
if cId, err = c.CreateComment(parentId, imgUrl); err != nil {
|
||||
if cId, err = c.CreateComment(n.Item.Id, text); err != nil {
|
||||
log.Printf("error creating reply: %v\n", err)
|
||||
continue
|
||||
}
|
||||
|
@ -158,8 +159,9 @@ func tickGameProgress(c *sn.Client) {
|
|||
continue
|
||||
}
|
||||
|
||||
text := fmt.Sprintf("`%s`\n\n%s", b.AlgebraicNotation(), imgUrl)
|
||||
var cId int
|
||||
if cId, err = c.CreateComment(n.Item.Id, imgUrl); err != nil {
|
||||
if cId, err = c.CreateComment(n.Item.Id, text); err != nil {
|
||||
log.Printf("error creating reply: %v\n", err)
|
||||
continue
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue