From c3c0b5703604d0d9dbf5dc4f819e3eb2ce304b11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Dulski?= Date: Tue, 11 Jun 2019 23:05:31 +0200 Subject: [PATCH] parser --- .../Algorithms/BestFirstSearch.cs | 176 +++++++++++++++++- .../DataModels/Models/Steps/CollectStep.cs | 4 + .../DataModels/Models/Steps/MoveStep.cs | 4 + .../DataModels/Models/Steps/SpillStep.cs | 4 + 4 files changed, 181 insertions(+), 7 deletions(-) diff --git a/Trunk/MonoGameView/Algorithms/BestFirstSearch.cs b/Trunk/MonoGameView/Algorithms/BestFirstSearch.cs index 8171525..048f09d 100644 --- a/Trunk/MonoGameView/Algorithms/BestFirstSearch.cs +++ b/Trunk/MonoGameView/Algorithms/BestFirstSearch.cs @@ -6,12 +6,15 @@ using CzokoŚmieciarka.MonoGameView.DataModels.Models; using CzokoŚmieciarka.MonoGameView.DataModels.Models.Steps; using System; using System.Collections.Generic; +using System.Diagnostics; +using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using Microsoft.Xna.Framework.Content; using System.Threading; using CzokoŚmieciarka.MonoGameView.DataModels.GeneralModels.Models; +using Microsoft.Xna.Framework.Graphics; using MonoGameView.DataModels.Models; namespace MonoGameView.Algorithms @@ -55,23 +58,183 @@ namespace MonoGameView.Algorithms var dataToLog = Jazda(r.Item1, CopyGrid(grid), (GarbageCollector) collector.Clone()).ToList(); - + /*Oznaczenia + *0 - trawa, nie do poruszania + *10 - droga po której można się poruszać + *11 - droga po której nie można się poruszać + *20 - dom z którego można wziąć śmieci + *21 - dom z którego nie można wziąć śmieci w tym momencie + *22 - dom pusty, bez śmieci + *30 - wysypisko szkła + *31 - wysypisko plastików i metali + *32 - wysypisko odpadów organicznych + *33 - wysypisko papieru + *40 - ruch w górę + *41 - ruch w prawo + *42 - ruch w dół + *43 - ruch w lewo + *50 - zbierz śmieci + *51 - wyrzuć śmieci + */ Console.WriteLine($"Counts : {count}"); - if (r == null) return new Tuple, int, List>(new List(), 0, new List()); - return r; + using (StreamWriter writer = new StreamWriter("chuj.txt")) + { + foreach (var item in dataToLog) + { + string line = ""; + if (item.Key is MoveStep) + { + MoveStep move = (item.Key as MoveStep); + String[,] mygrid = item.Value; + switch (move.GetDirection().ToString()) + { + case "Up": + line += "40"; + break; + case "Right": + line += "41"; + break; + case "Down": + line += "42"; + break; + case "Left": + line += "43"; + break; + } + + foreach (string field in mygrid) + { + switch (field) + { + case "grass": + line += "," + "0"; + break; + case "road1": + line += "," + "10"; + break; + case "road2": + line += "," + "11"; + break; + case "house": + line += "," + "20"; + break; + case "emptyHouse": + line += "," + "22"; + break; + case "Glass": + line += "," + "30"; + break; + case "PlasticMetal": + line += "," + "31"; + break; + case "Organic": + line += "," + "32"; + break; + case "Paper": + line += "," + "33"; + break; + } + } + } + else if (item.Key is CollectStep) + { + CollectStep collect = (item.Key as CollectStep); + String[,] mygrid = item.Value; + line += "50"; + foreach (string field in mygrid) + { + switch (field) + { + case "grass": + line += "," + "0"; + break; + case "road1": + line += "," + "10"; + break; + case "road2": + line += "," + "11"; + break; + case "house": + line += "," + "20"; + break; + case "emptyHouse": + line += "," + "22"; + break; + case "Glass": + line += "," + "30"; + break; + case "PlasticMetal": + line += "," + "31"; + break; + case "Organic": + line += "," + "32"; + break; + case "Paper": + line += "," + "33"; + break; + } + } + } + else + { + SpillStep spill = (item.Key as SpillStep); + String[,] mygrid = item.Value; + line += "51"; + foreach (string field in mygrid) + { + switch (field) + { + case "grass": + line += "," + "0"; + break; + case "road1": + line += "," + "10"; + break; + case "road2": + line += "," + "11"; + break; + case "house": + line += "," + "20"; + break; + case "emptyHouse": + line += "," + "22"; + break; + case "Glass": + line += "," + "30"; + break; + case "PlasticMetal": + line += "," + "31"; + break; + case "Organic": + line += "," + "32"; + break; + case "Paper": + line += "," + "33"; + break; + } + } + + } + writer.WriteLine(line); + } + } + if (r == null) + return new Tuple, int, List>(new List(), 0, + new List()); + return r; } - public IEnumerable> Jazda(List steps, ICloneable[,] grid, GarbageCollector collector) + public IEnumerable> Jazda(List steps, ICloneable[,] grid, GarbageCollector collector) { for (int i =0;i(steps[i], minGrid); - + yield return new KeyValuePair(steps[i], minGrid); diff --git a/Trunk/MonoGameView/DataModels/Models/Steps/CollectStep.cs b/Trunk/MonoGameView/DataModels/Models/Steps/CollectStep.cs index 8660859..2075c24 100644 --- a/Trunk/MonoGameView/DataModels/Models/Steps/CollectStep.cs +++ b/Trunk/MonoGameView/DataModels/Models/Steps/CollectStep.cs @@ -22,6 +22,10 @@ namespace CzokoŚmieciarka.MonoGameView.DataModels.Models.Steps private GarbageType _typeOfGarbage; + public GarbageType GetTypeOfGarbage() + { + return _typeOfGarbage; + } public bool Invoke(IGarbageCollector _garbageCollector, ICloneable [,] grid) { diff --git a/Trunk/MonoGameView/DataModels/Models/Steps/MoveStep.cs b/Trunk/MonoGameView/DataModels/Models/Steps/MoveStep.cs index f03deb6..2975e58 100644 --- a/Trunk/MonoGameView/DataModels/Models/Steps/MoveStep.cs +++ b/Trunk/MonoGameView/DataModels/Models/Steps/MoveStep.cs @@ -20,6 +20,10 @@ namespace CzokoŚmieciarka.MonoGameView.DataModels.Models.Steps private Direction _direction; private IGarbageCollector _garbageCollector; + public Direction GetDirection() + { + return _direction; + } public bool Invoke(IGarbageCollector _garbageCollector, ICloneable [,] grid) { if(grid[_garbageCollector.Coords.X, _garbageCollector.Coords.Y] is Road1) diff --git a/Trunk/MonoGameView/DataModels/Models/Steps/SpillStep.cs b/Trunk/MonoGameView/DataModels/Models/Steps/SpillStep.cs index baef596..4aa8988 100644 --- a/Trunk/MonoGameView/DataModels/Models/Steps/SpillStep.cs +++ b/Trunk/MonoGameView/DataModels/Models/Steps/SpillStep.cs @@ -20,6 +20,10 @@ namespace CzokoŚmieciarka.MonoGameView.DataModels.Models.Steps private GarbageType _typeOfGarbage; + public GarbageType GetTypeOfGarbage() + { + return _typeOfGarbage; + } public bool Invoke(IGarbageCollector _garbageCollector, ICloneable [,] grid) { var _dump = (ADump)grid[_garbageCollector.Coords.X, _garbageCollector.Coords.Y];