diff options
Diffstat (limited to 'go')
| -rw-r--r-- | go/game/playerControl_test.go | 25 | ||||
| -rw-r--r-- | go/game/state.go | 16 | ||||
| -rw-r--r-- | go/game/state_test.go | 22 |
3 files changed, 61 insertions, 2 deletions
diff --git a/go/game/playerControl_test.go b/go/game/playerControl_test.go index 34f20c59..0182e30b 100644 --- a/go/game/playerControl_test.go +++ b/go/game/playerControl_test.go @@ -4,6 +4,31 @@ import ( "testing" ) +type MockPlayerControl struct { + p *Player + sentNotifications []PlayerNotification +} + +func newMockPlayerControl(p *Player) PlayerControl { + return &MockPlayerControl{p: p} +} + +func (ctrl *MockPlayerControl) Close() {} +func (ctrl *MockPlayerControl) Player() *Player { return ctrl.p } +func (ctrl *MockPlayerControl) RecvNotification() (n PlayerNotification, err error) { + return +} + +func (ctrl *MockPlayerControl) SendNotification(n PlayerNotification) error { + ctrl.sentNotifications = append(ctrl.sentNotifications, n) + return nil +} + +func (ctrl *MockPlayerControl) RecvAction() (Action, error) { + return nil, nil +} +func (ctrl *MockPlayerControl) SendAction(Action) error { return nil } + const PRORITY_STRING = "!priority{}" func TestMarshalPriority(t *testing.T) { diff --git a/go/game/state.go b/go/game/state.go index f6bcbc8e..b72da192 100644 --- a/go/game/state.go +++ b/go/game/state.go @@ -458,6 +458,14 @@ func (s *LocalState) pushAction(a Action) { s.stack.push(a) } +type ErrDeclareSlowAction struct { + reason string +} + +func (err ErrDeclareSlowAction) Error() string { + return err.reason +} + func (s *LocalState) declareAction(a Action) { var err error @@ -471,8 +479,12 @@ func (s *LocalState) declareAction(a Action) { } case *FreeAction: default: - if a.Speed() == ActionSpeeds.Slow && !s.stack.IsEmpty() { - err = errors.New("slow action can not be declared while other actions are on the stack") + if a.Speed() == ActionSpeeds.Slow { + if !s.stack.IsEmpty() { + err = ErrDeclareSlowAction{"stack not empty"} + } else if s.activePlayerId != a.Controller().Id || s.activePhase != Phases.ActionPhase { + err = ErrDeclareSlowAction{"not action phase"} + } } } } diff --git a/go/game/state_test.go b/go/game/state_test.go new file mode 100644 index 00000000..ad7fdca7 --- /dev/null +++ b/go/game/state_test.go @@ -0,0 +1,22 @@ +package game + +import ( + "testing" +) + +func TestDeclareActions(t *testing.T) { + s := NewLocalState() + s.SetMap(newEmpty2x2Map()) + p := s.AddNewPlayer("p", NewDeck()) + p.Ctrl = newMockPlayerControl(p) + o := s.AddNewPlayer("o", NewDeck()) + o.Ctrl = newMockPlayerControl(o) + a := s.addNewUnit(NewCard("base/archer"), Position{0, 0}, p) + k := s.addNewUnit(NewCard("base/knight"), Position{1, 1}, o) + sa := NewAttackAction(a) + sa.Target().AddSelection(k) + s.declareAction(sa) + if !s.stack.IsEmpty() { + t.Fatal("declared slow action during upkeep") + } +} |
