From 0b534d67b3be20b0cb051c7406901fe43e6d11c5 Mon Sep 17 00:00:00 2001 From: ryuga4 Date: Mon, 22 Apr 2019 14:38:11 +0200 Subject: [PATCH] naprawione --- Trunk/MonoGameView/Algorithms/DFS.cs | 145 ++++----------------------- Trunk/MonoGameView/Game1.cs | 12 --- 2 files changed, 17 insertions(+), 140 deletions(-) diff --git a/Trunk/MonoGameView/Algorithms/DFS.cs b/Trunk/MonoGameView/Algorithms/DFS.cs index 10ae788..fd67bfc 100644 --- a/Trunk/MonoGameView/Algorithms/DFS.cs +++ b/Trunk/MonoGameView/Algorithms/DFS.cs @@ -1,17 +1,17 @@ -<<<<<<< HEAD:Trunk/Components/CzokoŚmieciarka.AI_Naive/DFS.cs -using CzokoŚmieciarka.DataModels.Enums; -using CzokoŚmieciarka.DataModels.Interfaces; -using CzokoŚmieciarka.DataModels.Interfaces.GarbageCollector; -using CzokoŚmieciarka.DataModels.Interfaces.TrashCans; -using CzokoŚmieciarka.DataModels.Models; -using CzokoŚmieciarka.DataModels.Models.Steps; +using CzokoŚmieciarka.MonoGameView.DataModels.Enums; +using CzokoŚmieciarka.MonoGameView.DataModels.Interfaces; +using CzokoŚmieciarka.MonoGameView.DataModels.Interfaces.GarbageCollector; +using CzokoŚmieciarka.MonoGameView.DataModels.Interfaces.TrashCans; +using CzokoŚmieciarka.MonoGameView.DataModels.Models; +using CzokoŚmieciarka.MonoGameView.DataModels.Models.Steps; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Microsoft.Xna.Framework.Content; -namespace CzokoŚmieciarka.AI_Naive +namespace CzokoŚmieciarka.MonoGameView.Algorithms { public class DFS { @@ -21,14 +21,15 @@ namespace CzokoŚmieciarka.AI_Naive int count = 0; - public List BestPath(AGarbageCollector collector, object[,] grid) + public List BestPath(ContentManager content, AGarbageCollector collector, object[,] grid) { - var r=Search(collector, grid, 0).Key; + var r=Search(content, collector, grid, 0).Key; Console.WriteLine(count); + if (r == null) return new List(); return r; } - List PossibleSteps(AGarbageCollector collector, object[,] grid) + List PossibleSteps(ContentManager content, AGarbageCollector collector, object[,] grid) { @@ -43,7 +44,7 @@ namespace CzokoŚmieciarka.AI_Naive var filteredMoveSteps = new List(); foreach (var item in moveSteps) { - var copyCollector = (AGarbageCollector)collector.Clone(); + var copyCollector = (AGarbageCollector)collector.Clone(content); var copyGrid = (object[,])grid.Clone(); try { @@ -64,26 +65,21 @@ namespace CzokoŚmieciarka.AI_Naive return result; } - KeyValuePair, int> Search(AGarbageCollector collector, object[,] grid, int length) + KeyValuePair, int> Search(ContentManager content, AGarbageCollector collector, object[,] grid, int length) { count++; if (length > 40) return new KeyValuePair, int>(new List(), length); - var possibleSteps = PossibleSteps(collector, grid); + var possibleSteps = PossibleSteps(content, collector, grid); foreach (var item in possibleSteps) { - var copyCollector = (AGarbageCollector)collector.Clone(); + var copyCollector = (AGarbageCollector)collector.Clone(content); var copyGrid = (object[,])grid.Clone(); - - - - - //if (copyGrid[copyCollector.Coords.X, copyCollector.Coords.Y] is IRoad1) copyGrid[copyCollector.Coords.X, copyCollector.Coords.Y] = new Road2(); item.Invoke(copyCollector, copyGrid); - var s = Search(copyCollector, copyGrid, length + 1); + var s = Search(content, copyCollector, copyGrid, length + 1); if (s.Key != null) { s.Key.Insert(0, item); @@ -108,110 +104,3 @@ namespace CzokoŚmieciarka.AI_Naive } } } -======= -using CzokoŚmieciarka.MonoGameView.DataModels.Enums; -using CzokoŚmieciarka.MonoGameView.DataModels.Interfaces; -using CzokoŚmieciarka.MonoGameView.DataModels.Interfaces.GarbageCollector; -using CzokoŚmieciarka.MonoGameView.DataModels.Interfaces.TrashCans; -using CzokoŚmieciarka.MonoGameView.DataModels.Models; -using CzokoŚmieciarka.MonoGameView.DataModels.Models.Steps; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Microsoft.Xna.Framework.Content; - -namespace CzokoŚmieciarka.MonoGameView.Algorithms -{ - public class DFS - { - public DFS() - { - } - int count = 0; - - - public List BestPath(ContentManager content, AGarbageCollector collector, object[,] grid) - { - var r=Search(content, collector, grid, 0).Key; - Console.WriteLine(count); - return r; - } - - List PossibleSteps(ContentManager content, AGarbageCollector collector, object[,] grid) - { - - - var result = new List(); - var moveSteps = new List() - { - new MoveStep(Direction.Up), - new MoveStep(Direction.Down), - new MoveStep(Direction.Left), - new MoveStep(Direction.Right) - }; - var filteredMoveSteps = new List(); - foreach (var item in moveSteps) - { - var copyCollector = (AGarbageCollector)collector.Clone(content); - var copyGrid = (object[,])grid.Clone(); - try - { - item.Invoke(copyCollector, grid); - var gcx = copyCollector.Coords.X; - var gcy = copyCollector.Coords.Y; - if (grid[gcx, gcy] is IRoad1 || grid[gcx, gcy] is IGarbageLocalization || grid[gcx, gcy] is ADump) - { - result.Add(item); - } - } - catch (Exception e) - { - - } - } - - return result; - } - - KeyValuePair, int> Search(ContentManager content, AGarbageCollector collector, object[,] grid, int length) - { - count++; - if (length > 40) return new KeyValuePair, int>(new List(), length); - var possibleSteps = PossibleSteps(content, collector, grid); - - foreach (var item in possibleSteps) - { - var copyCollector = (AGarbageCollector)collector.Clone(content); - var copyGrid = (object[,])grid.Clone(); - - - //if (copyGrid[copyCollector.Coords.X, copyCollector.Coords.Y] is IRoad1) copyGrid[copyCollector.Coords.X, copyCollector.Coords.Y] = new Road2(); - item.Invoke(copyCollector, copyGrid); - var s = Search(content, copyCollector, copyGrid, length + 1); - if (s.Key != null) - { - s.Key.Insert(0, item); - return s; - } - } - return new KeyValuePair, int>(null, length); - /*var min = int.MaxValue; - var min_index = 0; - for (int i = 0; i < mapped.Count; i++) - { - if (mapped.ElementAt(i).Value <= min) - { - min = mapped.ElementAt(i).Value; - min_index = i; - } - } - return mapped.ElementAt(min_index); - */ - - - } - } -} ->>>>>>> c3875873aa1c65d56eefe5ebef2127852fe69b7a:Trunk/MonoGameView/Algorithms/DFS.cs diff --git a/Trunk/MonoGameView/Game1.cs b/Trunk/MonoGameView/Game1.cs index 3787078..1426aba 100644 --- a/Trunk/MonoGameView/Game1.cs +++ b/Trunk/MonoGameView/Game1.cs @@ -53,19 +53,7 @@ namespace CzokoŚmieciarka.MonoGameView { // TODO: Add your initialization logic here roadPos = new Vector2(0, 0); -<<<<<<< HEAD - timer = 5f; - for (int x=0;x<10;x++) - { - for (int y=0;y<10;y++) - { - if (x % 2 == 0 || y % 2 == 0) grid[x, y] = new Road1(); - else grid[x, y] = null; - } - } -======= timer = 0.2f; ->>>>>>> c3875873aa1c65d56eefe5ebef2127852fe69b7a mapLoader.Load(out size,out grid,"map.xml"); collector = new GarbageCollector(new Coords(0, 0), new List(), size, size);