140 likes | 288 Views
GodPL. G amer o r D eity? P rogramming L anguage Konstantin Pozin. Problem Domain. A simple artificial life game: 2D environment Primitive creatures: Briyya (Pl. Briyyot ) Food sources (e.g. apple trees) Hazards (e.g. rocks, poisonous plants) Weather: rain, temperature
E N D
GodPL Gamer or Deity? Programming Language Konstantin Pozin
Problem Domain A simple artificial life game: • 2D environment • Primitive creatures: Briyya (Pl. Briyyot) • Food sources (e.g. apple trees) • Hazards (e.g. rocks, poisonous plants) • Weather: rain, temperature We want a fast way to program the creatures.
Problem Domain: Creatures • Can move, eat, hit other Briyyot, reproduce, die • Three life stages: Child, Adult, Senior • Two sexes • Genetic traits from 0.0 to 1.0:ColorRed, ColorBlue, ColorGreen, SizeScale, Swiftness, Curiosity, Aggressiveness, Courage, ResistanceToCold, ResistanceToToxin, ResistanceToPain, Strength, Metabolism • Sexual reproduction: gene averaging + error
Problem Domain: Creatures • Drives: Hunger, Boredom, Fear, Pain, (maybe more) • These correspond to probabilities that the creature will choose certain actions at given times • Basic learning (positive or negative attitudes towards categories of in-world objects)
Domain Inspiration • Creatures game, published in 1996 by Mindscape (later Cyberlife Technologies, then Creature Labs) • “one of the first commercial titles to code alifeorganisms from the genetic level upwards using a sophisticated biochemistry and neural network brains” (Wikipedia)
Language Features (1) Imperative, C-style language • Basic control loops • Definitions of methods • Conditions that trigger those methods (event-driven) • Special syntax for time-based triggers
Language Features (2) • Static typing, but with lots of implicit polymorphism • Type system: • Two primitives: float and string • Complex types are categories. An object can belong to more than one category (think of these as multiple interfaces). • GameObject, Briyya, Obstacle, FoodSource, PoisonSource, Shelter, Tree… • Categories cannot be defined by the user
General Program Structure globals: Type1 var1; Type2 var2; ... functions: Type1 foo1(…) { ... } ... triggers: (cond1 && cond2 && cond3) -> { foo1(…); foo2(…); foo3(…); … } ...
Control Flow if (cond1) { … } else if { … } else { … } float f = 0; while (f > 0) { f = f - 1; } foreach(Tree a) { if (me.DistanceTo(a) < 5) { me.MoveTowards(a); return; } }
Time Syntax Expressed as hh:mm:ss (time == 00:03:05) if ((time >= 00:00:00) && (time <= 00:00:10)) every(00:00:05)
Implementation: Runtime System • Microsoft .NET 3.5 on Windows • Written in C# • Using Windows Forms libraries for widgets • Microsoft XNA (managed graphics and game logic library) • Execution based on XNA’s game loop(usually 60 fps)
Implementation: Language • Primary ANTLR grammar for GodPL, generating a C#-based parser that outputs an AST • Secondary ANTLR grammar for AST, generating a C#-based parser that generates valid C# code • C# code compiled at runtime, incorporated into Briyyaclass’s Update() method
Remaining Tasks • Complete GodPL parser (about 10% left) • Write AST parser / C# generator • Complete runtime system (about 60% left) • Some concepts may yet have to be cut out • Sleep
Remaining Design Issues • Create special syntax for probability expressions? • How to deal with arbitrary identifiers (object names, member fields, and methods) • me.X and me.Drives.Hunger are valid • They get rewritten as this.X and this.Drives.Hunger in C# • What about me.GetType().Assembly.GetManifestResourceInfo()…