mirror of
https://github.com/vlang/v.git
synced 2025-09-13 14:32:26 +03:00
examples: support boxoban style collections of levels files (from https://github.com/google-deepmind/boxoban-levels/)
This commit is contained in:
parent
4c530217d2
commit
91328346a5
1 changed files with 13 additions and 1 deletions
|
@ -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)!)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue