返回 CodeWhale
WorldConformance.swift
根目录 / pet / swift / WorldConformance.swift
1 import Foundation
2
3 @main struct WorldConformance {
4 @MainActor static func main() throws {
5 let args = CommandLine.arguments
6 guard args.count >= 4 else { throw PetCoreError.invalid("Usage: world-conformance pet-native.js points.tsv demo.jsonl [--still]") }
7 let points = try String(contentsOfFile: args[2], encoding: .utf8).split(separator: "\n").map { line -> (Double, Double) in
8 let v = line.split(separator: "\t").compactMap { Double($0) }
9 guard v.count == 2 else { throw PetCoreError.invalid("Invalid points.") }; return (v[0], v[1])
10 }
11 let tape = try String(contentsOfFile: args[3], encoding: .utf8)
12 let core = try PetNativeCore(points: points, bundle: URL(fileURLWithPath: args[1]), tape: tape)
13 var voices = core.frame.voices.count
14 for i in 0..<2400 {
15 let frame = try core.tick(motion: !args.contains("--still"))
16 let native = petDigest(core.sim)
17 guard native == frame.digest else { throw PetCoreError.invalid("Frame \(i): Swift \(native) != shared world \(frame.digest)") }
18 voices += frame.voices.count
19 if i % 300 == 0 { print("f\(i) \(native) \(frame.behaviour) \(frame.needs)") }
20 }
21 print("PASS 2400 native world frames; \(voices) scheduled voices; \(args.contains("--still") ? "still" : "animated")")
22 }
23 }
24
24 lines Plain Text