-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpiece.go
51 lines (44 loc) · 1.04 KB
/
piece.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
package chess
// Piece represents a chess Piece. It can be initialized or not.
//
// If not initialized, both Color and Kind will be of type
// none (Color_None, Kind_None)
type Piece struct {
Color Color
Kind Kind
Square Square
}
func newPiece(color Color, kind Kind, pos Square) Piece {
return Piece{
Color: color,
Kind: kind,
Square: pos,
}
}
func (p Piece) clone() Piece {
return newPiece(p.Color, p.Kind, newSquare(p.Square.I, p.Square.J))
}
// Rune returns the rune of the piece.
//
// Examples:
// A black pawn // returns 'p'
// A white king // returns 'K'
func (p Piece) Rune() rune {
return p.Kind.RuneWithColor(p.Color)
}
// Unicode returns the unicode rune of the piece.
//
// Examples:
// A black pawn // returns '♟'
// A white king // returns '♕'
func (p Piece) Unicode() rune {
return p.Kind.UnicodeWithColor(p.Color)
}
// String returns the color and name of the piece.
//
// Examples:
// "white knight"
// "black bishop"
func (p Piece) String() string {
return p.Color.String() + " " + p.Kind.String()
}