examples: support boxoban style collections of levels files (from https://github.com/google-deepmind/boxoban-levels/)

This commit is contained in:
Delyan Angelov 2025-05-15 15:42:53 +03:00
parent 4c530217d2
commit 91328346a5
No known key found for this signature in database
GPG key ID: 66886C0F12D595ED

View file

@ -253,7 +253,19 @@ fn (mut g Game) iid(name string) !int {
fn main() {
mut g := &Game{}
if os.args.len > 1 {
g.levels = os.args[1..].map(os.read_file(it)!)
for fpath in os.args[1..] {
content := os.read_file(fpath)!
if content.starts_with(';') {
// many levels in the same file:
parts := content.trim_space().split('\n\n')
for part in parts {
g.levels << '${fpath}${part}'
}
} else {
// a single level:
g.levels << content
}
}
} else {
all_level_names := asset.read_text('/', '_all_levels.txt')!.split_into_lines()
g.levels = all_level_names.map(asset.read_text('/', it)!)