public void Render(SpriteBatch spriteBatch, Environment env, GameTime time, Rectangle mapDest, float posLerp) { int tile; Rectangle destination; int x = mapDest.X, y = mapDest.Y; int tileWidth = mapDest.Width / Environment.mazeSize_; int tileHeight = mapDest.Height / Environment.mazeSize_; for (int i = 0; i < Environment.mazeSize_; ++i) for (int j = 0; j < Environment.mazeSize_; ++j) { tile = env.maze_[i][j]; destination = new Rectangle(x + j * tileWidth, y + i * tileHeight, tileWidth, tileHeight); if (tile == -1) spriteBatch.Draw(WallTex, destination, Color.White); else { spriteBatch.Draw(FloorTex, destination, Color.White); spriteBatch.Draw(DirtTex, destination, Color.Lerp(Color.Transparent, Color.White, tile / MAX_DIRT)); } } destination = new Rectangle(x + env.agentPosY_ * tileWidth, y + env.agentPosX_ * tileHeight, tileWidth, tileHeight); switch (env.preAction_) { case ActionType.actIDLE: spriteBatch.Draw(CleanerTex, destination, Color.Yellow); break; case ActionType.actSUCK: spriteBatch.Draw(CleanerTex, destination, Color.Green); break; case ActionType.actUP: spriteBatch.Draw(CleanerTex, destination, env.isJustBump ? Color.Red : Color.White); break; case ActionType.actRIGHT: destination.Offset(tileWidth, 0); spriteBatch.Draw(CleanerTex, destination, null, env.isJustBump ? Color.Red : Color.White, MathHelper.PiOver2, Vector2.Zero, SpriteEffects.None, 0f); break; case ActionType.actDOWN: destination.Offset(tileWidth, tileHeight); spriteBatch.Draw(CleanerTex, destination, null, env.isJustBump ? Color.Red : Color.White, MathHelper.Pi, Vector2.Zero, SpriteEffects.None, 0f); break; case ActionType.actLEFT: destination.Offset(0, tileHeight); spriteBatch.Draw(CleanerTex, destination, null, env.isJustBump ? Color.Red : Color.White, -MathHelper.PiOver2, Vector2.Zero, SpriteEffects.None, 0f); break; } }
public void Eval(ActionType action, Environment env) { if (action == ActionType.actSUCK) consumedEnergy_ += 2; else if (action != ActionType.actIDLE) consumedEnergy_ += 1; cleanedDirty_ += env.getCleanedDirty; newDirty_ = env.getNewDirty; totalDirtyDegree_ += newDirty_; dirtyDegree_ = 0; for (int row = 0; row < Environment.mazeSize_; row++) { for (int col = 0; col < Environment.mazeSize_; col++) { long da = env.DirtAmount(row, col); dirtyDegree_ += da; } } }
public void Render(SpriteBatch spriteBatch, Environment env, GameTime time, Rectangle mapDest, float posLerp) { Vector2 currentPos = new Vector2(env.agentPosX_, env.agentPosY_); if (LastPos.X == float.NaN) { LastPos = currentPos; CurPos = LastPos; } if (posLerp == 0.0f) { LastPos = CurPos; CurPos = currentPos; } if (System.Math.Abs(LastPos.X - currentPos.X + LastPos.Y - currentPos.Y) > 1.5f) posLerp = 1.0f; Vector2 lerpPos = Vector2.Lerp(LastPos, currentPos, posLerp); if (posLerp > 0.5f) System.Console.WriteLine(); int tile; float x = -Environment.mazeSize_ * 0.5f, z = -Environment.mazeSize_ * 0.5f; Matrix worldTransform = Matrix.Identity; Matrix wvp; ModelMesh wallMesh = Wall.Meshes[0]; ModelMesh floorMesh = FloorTile.Meshes[0]; ModelMesh dirtMesh = Dirt.Meshes[0]; Effect wallEffect = wallMesh.Effects[0]; BasicEffect floorEffect = (BasicEffect)floorMesh.Effects[0]; Effect dirtEffect = dirtMesh.Effects[0]; DepthStencilState oldDss = GraphicsDevice.DepthStencilState; RasterizerState oldRs = GraphicsDevice.RasterizerState; GraphicsDevice.DepthStencilState = dss; GraphicsDevice.RasterizerState = rs; GraphicsDevice.SamplerStates[0] = ss; for (int i = 0; i < Environment.mazeSize_; ++i) for (int j = 0; j < Environment.mazeSize_; ++j) { tile = env.maze_[i][j]; worldTransform.M41 = x + i; worldTransform.M42 = 0.0f; worldTransform.M43 = z + j; Matrix.Multiply(ref worldTransform, ref Camera.ViewProj, out wvp); if (tile == -1) { wallEffect.Parameters["WorldViewProj"].SetValue(wvp); wallMesh.Draw(); } else { floorEffect.Parameters["WorldViewProj"].SetValue(wvp); floorEffect.DiffuseColor = Vector3.Lerp((Vector3)floorEffect.Tag, Vector3.Zero, tile * MAX_DIRT); floorMesh.Draw(); ////worldTransform.M42 = MathHelper.Lerp(0.04f, 0.8f, tile * MAX_DIRT); ////Matrix.Multiply(ref worldTransform, ref Camera.ViewProj, out wvp); //dirtEffect.Parameters["WorldViewProj"].SetValue(wvp); //dirtMesh.Draw(); } } worldTransform.M41 = x + lerpPos.X; worldTransform.M42 = 0.0f; worldTransform.M43 = z + lerpPos.Y + 0.5f; float rotation = 0f; Color col = Color.White; switch (env.preAction_) { case ActionType.actIDLE: rotation = LastRot; col = Color.Yellow; break; case ActionType.actSUCK: col = Color.Green; break; case ActionType.actUP: if (env.isJustBump) col = Color.Red; break; case ActionType.actRIGHT: if (env.isJustBump) col = Color.Red; rotation = MathHelper.PiOver2; break; case ActionType.actDOWN: if (env.isJustBump) col = Color.Red; rotation = MathHelper.Pi; break; case ActionType.actLEFT: if (env.isJustBump) col = Color.Red; rotation = -MathHelper.PiOver2; break; } var val1 = (float)System.Math.Cos(rotation); var val2 = (float)System.Math.Sin(rotation); worldTransform.M11 = val1; worldTransform.M13 = -val2; worldTransform.M31 = val2; worldTransform.M33 = val1; ModelMesh cleanerMesh = Cleaner.Meshes[0]; Matrix.Multiply(ref worldTransform, ref Camera.ViewProj, out wvp); foreach (BasicEffect effect in cleanerMesh.Effects) { effect.DiffuseColor = (Vector3)effect.Tag * col.ToVector3(); effect.Parameters["WorldViewProj"].SetValue(wvp); } cleanerMesh.Draw(); GraphicsDevice.DepthStencilState = oldDss; GraphicsDevice.RasterizerState = oldRs; }
public void Perceive(Environment env) { bump_ = env.isJustBump; dirty_ = env.IsCurrentPosDirty(); }
/// <summary> /// Reinitialize evaluator, agent, environment and statistics (used when go to next run) /// </summary> void StartLifecycle() { Environment = new Environment(SelectedMap); RNG = new RandomNumGen(Environment.RandomSeed + CurrentRun); Evaluator = new Evaluator(); switch (AgentName) { case "RandomAgent": CurrentAgent = new RandomAgent(); break; case "ModelAgent": CurrentAgent = new ModelAgent(); break; case "ModelAgentNoIdle": CurrentAgent = new ModelAgentNoIdle(); break; } TotalStepsDone = 0; StepsDone = 0; OverallDirty = 0; ConsumedEnergy = 0; DirtyOnMap = 0; CleanedDirty = 0; Displaying = false; RunStatsLbls[(int)RunStatistics.Action].Text = ""; RunStatsLbls[(int)RunStatistics.TimeStep].Text = TotalStepsDone.ToString(); DoOneStepBtn.Enabled = true; DoOneRunBtn.Enabled = true; DoAllRunBtn.Enabled = true; NextRunBtn.Enabled = false; GrpBox.Enabled = true; MapControl.Environment = Environment; }
public void Perceive(Environment env) { IsBump = env.isJustBump; IsDirty = env.IsCurrentPosDirty(); }