Commit 3fbcacbe authored by ceddral's avatar ceddral
Browse files

board: define type for field types

parent ec56470b
......@@ -17,27 +17,37 @@ const (
)
// 'constants'
var (
typeBG map[byte]tg.Color
typeFG map[byte]tg.Color
typeBG map[FType]tg.Color
typeFG map[FType]tg.Color
)
func InitBoard() {
// I miss c++ constexpr
typeBG = make(map[byte]tg.Color)
typeFG = make(map[byte]tg.Color)
typeBG['m'] = tg.ColorRed
typeBG['b'] = tg.ColorGreen
typeBG['w'] = tg.ColorGreen
typeBG['r'] = tg.ColorYellow
typeFG['m'] = tg.ColorBlack
typeFG['b'] = tg.ColorBlack
typeFG['w'] = tg.ColorWhite
typeFG['r'] = tg.ColorBlack
typeBG = make(map[FType]tg.Color)
typeFG = make(map[FType]tg.Color)
typeBG[fCloister] = tg.ColorRed
typeBG[fFarm] = tg.ColorGreen
typeBG[fRoad] = tg.ColorGreen
typeBG[fCity] = tg.ColorYellow
typeFG[fCloister] = tg.ColorBlack
typeFG[fFarm] = tg.ColorBlack
typeFG[fRoad] = tg.ColorWhite
typeFG[fCity] = tg.ColorBlack
}
type FType byte
const (
fRoad FType = 'w'
fCity FType = 'r'
fCloister FType = 'm'
fFarm FType = 'b'
fTower FType = 't'
)
type Field struct {
preRendered []byte
t byte
t FType
id byte
fgOverride tg.Color
c byte
......@@ -46,7 +56,7 @@ type Field struct {
type Piece struct {
f [][][]Field // 'graphic' representation [rotation][row][col]
fieldIdToType map[byte]byte
fieldIdToType map[byte]FType
copies int
}
......@@ -504,11 +514,11 @@ func readpieces(filename string) (pieces []Piece, err error) {
}
}
row = 0
curPiece.fieldIdToType = make(map[byte]byte)
curPiece.fieldIdToType = make(map[byte]FType)
meta := strings.Split(s.Text(), " ")
curPiece.fieldIdToType['X'] = 'b'
curPiece.fieldIdToType['X'] = fFarm
for i, c := range []byte(meta[0]) {
curPiece.fieldIdToType[byte(i) + '0'] = c
curPiece.fieldIdToType[byte(i) + '0'] = FType(c)
}
curPiece.copies, err = strconv.Atoi(meta[1])
if err != nil {
......
......@@ -134,15 +134,15 @@ func toToken(b byte) Token {
return tNone
}
func (t Token) placeable(fType byte) bool {
func (t Token) placeable(fType FType) bool {
switch (t) {
case tFollower: return true
case tBigFollower: return true
case tMayor: return fType == 'r' || fType == 't'
case tWagon: return fType != 'b' || fType == 't'
case tBuilder: return fType == 'r' || fType == 'w'
case tPig: return fType == 'b'
case tTower: return fType == 't'
case tMayor: return fType == fCity || fType == fTower
case tWagon: return fType != fFarm || fType == fTower
case tBuilder: return fType == fCity || fType == fRoad
case tPig: return fType == fFarm
case tTower: return fType == fTower
default: panic("unexpected token can not be converted to byte representation")
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment