-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
73 lines (61 loc) · 1.83 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package main
import (
"automaton/automaton"
"automaton/ofc"
"log"
"strconv"
"time"
)
func main() {
log.Printf("Starting Bot\n")
gCtxt := ofc.GameContext{
Hwnd: automaton.FindWindow("MEmu"),
ImageServerHost: "http://localhost:8000",
SolverServerHost: "http://34.74.180.106:9001/eval",
ScreenShotDir: "C:\\Users\\neera\\Documents\\screenshots"}
for {
var gs *ofc.GameState
var err error
// take a screenshot every half second, break when we have to make a decision
for {
gs, err = gCtxt.Capture("tmp") // don't care about saving these
if err != nil { // gs is nil
log.Println("Line 42 failed.")
log.Println(err)
}
if isValid, _ := gs.IsValid(); isValid && gs.DecisionRequired() {
// sometimes we screenshot halfway through loading all the cards on the screen.
// to fix that, sleep for half a second and recapture the game state
time.Sleep(500 * time.Millisecond)
timeString := strconv.Itoa(int(time.Now().Unix()))
gs, err = gCtxt.CaptureWithRetry(timeString)
if err != nil {
log.Fatalf("Second screenshot %v failed %v", timeString, err)
}
if !gs.DecisionRequired() {
panic("Somehow gamestate doesn't have a required decision")
}
break
}
log.Println("No Decision Required yet...")
time.Sleep(200 * time.Millisecond)
}
log.Println("Decision needed!")
actions, err := gCtxt.SolveGameState(gs)
if err != nil {
log.Println("Solver failed.")
log.Fatal(err)
}
err = gCtxt.ExecuteActions(actions, gs)
if err != nil {
log.Fatalf("ExecuteActions failed: %+v\n", err)
}
// make sure actions were performed correctly and press the confirm button.
err = gCtxt.ConfirmActions(actions)
if err != nil {
log.Println("Confirm Actions failed.")
log.Fatal(err)
}
time.Sleep(200 * time.Millisecond)
}
}