This commit is contained in:
ryuga4 2019-05-05 17:54:12 +02:00 committed by Michał Dulski
parent e96126a917
commit 6f81261072
10 changed files with 41 additions and 28 deletions

View File

@ -55,8 +55,8 @@ namespace MonoGameView.Algorithms
var result = new List<IStep>(); var result = new List<IStep>();
var itemdupa = grid[collector.Coords.X, collector.Coords.Y];
if (!(collector.TrashContainers.Any(x => x.FillPercent > 0) && grid[collector.Coords.X, collector.Coords.Y] is ADump)) if (!(itemdupa is House && collector.TrashContainers.All(i=>i.FillPercent==0)))
{ {
var moveSteps = new List<IStep>() var moveSteps = new List<IStep>()
{ {
@ -141,15 +141,15 @@ namespace MonoGameView.Algorithms
var nodes2 = new List<Tuple<List<IStep>, GarbageCollector, ICloneable[,]>>(); var nodes2 = new List<Tuple<List<IStep>, GarbageCollector, ICloneable[,]>>();
foreach (var item in nodes) foreach (var item in nodes)
{ {
Thread.Sleep(100); // Thread.Sleep(100);
this.Collector.Coords = item.Item2.Coords; /*this.Collector.Coords = item.Item2.Coords;
for (int x = 0; x < item.Item3.GetLength(0); x++) for (int x = 0; x < item.Item3.GetLength(0); x++)
{ {
for (int y = 0; y < item.Item3.GetLength(1); y++) for (int y = 0; y < item.Item3.GetLength(1); y++)
{ {
this.Grid[x, y] = item.Item3[x, 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)) if (Houses.All(c => (item.Item3[c.X, c.Y] as IGarbageLocalization).TrashCans.All(j => j.FillPercent == 0.0))
&& &&

View File

@ -126,8 +126,8 @@ namespace CzokoŚmieciarka.MonoGameView.Algorithms
KeyValuePair<List<IStep>, int> Search(ContentManager content, GarbageCollector collector, ICloneable[,] grid, int length) KeyValuePair<List<IStep>, int> Search(ContentManager content, GarbageCollector collector, ICloneable[,] grid, int length)
{ {
//Thread.Sleep(1); //Thread.Sleep(100);
this.Collector.Coords = collector.Coords; /*this.Collector.Coords = collector.Coords;
for (int x = 0; x < grid.GetLength(0); x++) for (int x = 0; x < grid.GetLength(0); x++)
{ {
for (int y = 0; y < grid.GetLength(1); y++) 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]; this.Grid[x, y] = grid[x, y];
} }
} }
*/
Console.WriteLine(collector.HouseCounter); Console.WriteLine(collector.HouseCounter);
if (collector.Counter> 15 || length > 100) if (collector.Counter> 100 || length > 100)
return new KeyValuePair<List<IStep>, int>(null,length); return new KeyValuePair<List<IStep>, int>(null,length);
count++; count++;
if (Houses.All(c => (grid[c.X, c.Y] as IGarbageLocalization).TrashCans.All(j => j.FillPercent == 0.0)) if (Houses.All(c => (grid[c.X, c.Y] as IGarbageLocalization).TrashCans.All(j => j.FillPercent == 0.0))

View File

@ -1,9 +1,10 @@
using CzokoŚmieciarka.MonoGameView.DataModels.Interfaces.GarbageCollector; using CzokoŚmieciarka.MonoGameView.DataModels.Interfaces.GarbageCollector;
using System;
namespace CzokoŚmieciarka.MonoGameView.DataModels.Interfaces namespace CzokoŚmieciarka.MonoGameView.DataModels.Interfaces
{ {
public interface IStep public interface IStep
{ {
bool Invoke(IGarbageCollector collector, object [,] grid); bool Invoke(IGarbageCollector collector, ICloneable [,] grid);
} }
} }

View File

@ -28,7 +28,7 @@ namespace CzokoŚmieciarka.MonoGameView.DataModels.Models
} }
public object Clone() public object Clone()
{ {
return new House((Coords) Coords.Clone(), TrashCans.Select(x => (TrashCan) x.Clone()).ToList()); return new House((Coords) Coords.Clone(), TrashCans.Select(x => (TrashCan) x.Clone()).ToList());
} }

View File

@ -21,7 +21,7 @@ namespace CzokoŚmieciarka.MonoGameView.DataModels.Models.Steps
private GarbageType _typeOfGarbage; 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]; var _garbageLocalization = (IGarbageLocalization) grid[_garbageCollector.Coords.X, _garbageCollector.Coords.Y];

View File

@ -20,7 +20,7 @@ namespace CzokoŚmieciarka.MonoGameView.DataModels.Models.Steps
private Direction _direction; private Direction _direction;
private IGarbageCollector _garbageCollector; 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) 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)); 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) switch (_direction)
{ {
case Direction.Up: case Direction.Up:
pass = _garbageCollector.MoveDown(); pass = _garbageCollector.MoveUp();
break; break;
case Direction.Down: case Direction.Down:
pass = _garbageCollector.MoveRight(); pass = _garbageCollector.MoveDown();
break; break;
case Direction.Left: case Direction.Left:
pass = _garbageCollector.MoveUp(); pass = _garbageCollector.MoveLeft();
break; break;
case Direction.Right: case Direction.Right:
pass = _garbageCollector.MoveLeft(); pass = _garbageCollector.MoveRight();
break; break;
} }
if (pass) if (pass)

View File

@ -20,7 +20,7 @@ namespace CzokoŚmieciarka.MonoGameView.DataModels.Models.Steps
private GarbageType _typeOfGarbage; 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]; var _dump = (ADump)grid[_garbageCollector.Coords.X, _garbageCollector.Coords.Y];

