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>();
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<IStep>()
{
@ -141,15 +141,15 @@ namespace MonoGameView.Algorithms
var nodes2 = new List<Tuple<List<IStep>, 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))
&&

View File

@ -126,8 +126,8 @@ namespace CzokoŚmieciarka.MonoGameView.Algorithms
KeyValuePair<List<IStep>, 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<List<IStep>, int>(null,length);
count++;
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 System;
namespace CzokoŚmieciarka.MonoGameView.DataModels.Interfaces
{
public interface IStep
{
bool Invoke(IGarbageCollector collector, object [,] grid);
bool Invoke(IGarbageCollector collector, ICloneable [,] grid);
}
}

View File

@ -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];

View File

@ -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)

View File

@ -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];

View File

@ -7,6 +7,7 @@ using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using CzokoŚmieciarka.MonoGameView.Algorithms;
using MonoGameView.DataModels;
@ -32,7 +33,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<IStep> steps;
GarbageCollector collector;
@ -60,7 +61,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<GarbageCollectorContainer>()
{
new GarbageCollectorContainer(
@ -89,12 +90,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 +132,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 +142,7 @@ namespace CzokoŚmieciarka.MonoGameView
steps.First().Invoke(collector, grid);
steps.RemoveAt(0);
}
}*/
}
// TODO: Add your update logic here
@ -171,7 +172,7 @@ namespace CzokoŚmieciarka.MonoGameView
collector.Draw(spriteBatch, size);
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();
// TODO: Add your drawing code here

View File

@ -41,6 +41,9 @@
<PropertyGroup>
<ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>
<PropertyGroup>
<StartupObject />
</PropertyGroup>
<ItemGroup>
<Compile Include="Algorithms\BFS.cs" />
<Compile Include="Algorithms\DFS.cs" />
@ -88,6 +91,9 @@
<Compile Include="Properties\AssemblyInfo.cs" />
</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">
<HintPath>$(MonoGameInstallDirectory)\MonoGame\v3.0\Assemblies\Windows\MonoGame.Framework.dll</HintPath>
</Reference>
@ -101,6 +107,7 @@
<MonoGameContentReference Include="Content\Content.mgcb" />
<None Include="app.config" />
<None Include="app.manifest" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup />
<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>