From 68c3b811c094fe43de3623e96291a0fcad7c4c31 Mon Sep 17 00:00:00 2001 From: ryuga4 Date: Sun, 5 May 2019 17:54:12 +0200 Subject: [PATCH] c5 --- Trunk/MonoGameView/Algorithms/BFS.cs | 10 +++++----- Trunk/MonoGameView/Algorithms/DFS.cs | 8 ++++---- .../DataModels/Interfaces/IStep.cs | 3 ++- .../DataModels/Models/Steps/CollectStep.cs | 2 +- .../DataModels/Models/Steps/MoveStep.cs | 10 +++++----- .../DataModels/Models/Steps/SpillStep.cs | 2 +- Trunk/MonoGameView/Game1.cs | 18 +++++++++--------- Trunk/MonoGameView/MonoGameView.csproj | 4 ++++ Trunk/MonoGameView/packages.config | 4 ++++ 9 files changed, 35 insertions(+), 26 deletions(-) create mode 100644 Trunk/MonoGameView/packages.config diff --git a/Trunk/MonoGameView/Algorithms/BFS.cs b/Trunk/MonoGameView/Algorithms/BFS.cs index 14ab60a..3473ce8 100644 --- a/Trunk/MonoGameView/Algorithms/BFS.cs +++ b/Trunk/MonoGameView/Algorithms/BFS.cs @@ -55,8 +55,8 @@ namespace MonoGameView.Algorithms var result = new List(); - - if (!(collector.TrashContainers.Any(x => x.FillPercent > 0) && grid[collector.Coords.X, collector.Coords.Y] is ADump)) + var itemdupa = grid[collector.Coords.X, collector.Coords.Y]; + if (!(itemdupa is House && collector.TrashContainers.All(i=>i.FillPercent==0))) { var moveSteps = new List() { @@ -141,15 +141,15 @@ namespace MonoGameView.Algorithms var nodes2 = new List, GarbageCollector, ICloneable[,]>>(); foreach (var item in nodes) { - Thread.Sleep(100); - this.Collector.Coords = item.Item2.Coords; + // Thread.Sleep(100); + /*this.Collector.Coords = item.Item2.Coords; for (int x = 0; x < item.Item3.GetLength(0); x++) { for (int y = 0; y < item.Item3.GetLength(1); y++) { this.Grid[x, y] = item.Item3[x, y]; } - } + }*/ if (Houses.All(c => (item.Item3[c.X, c.Y] as IGarbageLocalization).TrashCans.All(j => j.FillPercent == 0.0)) && diff --git a/Trunk/MonoGameView/Algorithms/DFS.cs b/Trunk/MonoGameView/Algorithms/DFS.cs index ab7dbf0..26ba707 100644 --- a/Trunk/MonoGameView/Algorithms/DFS.cs +++ b/Trunk/MonoGameView/Algorithms/DFS.cs @@ -126,8 +126,8 @@ namespace CzokoŚmieciarka.MonoGameView.Algorithms KeyValuePair, int> Search(ContentManager content, GarbageCollector collector, ICloneable[,] grid, int length) { - //Thread.Sleep(1); - this.Collector.Coords = collector.Coords; + //Thread.Sleep(100); + /*this.Collector.Coords = collector.Coords; for (int x = 0; x < grid.GetLength(0); x++) { for (int y = 0; y < grid.GetLength(1); y++) @@ -135,10 +135,10 @@ namespace CzokoŚmieciarka.MonoGameView.Algorithms this.Grid[x, y] = grid[x, y]; } } - + */ Console.WriteLine(collector.HouseCounter); - if (collector.Counter> 15 || length > 100) + if (collector.Counter> 100 || length > 100) return new KeyValuePair, int>(null,length); count++; if (Houses.All(c => (grid[c.X, c.Y] as IGarbageLocalization).TrashCans.All(j => j.FillPercent == 0.0)) diff --git a/Trunk/MonoGameView/DataModels/Interfaces/IStep.cs b/Trunk/MonoGameView/DataModels/Interfaces/IStep.cs index cc5c983..ac857b8 100644 --- a/Trunk/MonoGameView/DataModels/Interfaces/IStep.cs +++ b/Trunk/MonoGameView/DataModels/Interfaces/IStep.cs @@ -1,9 +1,10 @@ using CzokoŚmieciarka.MonoGameView.DataModels.Interfaces.GarbageCollector; +using System; namespace CzokoŚmieciarka.MonoGameView.DataModels.Interfaces { public interface IStep { - bool Invoke(IGarbageCollector collector, object [,] grid); + bool Invoke(IGarbageCollector collector, ICloneable [,] grid); } } diff --git a/Trunk/MonoGameView/DataModels/Models/Steps/CollectStep.cs b/Trunk/MonoGameView/DataModels/Models/Steps/CollectStep.cs index 21085d8..8b89df3 100644 --- a/Trunk/MonoGameView/DataModels/Models/Steps/CollectStep.cs +++ b/Trunk/MonoGameView/DataModels/Models/Steps/CollectStep.cs @@ -21,7 +21,7 @@ namespace CzokoŚmieciarka.MonoGameView.DataModels.Models.Steps private GarbageType _typeOfGarbage; - public bool Invoke(IGarbageCollector _garbageCollector, object [,] grid) + public bool Invoke(IGarbageCollector _garbageCollector, ICloneable [,] grid) { var _garbageLocalization = (IGarbageLocalization) grid[_garbageCollector.Coords.X, _garbageCollector.Coords.Y]; diff --git a/Trunk/MonoGameView/DataModels/Models/Steps/MoveStep.cs b/Trunk/MonoGameView/DataModels/Models/Steps/MoveStep.cs index 1bd790c..f03deb6 100644 --- a/Trunk/MonoGameView/DataModels/Models/Steps/MoveStep.cs +++ b/Trunk/MonoGameView/DataModels/Models/Steps/MoveStep.cs @@ -20,7 +20,7 @@ namespace CzokoŚmieciarka.MonoGameView.DataModels.Models.Steps private Direction _direction; private IGarbageCollector _garbageCollector; - public bool Invoke(IGarbageCollector _garbageCollector, object[,] grid) + public bool Invoke(IGarbageCollector _garbageCollector, ICloneable [,] grid) { if(grid[_garbageCollector.Coords.X, _garbageCollector.Coords.Y] is Road1) grid[_garbageCollector.Coords.X, _garbageCollector.Coords.Y] = new Road2(new Coords(_garbageCollector.Coords.X, _garbageCollector.Coords.Y)); @@ -28,17 +28,17 @@ namespace CzokoŚmieciarka.MonoGameView.DataModels.Models.Steps switch (_direction) { case Direction.Up: - pass = _garbageCollector.MoveDown(); + pass = _garbageCollector.MoveUp(); break; case Direction.Down: - pass = _garbageCollector.MoveRight(); + pass = _garbageCollector.MoveDown(); break; case Direction.Left: - pass = _garbageCollector.MoveUp(); + pass = _garbageCollector.MoveLeft(); break; case Direction.Right: - pass = _garbageCollector.MoveLeft(); + pass = _garbageCollector.MoveRight(); break; } if (pass) diff --git a/Trunk/MonoGameView/DataModels/Models/Steps/SpillStep.cs b/Trunk/MonoGameView/DataModels/Models/Steps/SpillStep.cs index 7028bcb..d6278df 100644 --- a/Trunk/MonoGameView/DataModels/Models/Steps/SpillStep.cs +++ b/Trunk/MonoGameView/DataModels/Models/Steps/SpillStep.cs @@ -20,7 +20,7 @@ namespace CzokoŚmieciarka.MonoGameView.DataModels.Models.Steps private GarbageType _typeOfGarbage; - public bool Invoke(IGarbageCollector _garbageCollector, object [,] grid) + public bool Invoke(IGarbageCollector _garbageCollector, ICloneable [,] grid) { var _dump = (ADump)grid[_garbageCollector.Coords.X, _garbageCollector.Coords.Y]; diff --git a/Trunk/MonoGameView/Game1.cs b/Trunk/MonoGameView/Game1.cs index c42765a..feffbba 100644 --- a/Trunk/MonoGameView/Game1.cs +++ b/Trunk/MonoGameView/Game1.cs @@ -32,7 +32,7 @@ namespace CzokoŚmieciarka.MonoGameView MapLoader mapLoader = new MapLoader(); Vector2 roadPos; float timer; - const float TIMER = 1f; + const float TIMER = 0.1f; int stepN; List steps; GarbageCollector collector; @@ -60,7 +60,7 @@ namespace CzokoŚmieciarka.MonoGameView // TODO: Add your initialization logic here timer = 0f; - mapLoader.Load(out size,out grid,"map1.xml"); + mapLoader.Load(out size,out grid,"map2.xml"); var containers = new List() { new GarbageCollectorContainer( @@ -89,12 +89,12 @@ namespace CzokoŚmieciarka.MonoGameView stepN = 0; - var dfs = new BFS(collector,grid); - //steps = dfs.BestPath(Content, collector, grid); - new Thread(delegate() { - var x = dfs.BestPath(Content, collector, grid); + var dfs = new DFS(collector,grid); + steps = dfs.BestPath(Content, collector, grid); + //new Thread(delegate() { + // var x = dfs.BestPath(Content, collector, grid); - }).Start(); + //}).Start(); base.Initialize(); } @@ -131,7 +131,7 @@ namespace CzokoŚmieciarka.MonoGameView if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) Exit(); - /*var elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds; + var elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds; timer -= elapsed; if (timer<0) { @@ -141,7 +141,7 @@ namespace CzokoŚmieciarka.MonoGameView steps.First().Invoke(collector, grid); steps.RemoveAt(0); } - }*/ + } // TODO: Add your update logic here diff --git a/Trunk/MonoGameView/MonoGameView.csproj b/Trunk/MonoGameView/MonoGameView.csproj index a966011..e76fbd6 100644 --- a/Trunk/MonoGameView/MonoGameView.csproj +++ b/Trunk/MonoGameView/MonoGameView.csproj @@ -88,6 +88,9 @@ + + ..\packages\C5.2.5.3\lib\net45\C5.dll + $(MonoGameInstallDirectory)\MonoGame\v3.0\Assemblies\Windows\MonoGame.Framework.dll @@ -101,6 +104,7 @@ + diff --git a/Trunk/MonoGameView/packages.config b/Trunk/MonoGameView/packages.config new file mode 100644 index 0000000..ec72072 --- /dev/null +++ b/Trunk/MonoGameView/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file