View File

@ -7,6 +7,7 @@ using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Input;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Linq; using System.Linq;
using CzokoŚmieciarka.MonoGameView.Algorithms; using CzokoŚmieciarka.MonoGameView.Algorithms;
using MonoGameView.DataModels; using MonoGameView.DataModels;
@ -32,7 +33,7 @@ namespace CzokoŚmieciarka.MonoGameView
MapLoader mapLoader = new MapLoader(); MapLoader mapLoader = new MapLoader();
Vector2 roadPos; Vector2 roadPos;
float timer; float timer;
const float TIMER = 1f; const float TIMER = 0.1f;
int stepN; int stepN;
List<IStep> steps; List<IStep> steps;
GarbageCollector collector; GarbageCollector collector;
@ -60,7 +61,7 @@ namespace CzokoŚmieciarka.MonoGameView
// TODO: Add your initialization logic here // TODO: Add your initialization logic here
timer = 0f; timer = 0f;
mapLoader.Load(out size,out grid,"map1.xml"); mapLoader.Load(out size,out grid,"map2.xml");
var containers = new List<GarbageCollectorContainer>() var containers = new List<GarbageCollectorContainer>()
{ {
new GarbageCollectorContainer( new GarbageCollectorContainer(
@ -89,12 +90,12 @@ namespace CzokoŚmieciarka.MonoGameView
stepN = 0; stepN = 0;
var dfs = new BFS(collector,grid); var dfs = new DFS(collector,grid);
//steps = dfs.BestPath(Content, collector, grid); steps = dfs.BestPath(Content, collector, grid);
new Thread(delegate() { //new Thread(delegate() {
var x = dfs.BestPath(Content, collector, grid); // var x = dfs.BestPath(Content, collector, grid);
}).Start(); //}).Start();
base.Initialize(); base.Initialize();
} }
@ -131,7 +132,7 @@ namespace CzokoŚmieciarka.MonoGameView
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
Exit(); Exit();
/*var elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds; var elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds;
timer -= elapsed; timer -= elapsed;
if (timer<0) if (timer<0)
{ {
@ -141,7 +142,7 @@ namespace CzokoŚmieciarka.MonoGameView
steps.First().Invoke(collector, grid); steps.First().Invoke(collector, grid);
steps.RemoveAt(0); steps.RemoveAt(0);
} }
}*/ }
// TODO: Add your update logic here // TODO: Add your update logic here
@ -171,7 +172,7 @@ namespace CzokoŚmieciarka.MonoGameView
collector.Draw(spriteBatch, size); collector.Draw(spriteBatch, size);
Display(new Dictionary<string, string>(){["Dupa"] = "123", ["Stefan"] = "555", ["Dupa1"] = "123", ["Stefan1"] = "555", ["Dupa2"] = "123", ["Stefan2"] = "555"}); Display(new Dictionary<string, string>(){["Dupa"] = "123", ["Stefan"] = "555", ["Dupa1"] = "123", ["Stefan1"] = "555", ["Dupa2"] = "123", ["Stefan2"] = "555"});
Debug.WriteLine("cycki dupa, chuj biskupa");
spriteBatch.End(); spriteBatch.End();
// TODO: Add your drawing code here // TODO: Add your drawing code here

View File

@ -41,6 +41,9 @@
<PropertyGroup> <PropertyGroup>
<ApplicationManifest>app.manifest</ApplicationManifest> <ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup> </PropertyGroup>
<PropertyGroup>
<StartupObject />
</PropertyGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Algorithms\BFS.cs" /> <Compile Include="Algorithms\BFS.cs" />
<Compile Include="Algorithms\DFS.cs" /> <Compile Include="Algorithms\DFS.cs" />
@ -88,6 +91,9 @@
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Reference Include="C5, Version=2.5.0.0, Culture=neutral, PublicKeyToken=282361b99ded7e8e, processorArchitecture=MSIL">
<HintPath>..\packages\C5.2.5.3\lib\net45\C5.dll</HintPath>
</Reference>
<Reference Include="MonoGame.Framework"> <Reference Include="MonoGame.Framework">
<HintPath>$(MonoGameInstallDirectory)\MonoGame\v3.0\Assemblies\Windows\MonoGame.Framework.dll</HintPath> <HintPath>$(MonoGameInstallDirectory)\MonoGame\v3.0\Assemblies\Windows\MonoGame.Framework.dll</HintPath>
</Reference> </Reference>
@ -101,6 +107,7 @@
<MonoGameContentReference Include="Content\Content.mgcb" /> <MonoGameContentReference Include="Content\Content.mgcb" />
<None Include="app.config" /> <None Include="app.config" />
<None Include="app.manifest" /> <None Include="app.manifest" />
<None Include="packages.config" />
</ItemGroup> </ItemGroup>
<ItemGroup /> <ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="C5" version="2.5.3" targetFramework="net461" />
</packages>