split off test game

still need to adapt the call to the lean binary to provide two arguments
This commit is contained in:
Alexander Bentkamp
2022-10-17 17:42:52 +02:00
parent 7563730292
commit d6bd2c98da
24 changed files with 60 additions and 52 deletions
+2
View File
@@ -0,0 +1,2 @@
import GameServer.Commands
import GameServer.Server
@@ -1,7 +1,7 @@
import Lean import Lean
import NNG.GameServer.Utils import GameServer.Utils
import NNG.GameServer.EnvExtensions import GameServer.EnvExtensions
open Lean Meta open Lean Meta
@@ -1,5 +1,5 @@
import NNG.GameServer.HashMapExtension import GameServer.HashMapExtension
import NNG.GameServer.SingleValPersistentEnvExtension import GameServer.SingleValPersistentEnvExtension
/-! # Environment extensions /-! # Environment extensions
@@ -6,8 +6,8 @@ It is based on lean-gym by Daniel Selsam.
-/ -/
import Lean.Data.Json.Basic import Lean.Data.Json.Basic
import NNG.GameServer.Utils import GameServer.Utils
import NNG.GameServer.EnvExtensions import GameServer.EnvExtensions
open Lean Meta Elab Tactic Std open Lean Meta Elab Tactic Std
@@ -223,7 +223,7 @@ where
open System Lean Std in open System Lean Std in
partial def runGame (GameName : Name) (paths : List FilePath): IO Unit := do partial def runGame (GameName : Name) (paths : List FilePath): IO Unit := do
searchPathRef.set paths searchPathRef.set paths
let env ← importModules [{ module := `Init : Import }, { module := GameName ++ GameName : Import }] {} 0 let env ← importModules [{ module := `Init : Import }, { module := GameName : Import }] {} 0
let termElabM : TermElabM Unit := do let termElabM : TermElabM Unit := do
let levels := levelsExt.getState env let levels := levelsExt.getState env
let game := {← gameExt.get with nb_levels := levels.size } let game := {← gameExt.get with nb_levels := levels.size }
+14 -11
View File
@@ -1,13 +1,16 @@
import NNG.GameServer.Server import GameServer.Server
import NNG.NNG
def System.FilePath.parent! (fp : System.FilePath) : System.FilePath := unsafe def main (args : List String) : IO Unit := do
match fp.parent with
| some path => path
| none => panic! "Couldn't find parent folder"
unsafe def main : IO Unit := do if args.length != 2 then
let build_folder := (← IO.appPath).parent!.parent! throw (IO.userError "Expected two arguments: The name of the game module and the path to the game project.")
let paths : List System.FilePath := [build_folder/"lib",
(← Lean.findSysroot) / "lib" / "lean"] let out ← IO.Process.output { cwd := args[1]!, cmd := "lake", args := #["env","printenv","LEAN_PATH"] }
Server.runGame `NNG paths
if out.exitCode != 0 then
IO.eprintln out.stderr
else
let paths : List System.FilePath := System.SearchPath.parse out.stdout.trim
let currentDir ← IO.currentDir
let paths := paths.map fun p => currentDir / (args[1]! : System.FilePath) / p
Server.runGame (Lean.Name.mkSimple args[0]!) paths
-7
View File
@@ -1,7 +0,0 @@
import NNG.Metadata
import NNG.Levels.Level1
import NNG.Levels.Level2
import NNG.Levels.Level3
import NNG.Levels.Level4
import NNG.Levels.Level5
+3 -11
View File
@@ -1,20 +1,12 @@
import Lake import Lake
open Lake DSL open Lake DSL
package nng { package GameServer
-- add package configuration options here
}
lean_lib NNG { lean_lib GameServer
-- add library configuration options here
}
lean_lib NNG.levels {
-- add library configuration options here
}
@[defaultTarget] @[defaultTarget]
lean_exe nng { lean_exe gameserver {
root := `Main root := `Main
supportInterpreter := true supportInterpreter := true
} }
+1
View File
@@ -0,0 +1 @@
build
+7
View File
@@ -0,0 +1,7 @@
import TestGame.Metadata
import TestGame.Levels.Level1
import TestGame.Levels.Level2
import TestGame.Levels.Level3
import TestGame.Levels.Level4
import TestGame.Levels.Level5
@@ -1,5 +1,5 @@
import NNG.GameServer.Commands import GameServer.Commands
import NNG.MyNat import TestGame.MyNat
LemmaDoc zero_add as zero_add in "Addition" LemmaDoc zero_add as zero_add in "Addition"
"This lemma says `∀ a : ℕ, 0 + a = a`." "This lemma says `∀ a : ℕ, 0 + a = a`."
@@ -1,4 +1,4 @@
import NNG.Metadata import TestGame.Metadata
Level 1 Level 1
@@ -1,4 +1,4 @@
import NNG.Metadata import TestGame.Metadata
Level 2 Level 2
@@ -1,4 +1,4 @@
import NNG.Metadata import TestGame.Metadata
Level 3 Level 3
@@ -1,4 +1,4 @@
import NNG.Metadata import TestGame.Metadata
Level 4 Level 4
@@ -1,5 +1,5 @@
import NNG.Metadata import TestGame.Metadata
import NNG.Tactics import TestGame.Tactics
Level 5 Level 5
@@ -1,9 +1,9 @@
import NNG.GameServer.Commands import GameServer.Commands
import NNG.MyNat import TestGame.MyNat
import NNG.TacticDocs import TestGame.TacticDocs
import NNG.LemmaDocs import TestGame.LemmaDocs
Game "NNG" Game "TestGame"
Title "The Natural Number Game" Title "The Natural Number Game"
@@ -1,6 +1,6 @@
import NNG.GameServer.Commands import GameServer.Commands
import NNG.Tactics import TestGame.Tactics
TacticDoc rfl TacticDoc rfl
" "
@@ -1,5 +1,5 @@
import Lean import Lean
import NNG.MyNat import TestGame.MyNat
open Lean Elab Tactic open Lean Elab Tactic
+9
View File
@@ -0,0 +1,9 @@
import Lake
open Lake DSL
require GameServer from ".."/"server"
package TestGame
@[defaultTarget]
lean_lib TestGame
+1
View File
@@ -0,0 +1 @@
leanprover/lean4:nightly-2022-09-23