diff --git a/game.go b/game.go index 777b39e..7fa5ec9 100644 --- a/game.go +++ b/game.go @@ -252,12 +252,11 @@ func (g *Game) combat(atk, def *Piece) (int, error) { if atk == nil || def == nil { return 0, errors.New("invalid attacker or defender") } - if atk.Hidden { - return 0, errors.New("trying to attack with a piece we know nothing about?") - } - if def.Hidden { + if def.Hidden && def.Rank == Unknown { return 0, errors.New("defender has not been revealed to us") } + //reveal attacker + atk.Hidden = false //handle special cases first //miner hitting bomb if atk.Rank == Miner && def.Rank == Bomb { diff --git a/piece.go b/piece.go index 80f8a65..e571f26 100644 --- a/piece.go +++ b/piece.go @@ -14,6 +14,7 @@ const ( General Marshal Bomb + Unknown ) //Piece :game piece @@ -36,15 +37,16 @@ func NewPieceFromInt(r int, o Colour) *Piece { func NewPiece(r Rank, o Colour) *Piece { return &Piece{ Rank: r, - Owner: o, - Hidden: false, - } -} - -//NewHiddenPiece creates a new hidden piece -func NewHiddenPiece(o Colour) *Piece { - return &Piece{ Owner: o, Hidden: true, } } + +//NewUnknownPiece creates a new hidden piece +func NewUnknownPiece(o Colour) *Piece { + return &Piece{ + Owner: o, + Rank: Unknown, + Hidden: true, + } +} diff --git a/rank_enumer.go b/rank_enumer.go index da53b83..6acd9b9 100644 --- a/rank_enumer.go +++ b/rank_enumer.go @@ -7,9 +7,9 @@ import ( "fmt" ) -const _RankName = "FlagSpyScoutMinerCaptainGeneralMarshalBomb" +const _RankName = "FlagSpyScoutMinerCaptainGeneralMarshalBombUnknown" -var _RankIndex = [...]uint8{0, 4, 7, 12, 17, 24, 31, 38, 42} +var _RankIndex = [...]uint8{0, 4, 7, 12, 17, 24, 31, 38, 42, 49} func (i Rank) String() string { if i < 0 || i >= Rank(len(_RankIndex)-1) { @@ -18,7 +18,7 @@ func (i Rank) String() string { return _RankName[_RankIndex[i]:_RankIndex[i+1]] } -var _RankValues = []Rank{0, 1, 2, 3, 4, 5, 6, 7} +var _RankValues = []Rank{0, 1, 2, 3, 4, 5, 6, 7, 8} var _RankNameToValueMap = map[string]Rank{ _RankName[0:4]: 0, @@ -29,6 +29,7 @@ var _RankNameToValueMap = map[string]Rank{ _RankName[24:31]: 5, _RankName[31:38]: 6, _RankName[38:42]: 7, + _RankName[42:49]: 8, } // RankString retrieves an enum value from the enum constants string name.