add piece ranks
This commit is contained in:
parent
719b7626c9
commit
7fd0bfb1c6
16
piece.go
16
piece.go
@ -1,13 +1,19 @@
|
||||
package main
|
||||
|
||||
import "strconv"
|
||||
|
||||
//Rank represents the rank of a piece
|
||||
//go:generate enumer -type=Rank
|
||||
type Rank int
|
||||
|
||||
func (r Rank) String() string {
|
||||
return strconv.Itoa(int(r))
|
||||
}
|
||||
//Rank rank pieces
|
||||
const (
|
||||
Flag Rank = iota
|
||||
Spy
|
||||
Scout
|
||||
Miner
|
||||
Captain
|
||||
General
|
||||
Marshal
|
||||
)
|
||||
|
||||
//Piece :game piece
|
||||
type Piece struct {
|
||||
|
55
rank_enumer.go
Normal file
55
rank_enumer.go
Normal file
@ -0,0 +1,55 @@
|
||||
// Code generated by "enumer -type=Rank"; DO NOT EDIT.
|
||||
|
||||
//
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
const _RankName = "FlagSpyScoutMinerCaptainGeneralMarshal"
|
||||
|
||||
var _RankIndex = [...]uint8{0, 4, 7, 12, 17, 24, 31, 38}
|
||||
|
||||
func (i Rank) String() string {
|
||||
if i < 0 || i >= Rank(len(_RankIndex)-1) {
|
||||
return fmt.Sprintf("Rank(%d)", i)
|
||||
}
|
||||
return _RankName[_RankIndex[i]:_RankIndex[i+1]]
|
||||
}
|
||||
|
||||
var _RankValues = []Rank{0, 1, 2, 3, 4, 5, 6}
|
||||
|
||||
var _RankNameToValueMap = map[string]Rank{
|
||||
_RankName[0:4]: 0,
|
||||
_RankName[4:7]: 1,
|
||||
_RankName[7:12]: 2,
|
||||
_RankName[12:17]: 3,
|
||||
_RankName[17:24]: 4,
|
||||
_RankName[24:31]: 5,
|
||||
_RankName[31:38]: 6,
|
||||
}
|
||||
|
||||
// RankString retrieves an enum value from the enum constants string name.
|
||||
// Throws an error if the param is not part of the enum.
|
||||
func RankString(s string) (Rank, error) {
|
||||
if val, ok := _RankNameToValueMap[s]; ok {
|
||||
return val, nil
|
||||
}
|
||||
return 0, fmt.Errorf("%s does not belong to Rank values", s)
|
||||
}
|
||||
|
||||
// RankValues returns all values of the enum
|
||||
func RankValues() []Rank {
|
||||
return _RankValues
|
||||
}
|
||||
|
||||
// IsARank returns "true" if the value is listed in the enum definition. "false" otherwise
|
||||
func (i Rank) IsARank() bool {
|
||||
for _, v := range _RankValues {
|
||||
if i == v {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
Loading…
Reference in New Issue
Block a user