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 NNG.GameServer.Utils
import NNG.GameServer.EnvExtensions
import GameServer.Utils
import GameServer.EnvExtensions
open Lean Meta
@@ -1,5 +1,5 @@
import NNG.GameServer.HashMapExtension
import NNG.GameServer.SingleValPersistentEnvExtension
import GameServer.HashMapExtension
import GameServer.SingleValPersistentEnvExtension
/-! # Environment extensions
@@ -6,8 +6,8 @@ It is based on lean-gym by Daniel Selsam.
-/
import Lean.Data.Json.Basic
import NNG.GameServer.Utils
import NNG.GameServer.EnvExtensions
import GameServer.Utils
import GameServer.EnvExtensions
open Lean Meta Elab Tactic Std
@@ -223,7 +223,7 @@ where
open System Lean Std in
partial def runGame (GameName : Name) (paths : List FilePath): IO Unit := do
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 levels := levelsExt.getState env
let game := {← gameExt.get with nb_levels := levels.size }
+14 -11
View File
@@ -1,13 +1,16 @@
import NNG.GameServer.Server
import NNG.NNG
import GameServer.Server
def System.FilePath.parent! (fp : System.FilePath) : System.FilePath :=
match fp.parent with
| some path => path
| none => panic! "Couldn't find parent folder"
unsafe def main (args : List String) : IO Unit := do
unsafe def main : IO Unit := do
let build_folder := (← IO.appPath).parent!.parent!
let paths : List System.FilePath := [build_folder/"lib",
(← Lean.findSysroot) / "lib" / "lean"]
Server.runGame `NNG paths
if args.length != 2 then
throw (IO.userError "Expected two arguments: The name of the game module and the path to the game project.")
let out ← IO.Process.output { cwd := args[1]!, cmd := "lake", args := #["env","printenv","LEAN_PATH"] }
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
open Lake DSL
package nng {
-- add package configuration options here
}
package GameServer
lean_lib NNG {
-- add library configuration options here
}
lean_lib NNG.levels {
-- add library configuration options here
}
lean_lib GameServer
@[defaultTarget]
lean_exe nng {
lean_exe gameserver {
root := `Main
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 NNG.MyNat
import GameServer.Commands
import TestGame.MyNat
LemmaDoc zero_add as zero_add in "Addition"
"This lemma says `∀ a : ℕ, 0 + a = a`."
@@ -1,4 +1,4 @@
import NNG.Metadata
import TestGame.Metadata
Level 1
@@ -1,4 +1,4 @@
import NNG.Metadata
import TestGame.Metadata
Level 2
@@ -1,4 +1,4 @@
import NNG.Metadata
import TestGame.Metadata
Level 3
@@ -1,4 +1,4 @@
import NNG.Metadata
import TestGame.Metadata
Level 4
@@ -1,5 +1,5 @@
import NNG.Metadata
import NNG.Tactics
import TestGame.Metadata
import TestGame.Tactics
Level 5
@@ -1,9 +1,9 @@
import NNG.GameServer.Commands
import NNG.MyNat
import NNG.TacticDocs
import NNG.LemmaDocs
import GameServer.Commands
import TestGame.MyNat
import TestGame.TacticDocs
import TestGame.LemmaDocs
Game "NNG"
Game "TestGame"
Title "The Natural Number Game"
@@ -1,6 +1,6 @@
import NNG.GameServer.Commands
import GameServer.Commands
import NNG.Tactics
import TestGame.Tactics
TacticDoc rfl
"
@@ -1,5 +1,5 @@
import Lean
import NNG.MyNat
import TestGame.MyNat
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