Created
June 9, 2017 20:50
-
-
Save unixpickle/2ae43b9fa2dfd4e4374367838aa516f6 to your computer and use it in GitHub Desktop.
Variants demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Demonstrate game variants in muniverse. | |
package main | |
import ( | |
"fmt" | |
"image/png" | |
"log" | |
"os" | |
"time" | |
"github.com/unixpickle/muniverse" | |
) | |
func main() { | |
names := []string{ | |
"GoldMinerTom-v0", | |
"GoldMinerTom-v1", | |
"BurninRubber-v0", | |
"BurninRubber-v1", | |
"BurninRubber-v2", | |
"BurninRubber-v3", | |
} | |
for _, name := range names { | |
log.Println("Doing", name, "...") | |
spec := muniverse.SpecForName(name) | |
if spec == nil { | |
panic("no spec") | |
} | |
env, err := muniverse.NewEnv(spec) | |
if err != nil { | |
panic(err) | |
} | |
if err := env.Reset(); err != nil { | |
panic(err) | |
} | |
rew, done, err := env.Step(time.Second * 2) | |
if err != nil { | |
panic(err) | |
} | |
fmt.Println("rew", rew, "done", done) | |
obs, err := env.Observe() | |
if err != nil { | |
panic(err) | |
} | |
img, err := obs.Image() | |
if err != nil { | |
panic(err) | |
} | |
f, _ := os.Create(name + ".png") | |
png.Encode(f, img) | |
f.Close() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment