diff options
Diffstat (limited to 'go/game/stack.go')
| -rw-r--r-- | go/game/stack.go | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/go/game/stack.go b/go/game/stack.go index 5d62e601..22c20fa3 100644 --- a/go/game/stack.go +++ b/go/game/stack.go @@ -1,5 +1,32 @@ package game +import ( + "log" +) + type Stack struct { - Actions []Action + gameState *State + Actions []Action +} + +func NewStack(s *State) *Stack { + return &Stack{s, []Action{}} +} + +func (s *Stack) IsEmpty() bool { + return len(s.Actions) == 0 +} + +func (s *Stack) Push(a Action) { + s.Actions = append(s.Actions, a) +} + +func (s *Stack) Pop() { + l := len(s.Actions) + if l == 0 { + log.Fatalf("Can not pop from empty stack") + } + a := s.Actions[l-1] + s.Actions = s.Actions[:l-1] + a.Resolve(s.gameState) } |
