better hidden logic

This commit is contained in:
stryan 2022-03-07 16:09:42 -05:00
parent a332444817
commit 38a4163410
3 changed files with 17 additions and 15 deletions

View File

@ -252,12 +252,11 @@ func (g *Game) combat(atk, def *Piece) (int, error) {
if atk == nil || def == nil { if atk == nil || def == nil {
return 0, errors.New("invalid attacker or defender") return 0, errors.New("invalid attacker or defender")
} }
if atk.Hidden { if def.Hidden && def.Rank == Unknown {
return 0, errors.New("trying to attack with a piece we know nothing about?")
}
if def.Hidden {
return 0, errors.New("defender has not been revealed to us") return 0, errors.New("defender has not been revealed to us")
} }
//reveal attacker
atk.Hidden = false
//handle special cases first //handle special cases first
//miner hitting bomb //miner hitting bomb
if atk.Rank == Miner && def.Rank == Bomb { if atk.Rank == Miner && def.Rank == Bomb {

View File

@ -14,6 +14,7 @@ const (
General General
Marshal Marshal
Bomb Bomb
Unknown
) )
//Piece :game piece //Piece :game piece
@ -36,15 +37,16 @@ func NewPieceFromInt(r int, o Colour) *Piece {
func NewPiece(r Rank, o Colour) *Piece { func NewPiece(r Rank, o Colour) *Piece {
return &Piece{ return &Piece{
Rank: r, Rank: r,
Owner: o,
Hidden: false,
}
}
//NewHiddenPiece creates a new hidden piece
func NewHiddenPiece(o Colour) *Piece {
return &Piece{
Owner: o, Owner: o,
Hidden: true, Hidden: true,
} }
} }
//NewUnknownPiece creates a new hidden piece
func NewUnknownPiece(o Colour) *Piece {
return &Piece{
Owner: o,
Rank: Unknown,
Hidden: true,
}
}

View File

@ -7,9 +7,9 @@ import (
"fmt" "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 { func (i Rank) String() string {
if i < 0 || i >= Rank(len(_RankIndex)-1) { if i < 0 || i >= Rank(len(_RankIndex)-1) {
@ -18,7 +18,7 @@ func (i Rank) String() string {
return _RankName[_RankIndex[i]:_RankIndex[i+1]] 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{ var _RankNameToValueMap = map[string]Rank{
_RankName[0:4]: 0, _RankName[0:4]: 0,
@ -29,6 +29,7 @@ var _RankNameToValueMap = map[string]Rank{
_RankName[24:31]: 5, _RankName[24:31]: 5,
_RankName[31:38]: 6, _RankName[31:38]: 6,
_RankName[38:42]: 7, _RankName[38:42]: 7,
_RankName[42:49]: 8,
} }
// RankString retrieves an enum value from the enum constants string name. // RankString retrieves an enum value from the enum constants string name.