public EncogMaze(MazeInfo maze, MazeGame gameRef) : this(maze) { this.gameRef = gameRef; gameRef.GameStartEvent += GameRef_GameStartEvent; gameRef.GameCycleEvent += GameRef_GameCycleEvent; }
public MazeInfo GetByID(int id) { MazeInfo retVal = null; var sql = $"SELECT [ID], [Name], [Metadata] FROM [{TABLE}] WHERE [ID] = @ID"; using (var conn = GetOpenConnection()) { using (var comm = new SqlCommand(sql, conn)) { comm.Parameters.Add(new SqlParameter("@ID", id)); using (var reader = comm.ExecuteReader()) { while (reader.Read()) { retVal = new MazeInfo(); retVal.ID = Convert.ToInt32(reader[0]); retVal.Name = reader[1].ToString(); retVal.Metadata = reader[2].ToString(); } } } } return(retVal); }
public virtual RlmNetwork CreateOrLoadNetwork(MazeInfo maze) { var rlmNet = new RlmNetwork("RLM_maze_" + maze.Name); //+ "_" + Guid.NewGuid().ToString("N")); rlmNet.DataPersistenceComplete += RlmNet_DataPersistenceComplete; rlmNet.DataPersistenceProgress += RlmNet_DataPersistenceProgress; if (!rlmNetCache.Contains("rlmNet")) { var expiration = DateTimeOffset.UtcNow.AddDays(1); rlmNetCache.Add("rlmNet", rlmNet, expiration); } else { rlmNet = (RlmNetwork)rlmNetCache.Get("rlmNet", null); } if (!rlmNet.LoadNetwork(maze.Name)) { var inputs = new List <RlmIO>() { new RlmIO("X", typeof(Int32).ToString(), 0, maze.Width - 1, RlmInputType.Distinct), new RlmIO("Y", typeof(Int32).ToString(), 0, maze.Height - 1, RlmInputType.Distinct), }; var outputs = new List <RlmIO>() { new RlmIO("Direction", typeof(Int16).ToString(), 0, 3) }; rlmNet.NewNetwork(maze.Name, inputs, outputs); } return(rlmNet); }
public EncogMazeTraveler(BasicNetwork network, MazeInfo maze) { this.network = network; this.maze = maze; // set normalized fields xInput = new NormalizedField(NormalizationAction.Normalize, "X", maze.Width - 1, 0, -0.9, 0.9); yInput = new NormalizedField(NormalizationAction.Normalize, "Y", maze.Height - 1, 0, -0.9, 0.9); bumpedIntoWallInput = new NormalizedField(NormalizationAction.Normalize, "BumpedIntoWall", 1, 0, -0.9, 0.9); directionOutput = new NormalizedField(NormalizationAction.Normalize, "Direction", 3, 0, -0.9, 0.9); tmr.Elapsed += Tmr_Elapsed; }
// for windowless version public RLMMazeTraveler(MazeInfo maze, bool learn = false, int numSessions = 1, int startRandomness = 1, int endRandomness = 1) { this.maze = maze; Learn = learn; rlmNetCache = MemoryCache.Default; rlmNet = CreateOrLoadNetwork(maze); rlmNet.NumSessions = numSessions; rlmNet.StartRandomness = startRandomness; rlmNet.EndRandomness = endRandomness; tmr.Elapsed += Tmr_Elapsed; }
public void UpdateMaze(int id, MazeInfo maze) { var sql = $"UPDATE [{TABLE}] SET [Name] = @Name, [Metadata] = @Metadata WHERE [ID] = @ID"; using (var conn = GetOpenConnection()) { using (var comm = new SqlCommand(sql, conn)) { comm.Parameters.Add(new SqlParameter("@ID", id)); comm.Parameters.Add(new SqlParameter("@Name", maze.Name)); comm.Parameters.Add(new SqlParameter("@Metadata", maze.Metadata)); comm.ExecuteNonQuery(); } } }
public MazeInfo CreateMaze(MazeInfo maze) { var sql = $"INSERT INTO [{TABLE}] VALUES (@Name, @Metadata); SELECT SCOPE_IDENTITY();"; using (var conn = GetOpenConnection()) { using (var comm = new SqlCommand(sql, conn)) { comm.Parameters.Add(new SqlParameter("@Name", maze.Name)); comm.Parameters.Add(new SqlParameter("@Metadata", maze.Metadata)); maze.ID = Convert.ToInt32(comm.ExecuteScalar()); } } return(maze); }
public void InitGame(MazeInfo maze) { //Set Goal Location TheMazeGrid = maze.Grid; Height = maze.Height; Width = maze.Width; PerfectGameMovesCount = maze.PerfectGameMovesCount; GoalLocation.X = maze.GoalPosition.X; GoalLocation.Y = maze.GoalPosition.Y; OldLocation.X = maze.StartingPosition.X; OldLocation.Y = maze.StartingPosition.Y; if (traveler != null) { traveler.location.X = maze.StartingPosition.X; traveler.location.Y = maze.StartingPosition.Y; } }
// for windowless version public RLMMazeTraveler(MazeInfo maze, bool learn = false, int numSessions = 1, int startRandomness = 1, int endRandomness = 1, Action <double, double> persistentProgressAct = null, Action persistentDoneAct = null) { this.maze = maze; Learn = learn; rlmNetCache = MemoryCache.Default; rlmNet = CreateOrLoadNetwork(maze); rlmNet.NumSessions = numSessions; rlmNet.StartRandomness = startRandomness; rlmNet.EndRandomness = endRandomness; tmr.Elapsed += Tmr_Elapsed; this.persistentProgressAct = persistentProgressAct; this.persistentDoneAct = persistentDoneAct; }
// for window version public RLMMazeTraveler(MazeInfo maze, MazeGame gameref, bool learn = false, int numSessions = 1, int startRandomness = 1, int endRandomness = 1, SetRandomnessLeftDelegate setRandomnessLeft = null) : base(gameref) { Learn = learn; GameRef.GameStartEvent += GameRef_GameStartEvent; GameRef.GameCycleEvent += GameRef_GameCycleEvent; //GameRef.GameOverEvent += GameRef_GameOverEvent; rlmNet = CreateOrLoadNetwork(maze); // Temporary, while RFactor not yet implemented rlmNet.NumSessions = numSessions; rlmNet.StartRandomness = startRandomness; rlmNet.EndRandomness = endRandomness; rlmNet.CycleComplete += Rlm_net_CycleComplete; SetRandomnessLeft = setRandomnessLeft; tmr.Elapsed += Tmr_Elapsed; }
public EncogMaze(MazeInfo maze, int hiddenLayers = 1, int?hiddenLayerNeurons = null) { this.maze = maze; filePath = Path.Combine(Environment.CurrentDirectory, maze.Name + "." + ENCOG_FILE_EXTENSION); if (!LoadNetwork()) { // create new network var pattern = new FeedForwardPattern() { InputNeurons = INPUT_RNEURONS, OutputNeurons = OUTPUT_RNEURONS }; for (int i = 0; i < hiddenLayers; i++) { pattern.AddHiddenLayer(hiddenLayerNeurons == null ? maze.Width * maze.Height : hiddenLayerNeurons.Value); } pattern.ActivationFunction = new ActivationTANH(); network = (BasicNetwork)pattern.Generate(); network.Reset(); } }
public EncogScore(MazeInfo maze, int timerTimeout = 5) { this.maze = maze; this.time = timerTimeout; }