File tree Expand file tree Collapse file tree 2 files changed +23
-23
lines changed Expand file tree Collapse file tree 2 files changed +23
-23
lines changed Original file line number Diff line number Diff line change @@ -10,8 +10,6 @@ import (
10
10
"time"
11
11
)
12
12
13
- const maxHistorySize = 10
14
-
15
13
type Engine struct {
16
14
State * State
17
15
UiProtocol []UiProtocolEntry
@@ -81,27 +79,6 @@ func (e *Engine) AddGameEvent(gameEvent GameEvent) {
81
79
e .LogGameEvent (gameEvent )
82
80
}
83
81
84
- // UndoLastAction restores the last state from internal history
85
- func (e * Engine ) UndoLastAction () {
86
- lastIndex := len (e .History ) - 2
87
- if lastIndex >= 0 {
88
- * e .State = e .History [lastIndex ].State .DeepCopy ()
89
- e .UiProtocol = append (e .History [lastIndex ].UiProtocol [:0 :0 ],
90
- e .History [lastIndex ].UiProtocol ... )
91
- e .History = e .History [0 :lastIndex ]
92
- }
93
- }
94
-
95
- func (e * Engine ) appendHistory () {
96
- var entry HistoryEntry
97
- entry .State = e .State .DeepCopy ()
98
- entry .UiProtocol = append (e .UiProtocol [:0 :0 ], e .UiProtocol ... )
99
- e .History = append (e .History , entry )
100
- if len (e .History ) > maxHistorySize {
101
- e .History = e .History [1 :]
102
- }
103
- }
104
-
105
82
func (e * Engine ) Continue () {
106
83
substitutionIntend := e .State .BotSubstitutionIntend ()
107
84
if substitutionIntend != TeamUnknown {
Original file line number Diff line number Diff line change 8
8
"os"
9
9
)
10
10
11
+ const maxHistorySize = 10
11
12
const historyFileName = "history.json"
12
13
13
14
type HistoryPreserver struct {
@@ -79,3 +80,25 @@ func (r *HistoryPreserver) Save(history History) {
79
80
log .Print ("Could not sync history file" , err )
80
81
}
81
82
}
83
+
84
+ // UndoLastAction restores the last state from internal history
85
+ func (e * Engine ) UndoLastAction () {
86
+ lastIndex := len (e .History ) - 2
87
+ if lastIndex >= 0 {
88
+ * e .State = e .History [lastIndex ].State .DeepCopy ()
89
+ e .UiProtocol = append (e .History [lastIndex ].UiProtocol [:0 :0 ],
90
+ e .History [lastIndex ].UiProtocol ... )
91
+ e .History = e .History [0 :lastIndex ]
92
+ }
93
+ }
94
+
95
+ // appendHistory appends the current state to the history
96
+ func (e * Engine ) appendHistory () {
97
+ var entry HistoryEntry
98
+ entry .State = e .State .DeepCopy ()
99
+ entry .UiProtocol = append (e .UiProtocol [:0 :0 ], e .UiProtocol ... )
100
+ e .History = append (e .History , entry )
101
+ if len (e .History ) > maxHistorySize {
102
+ e .History = e .History [1 :]
103
+ }
104
+ }
You can’t perform that action at this time.
0 commit comments