dfs dziala prawie
@ -41,6 +41,7 @@
|
|||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="DFS.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
109
Trunk/Components/CzokoŚmieciarka.AI_Naive/DFS.cs
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
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 System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace CzokoŚmieciarka.AI_Naive
|
||||||
|
{
|
||||||
|
public class DFS
|
||||||
|
{
|
||||||
|
public DFS()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
int count = 0;
|
||||||
|
|
||||||
|
|
||||||
|
public List<IStep> BestPath(AGarbageCollector collector, object[,] grid)
|
||||||
|
{
|
||||||
|
var r=Search(collector, grid, 0).Key;
|
||||||
|
Console.WriteLine(count);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<IStep> PossibleSteps(AGarbageCollector collector, object[,] grid)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
var result = new List<IStep>();
|
||||||
|
var moveSteps = new List<IStep>()
|
||||||
|
{
|
||||||
|
new MoveStep(Direction.Up),
|
||||||
|
new MoveStep(Direction.Down),
|
||||||
|
new MoveStep(Direction.Left),
|
||||||
|
new MoveStep(Direction.Right)
|
||||||
|
};
|
||||||
|
var filteredMoveSteps = new List<IStep>();
|
||||||
|
foreach (var item in moveSteps)
|
||||||
|
{
|
||||||
|
var copyCollector = (AGarbageCollector)collector.Clone();
|
||||||
|
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<List<IStep>, int> Search(AGarbageCollector collector, object[,] grid, int length)
|
||||||
|
{
|
||||||
|
count++;
|
||||||
|
if (length > 40) return new KeyValuePair<List<IStep>, int>(new List<IStep>(), length);
|
||||||
|
var possibleSteps = PossibleSteps(collector, grid);
|
||||||
|
|
||||||
|
foreach (var item in possibleSteps)
|
||||||
|
{
|
||||||
|
var copyCollector = (AGarbageCollector)collector.Clone();
|
||||||
|
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);
|
||||||
|
if (s.Key != null)
|
||||||
|
{
|
||||||
|
s.Key.Insert(0, item);
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new KeyValuePair<List<IStep>, 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);
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -51,6 +51,8 @@
|
|||||||
<Compile Include="Interfaces\Garbage\AGarbage.cs" />
|
<Compile Include="Interfaces\Garbage\AGarbage.cs" />
|
||||||
<Compile Include="Interfaces\Garbage\IGarbage.cs" />
|
<Compile Include="Interfaces\Garbage\IGarbage.cs" />
|
||||||
<Compile Include="Interfaces\IRoad.cs" />
|
<Compile Include="Interfaces\IRoad.cs" />
|
||||||
|
<Compile Include="Interfaces\IRoad1.cs" />
|
||||||
|
<Compile Include="Interfaces\IRoad2.cs" />
|
||||||
<Compile Include="Interfaces\TrashCans\ADump.cs" />
|
<Compile Include="Interfaces\TrashCans\ADump.cs" />
|
||||||
<Compile Include="Interfaces\IGarbageLocalization.cs" />
|
<Compile Include="Interfaces\IGarbageLocalization.cs" />
|
||||||
<Compile Include="Interfaces\ITypeOfGarbage.cs" />
|
<Compile Include="Interfaces\ITypeOfGarbage.cs" />
|
||||||
@ -60,6 +62,8 @@
|
|||||||
<Compile Include="Interfaces\IStep.cs" />
|
<Compile Include="Interfaces\IStep.cs" />
|
||||||
<Compile Include="Models\Coords.cs" />
|
<Compile Include="Models\Coords.cs" />
|
||||||
<Compile Include="Models\Map.cs" />
|
<Compile Include="Models\Map.cs" />
|
||||||
|
<Compile Include="Models\Road1.cs" />
|
||||||
|
<Compile Include="Models\Road2.cs" />
|
||||||
<Compile Include="Models\Steps\CollectStep.cs" />
|
<Compile Include="Models\Steps\CollectStep.cs" />
|
||||||
<Compile Include="Models\Steps\MoveStep.cs" />
|
<Compile Include="Models\Steps\MoveStep.cs" />
|
||||||
<Compile Include="Models\Steps\SpillStep.cs" />
|
<Compile Include="Models\Steps\SpillStep.cs" />
|
||||||
|
@ -9,7 +9,7 @@ using CzokoŚmieciarka.DataModels.Models;
|
|||||||
|
|
||||||
namespace CzokoŚmieciarka.DataModels.Interfaces.GarbageCollector
|
namespace CzokoŚmieciarka.DataModels.Interfaces.GarbageCollector
|
||||||
{
|
{
|
||||||
public abstract class AGarbageCollector : IGarbageCollector
|
public abstract class AGarbageCollector : IGarbageCollector, ICloneable
|
||||||
{
|
{
|
||||||
public AGarbageCollector(Coords startPosition, IEnumerable<AGarbageCollectorContainer> trashContainers, int columns, int rows)
|
public AGarbageCollector(Coords startPosition, IEnumerable<AGarbageCollectorContainer> trashContainers, int columns, int rows)
|
||||||
{
|
{
|
||||||
@ -57,9 +57,9 @@ namespace CzokoŚmieciarka.DataModels.Interfaces.GarbageCollector
|
|||||||
Coords.X += 1;
|
Coords.X += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public object Clone()
|
public virtual object Clone()
|
||||||
{
|
{
|
||||||
return this.MemberwiseClone();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<AGarbageCollectorContainer> TrashContainers { get; }
|
public IEnumerable<AGarbageCollectorContainer> TrashContainers { get; }
|
||||||
|
@ -0,0 +1,12 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace CzokoŚmieciarka.DataModels.Interfaces
|
||||||
|
{
|
||||||
|
public interface IRoad1
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace CzokoŚmieciarka.DataModels.Interfaces
|
||||||
|
{
|
||||||
|
public interface IRoad2
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +1,9 @@
|
|||||||
namespace CzokoŚmieciarka.DataModels.Interfaces
|
using CzokoŚmieciarka.DataModels.Interfaces.GarbageCollector;
|
||||||
|
|
||||||
|
namespace CzokoŚmieciarka.DataModels.Interfaces
|
||||||
{
|
{
|
||||||
public interface IStep
|
public interface IStep
|
||||||
{
|
{
|
||||||
void Invoke();
|
void Invoke(IGarbageCollector collector, object [,] grid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,5 +35,20 @@ namespace CzokoŚmieciarka.DataModels.Models
|
|||||||
{
|
{
|
||||||
return new Coords(a.X - b.X, a.Y - b.Y);
|
return new Coords(a.X - b.X, a.Y - b.Y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return base.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool Equals(object obj)
|
||||||
|
{
|
||||||
|
return base.Equals(obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override int GetHashCode()
|
||||||
|
{
|
||||||
|
return base.GetHashCode();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
13
Trunk/Components/CzokoŚmieciarka.DataModels/Models/Road1.cs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
using CzokoŚmieciarka.DataModels.Interfaces;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace CzokoŚmieciarka.DataModels.Models
|
||||||
|
{
|
||||||
|
public class Road1 :IRoad1
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
13
Trunk/Components/CzokoŚmieciarka.DataModels/Models/Road2.cs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
using CzokoŚmieciarka.DataModels.Interfaces;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace CzokoŚmieciarka.DataModels.Models
|
||||||
|
{
|
||||||
|
public class Road2 : IRoad2
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
@ -10,19 +10,16 @@ namespace CzokoŚmieciarka.DataModels.Models.Steps
|
|||||||
{
|
{
|
||||||
public class CollectStep : IStep
|
public class CollectStep : IStep
|
||||||
{
|
{
|
||||||
public CollectStep(IGarbageCollector garbageCollector, IGarbageLocalization garbageLocalization, ITypeOfGarbage typeOfGarbage)
|
public CollectStep(ITypeOfGarbage typeOfGarbage)
|
||||||
{
|
{
|
||||||
this._garbageCollector = garbageCollector;
|
|
||||||
this._garbageLocalization = garbageLocalization;
|
|
||||||
this._typeOfGarbage = typeOfGarbage;
|
this._typeOfGarbage = typeOfGarbage;
|
||||||
}
|
}
|
||||||
|
|
||||||
private IGarbageCollector _garbageCollector;
|
|
||||||
private ITypeOfGarbage _typeOfGarbage;
|
private ITypeOfGarbage _typeOfGarbage;
|
||||||
private IGarbageLocalization _garbageLocalization;
|
|
||||||
|
|
||||||
public void Invoke()
|
public void Invoke(IGarbageCollector garbageCollector, object [,] grid)
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
if(_garbageCollector.Coords != _garbageLocalization.Coords)
|
if(_garbageCollector.Coords != _garbageLocalization.Coords)
|
||||||
throw new WrongPositionException("Śmieciarka nie jest w miejscu oderbania śmieci");
|
throw new WrongPositionException("Śmieciarka nie jest w miejscu oderbania śmieci");
|
||||||
|
|
||||||
@ -33,6 +30,7 @@ namespace CzokoŚmieciarka.DataModels.Models.Steps
|
|||||||
throw new TrashContainerNotFound($"Nie znaleziono kontenera na {_typeOfGarbage.GarbageType}.");
|
throw new TrashContainerNotFound($"Nie znaleziono kontenera na {_typeOfGarbage.GarbageType}.");
|
||||||
|
|
||||||
_garbageCollector.TrashContainers.First(t => t.TypeOfGarbage == _typeOfGarbage).AddGarbage(garbage);
|
_garbageCollector.TrashContainers.First(t => t.TypeOfGarbage == _typeOfGarbage).AddGarbage(garbage);
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,17 +11,18 @@ namespace CzokoŚmieciarka.DataModels.Models.Steps
|
|||||||
{
|
{
|
||||||
public class MoveStep : IStep
|
public class MoveStep : IStep
|
||||||
{
|
{
|
||||||
public MoveStep(Direction direction, IGarbageCollector garbageCollector)
|
public MoveStep(Direction direction)
|
||||||
{
|
{
|
||||||
this._garbageCollector = garbageCollector;
|
|
||||||
this._direction = direction;
|
this._direction = direction;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Direction _direction;
|
private Direction _direction;
|
||||||
private IGarbageCollector _garbageCollector;
|
private IGarbageCollector _garbageCollector;
|
||||||
|
|
||||||
public void Invoke()
|
public void Invoke(IGarbageCollector _garbageCollector, object[,] grid)
|
||||||
{
|
{
|
||||||
|
if(grid[_garbageCollector.Coords.X, _garbageCollector.Coords.Y] is Road1)
|
||||||
|
grid[_garbageCollector.Coords.X, _garbageCollector.Coords.Y] = new Road2();
|
||||||
switch (_direction)
|
switch (_direction)
|
||||||
{
|
{
|
||||||
case Direction.Up: _garbageCollector.MoveUp(); break;
|
case Direction.Up: _garbageCollector.MoveUp(); break;
|
||||||
|
@ -10,19 +10,15 @@ namespace CzokoŚmieciarka.DataModels.Models.Steps
|
|||||||
{
|
{
|
||||||
public class SpillStep : IStep
|
public class SpillStep : IStep
|
||||||
{
|
{
|
||||||
public SpillStep(IGarbageCollector garbageCollector, ADump dump, ITypeOfGarbage typeOfGarbage)
|
public SpillStep(ITypeOfGarbage typeOfGarbage)
|
||||||
{
|
{
|
||||||
this._garbageCollector = garbageCollector;
|
|
||||||
this._dump = dump;
|
|
||||||
this._typeOfGarbage = typeOfGarbage;
|
this._typeOfGarbage = typeOfGarbage;
|
||||||
}
|
}
|
||||||
|
|
||||||
private IGarbageCollector _garbageCollector;
|
|
||||||
private ADump _dump;
|
|
||||||
private ITypeOfGarbage _typeOfGarbage;
|
private ITypeOfGarbage _typeOfGarbage;
|
||||||
|
|
||||||
public void Invoke()
|
public void Invoke(IGarbageCollector garbageCollector, object [,] grid)
|
||||||
{
|
{/*
|
||||||
if(_garbageCollector.Coords != _dump.Coords)
|
if(_garbageCollector.Coords != _dump.Coords)
|
||||||
throw new WrongPositionException("Śmieciarka nie na terenie podanego wyspiska");
|
throw new WrongPositionException("Śmieciarka nie na terenie podanego wyspiska");
|
||||||
|
|
||||||
@ -36,7 +32,7 @@ namespace CzokoŚmieciarka.DataModels.Models.Steps
|
|||||||
.Select(t => t.TakeGarbage())
|
.Select(t => t.TakeGarbage())
|
||||||
.Aggregate((a, b) => a + b);
|
.Aggregate((a, b) => a + b);
|
||||||
|
|
||||||
_dump.AddGarbage(garbage);
|
_dump.AddGarbage(garbage);*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
#---------------------------------- Content ---------------------------------#
|
#---------------------------------- Content ---------------------------------#
|
||||||
|
|
||||||
#begin intersection.png
|
#begin collector.png
|
||||||
/importer:TextureImporter
|
/importer:TextureImporter
|
||||||
/processor:TextureProcessor
|
/processor:TextureProcessor
|
||||||
/processorParam:ColorKeyColor=255,0,255,255
|
/processorParam:ColorKeyColor=255,0,255,255
|
||||||
@ -23,9 +23,9 @@
|
|||||||
/processorParam:ResizeToPowerOfTwo=False
|
/processorParam:ResizeToPowerOfTwo=False
|
||||||
/processorParam:MakeSquare=False
|
/processorParam:MakeSquare=False
|
||||||
/processorParam:TextureFormat=Color
|
/processorParam:TextureFormat=Color
|
||||||
/build:intersection.png
|
/build:collector.png
|
||||||
|
|
||||||
#begin road.png
|
#begin grass.png
|
||||||
/importer:TextureImporter
|
/importer:TextureImporter
|
||||||
/processor:TextureProcessor
|
/processor:TextureProcessor
|
||||||
/processorParam:ColorKeyColor=255,0,255,255
|
/processorParam:ColorKeyColor=255,0,255,255
|
||||||
@ -35,5 +35,41 @@
|
|||||||
/processorParam:ResizeToPowerOfTwo=False
|
/processorParam:ResizeToPowerOfTwo=False
|
||||||
/processorParam:MakeSquare=False
|
/processorParam:MakeSquare=False
|
||||||
/processorParam:TextureFormat=Color
|
/processorParam:TextureFormat=Color
|
||||||
/build:road.png
|
/build:grass.png
|
||||||
|
|
||||||
|
#begin house.png
|
||||||
|
/importer:TextureImporter
|
||||||
|
/processor:TextureProcessor
|
||||||
|
/processorParam:ColorKeyColor=255,0,255,255
|
||||||
|
/processorParam:ColorKeyEnabled=True
|
||||||
|
/processorParam:GenerateMipmaps=False
|
||||||
|
/processorParam:PremultiplyAlpha=True
|
||||||
|
/processorParam:ResizeToPowerOfTwo=False
|
||||||
|
/processorParam:MakeSquare=False
|
||||||
|
/processorParam:TextureFormat=Color
|
||||||
|
/build:house.png
|
||||||
|
|
||||||
|
#begin road1.png
|
||||||
|
/importer:TextureImporter
|
||||||
|
/processor:TextureProcessor
|
||||||
|
/processorParam:ColorKeyColor=255,0,255,255
|
||||||
|
/processorParam:ColorKeyEnabled=True
|
||||||
|
/processorParam:GenerateMipmaps=False
|
||||||
|
/processorParam:PremultiplyAlpha=True
|
||||||
|
/processorParam:ResizeToPowerOfTwo=False
|
||||||
|
/processorParam:MakeSquare=False
|
||||||
|
/processorParam:TextureFormat=Color
|
||||||
|
/build:road1.png
|
||||||
|
|
||||||
|
#begin road2.png
|
||||||
|
/importer:TextureImporter
|
||||||
|
/processor:TextureProcessor
|
||||||
|
/processorParam:ColorKeyColor=255,0,255,255
|
||||||
|
/processorParam:ColorKeyEnabled=True
|
||||||
|
/processorParam:GenerateMipmaps=False
|
||||||
|
/processorParam:PremultiplyAlpha=True
|
||||||
|
/processorParam:ResizeToPowerOfTwo=False
|
||||||
|
/processorParam:MakeSquare=False
|
||||||
|
/processorParam:TextureFormat=Color
|
||||||
|
/build:road2.png
|
||||||
|
|
||||||
|
BIN
Trunk/MonoGameView/Content/collector.png
Normal file
After Width: | Height: | Size: 369 B |
Before Width: | Height: | Size: 59 KiB |
BIN
Trunk/MonoGameView/Content/grass.png
Normal file
After Width: | Height: | Size: 184 B |
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 420 B |
Before Width: | Height: | Size: 3.1 KiB |
Before Width: | Height: | Size: 3.0 KiB |
Before Width: | Height: | Size: 180 B After Width: | Height: | Size: 180 B |
BIN
Trunk/MonoGameView/Content/road2.png
Normal file
After Width: | Height: | Size: 193 B |
@ -1,9 +1,17 @@
|
|||||||
using Microsoft.Xna.Framework;
|
using CzokoŚmieciarka.AI_Naive;
|
||||||
|
using CzokoŚmieciarka.DataModels.Interfaces;
|
||||||
|
using CzokoŚmieciarka.DataModels.Interfaces.GarbageCollector;
|
||||||
|
using CzokoŚmieciarka.DataModels.Interfaces.TrashCans;
|
||||||
|
using CzokoŚmieciarka.DataModels.Models;
|
||||||
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
using Microsoft.Xna.Framework.Input;
|
using Microsoft.Xna.Framework.Input;
|
||||||
|
using MonoGameView;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace MonoGameView
|
namespace CzokoŚmieciarka.MonoGameView
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This is the main type for your game.
|
/// This is the main type for your game.
|
||||||
@ -12,8 +20,16 @@ namespace MonoGameView
|
|||||||
{
|
{
|
||||||
GraphicsDeviceManager graphics;
|
GraphicsDeviceManager graphics;
|
||||||
SpriteBatch spriteBatch;
|
SpriteBatch spriteBatch;
|
||||||
Texture2D road;
|
Texture2D road1;
|
||||||
|
Texture2D road2;
|
||||||
|
Texture2D grass;
|
||||||
Vector2 roadPos;
|
Vector2 roadPos;
|
||||||
|
float timer;
|
||||||
|
const float TIMER = 0.2f;
|
||||||
|
int stepN;
|
||||||
|
List<IStep> steps;
|
||||||
|
GarbageCollector collector;
|
||||||
|
object[,] grid = new object[10, 10];
|
||||||
public Game1()
|
public Game1()
|
||||||
{
|
{
|
||||||
graphics = new GraphicsDeviceManager(this);
|
graphics = new GraphicsDeviceManager(this);
|
||||||
@ -22,6 +38,8 @@ namespace MonoGameView
|
|||||||
graphics.PreferredBackBufferHeight = 500;
|
graphics.PreferredBackBufferHeight = 500;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Allows the game to perform any initialization it needs to before starting to run.
|
/// Allows the game to perform any initialization it needs to before starting to run.
|
||||||
/// This is where it can query for any required services and load any non-graphic
|
/// This is where it can query for any required services and load any non-graphic
|
||||||
@ -32,6 +50,24 @@ namespace MonoGameView
|
|||||||
{
|
{
|
||||||
// TODO: Add your initialization logic here
|
// TODO: Add your initialization logic here
|
||||||
roadPos = new Vector2(0, 0);
|
roadPos = new Vector2(0, 0);
|
||||||
|
timer = 0.2f;
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
collector = new GarbageCollector(Content,new Coords(0, 0), new List<AGarbageCollectorContainer>(), 10, 10);
|
||||||
|
|
||||||
|
|
||||||
|
stepN = 0;
|
||||||
|
var dfs = new DFS();
|
||||||
|
steps = dfs.BestPath(collector, grid);
|
||||||
|
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,7 +79,9 @@ namespace MonoGameView
|
|||||||
{
|
{
|
||||||
// Create a new SpriteBatch, which can be used to draw textures.
|
// Create a new SpriteBatch, which can be used to draw textures.
|
||||||
spriteBatch = new SpriteBatch(GraphicsDevice);
|
spriteBatch = new SpriteBatch(GraphicsDevice);
|
||||||
road = Content.Load<Texture2D>("road");
|
road1 = Content.Load<Texture2D>("road1");
|
||||||
|
road2 = Content.Load<Texture2D>("road2");
|
||||||
|
grass = Content.Load<Texture2D>("grass");
|
||||||
// TODO: use this.Content to load your game content here
|
// TODO: use this.Content to load your game content here
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,11 +103,24 @@ namespace 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;
|
||||||
|
timer -= elapsed;
|
||||||
|
if (timer<0)
|
||||||
|
{
|
||||||
|
timer = TIMER;
|
||||||
|
if (steps.Any())
|
||||||
|
{
|
||||||
|
steps.First().Invoke(collector, grid);
|
||||||
|
steps.RemoveAt(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
// TODO: Add your update logic here
|
// TODO: Add your update logic here
|
||||||
double time = gameTime.TotalGameTime.TotalMilliseconds / 1000 * Math.PI;
|
|
||||||
roadPos.X = (float) (225 + 200*Math.Sin(time));
|
|
||||||
roadPos.Y = (float)(225 + 200*Math.Cos(time));
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
base.Update(gameTime);
|
base.Update(gameTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,7 +133,17 @@ namespace MonoGameView
|
|||||||
GraphicsDevice.Clear(Color.CornflowerBlue);
|
GraphicsDevice.Clear(Color.CornflowerBlue);
|
||||||
spriteBatch.Begin();
|
spriteBatch.Begin();
|
||||||
|
|
||||||
spriteBatch.Draw(road, roadPos, Color.White);
|
for (int x = 0; x < 10; x++)
|
||||||
|
{
|
||||||
|
for (int y = 0; y < 10; y++)
|
||||||
|
{
|
||||||
|
if (grid[x, y] is Road1) spriteBatch.Draw(road1, new Vector2(x*50,y*50), Color.White);
|
||||||
|
else if (grid[x,y] is Road2) spriteBatch.Draw(road2, new Vector2(x * 50, y * 50), Color.White);
|
||||||
|
else spriteBatch.Draw(grass, new Vector2(x * 50, y * 50), Color.White);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
collector.Draw(spriteBatch);
|
||||||
|
|
||||||
spriteBatch.End();
|
spriteBatch.End();
|
||||||
// TODO: Add your drawing code here
|
// TODO: Add your drawing code here
|
||||||
|
|
||||||
|
40
Trunk/MonoGameView/GarbageCollector.cs
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
using CzokoŚmieciarka.DataModels.Interfaces.GarbageCollector;
|
||||||
|
using CzokoŚmieciarka.DataModels.Interfaces.TrashCans;
|
||||||
|
using CzokoŚmieciarka.DataModels.Models;
|
||||||
|
using Microsoft.Xna.Framework;
|
||||||
|
using Microsoft.Xna.Framework.Content;
|
||||||
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace MonoGameView
|
||||||
|
{
|
||||||
|
public class GarbageCollector : AGarbageCollector
|
||||||
|
{
|
||||||
|
public Texture2D Image { get; set; }
|
||||||
|
public GarbageCollector(ContentManager content, Coords c, List<AGarbageCollectorContainer> l, int rows, int cols) : base(c,l,rows,cols)
|
||||||
|
{
|
||||||
|
Image = content.Load<Texture2D>("collector");
|
||||||
|
}
|
||||||
|
public GarbageCollector(Texture2D image, Coords c, List<AGarbageCollectorContainer> l, int rows, int cols) : base(c, l, rows, cols)
|
||||||
|
{
|
||||||
|
Image = image;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void Draw(SpriteBatch batch)
|
||||||
|
{
|
||||||
|
batch.Draw(Image, new Vector2(Coords.X*50, Coords.Y*50), Color.White);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public override object Clone()
|
||||||
|
{
|
||||||
|
var cloneList = new List<AGarbageCollectorContainer>();
|
||||||
|
return new GarbageCollector(Image, new Coords(Coords.X,Coords.Y), cloneList, rows,columns);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
<Import Project="$(MSBuildExtensionsPath)\MonoGame\v3.0\MonoGame.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\MonoGame\v3.0\MonoGame.Common.props')" />
|
<Import Project="$(MSBuildExtensionsPath)\MonoGame\v3.0\MonoGame.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\MonoGame\v3.0\MonoGame.Common.props')" />
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
@ -13,7 +13,8 @@
|
|||||||
<AssemblyName>MonoGameView</AssemblyName>
|
<AssemblyName>MonoGameView</AssemblyName>
|
||||||
<FileAlignment>512</FileAlignment>
|
<FileAlignment>512</FileAlignment>
|
||||||
<MonoGamePlatform>Windows</MonoGamePlatform>
|
<MonoGamePlatform>Windows</MonoGamePlatform>
|
||||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
|
||||||
|
<TargetFrameworkProfile />
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
|
||||||
<PlatformTarget>x86</PlatformTarget>
|
<PlatformTarget>x86</PlatformTarget>
|
||||||
@ -42,6 +43,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Game1.cs" />
|
<Compile Include="Game1.cs" />
|
||||||
|
<Compile Include="GarbageCollector.cs" />
|
||||||
<Compile Include="Program.cs" />
|
<Compile Include="Program.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
@ -57,8 +59,23 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<MonoGameContentReference Include="Content\Content.mgcb" />
|
<MonoGameContentReference Include="Content\Content.mgcb" />
|
||||||
|
<None Include="app.config" />
|
||||||
<None Include="app.manifest" />
|
<None Include="app.manifest" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\Components\CzokoŚmieciarka.AI_Naive\CzokoŚmieciarka.AI_Naive.csproj">
|
||||||
|
<Project>{10e77bbe-55e1-483d-a456-0e94eac9b24a}</Project>
|
||||||
|
<Name>CzokoŚmieciarka.AI_Naive</Name>
|
||||||
|
</ProjectReference>
|
||||||
|
<ProjectReference Include="..\Components\CzokoŚmieciarka.DataModels.GeneralModels\CzokoŚmieciarka.DataModels.GeneralModels.csproj">
|
||||||
|
<Project>{a3d5da96-69d7-463f-b1ee-6fc70716e3b2}</Project>
|
||||||
|
<Name>CzokoŚmieciarka.DataModels.GeneralModels</Name>
|
||||||
|
</ProjectReference>
|
||||||
|
<ProjectReference Include="..\Components\CzokoŚmieciarka.DataModels\CzokoŚmieciarka.DataModels.csproj">
|
||||||
|
<Project>{f2e11fee-c5ac-47d2-ba9c-819909b6dff7}</Project>
|
||||||
|
<Name>CzokoŚmieciarka.DataModels</Name>
|
||||||
|
</ProjectReference>
|
||||||
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
<Import Project="$(MSBuildExtensionsPath)\MonoGame\v3.0\MonoGame.Content.Builder.targets" />
|
<Import Project="$(MSBuildExtensionsPath)\MonoGame\v3.0\MonoGame.Content.Builder.targets" />
|
||||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace MonoGameView
|
namespace CzokoŚmieciarka.MonoGameView
|
||||||
{
|
{
|
||||||
#if WINDOWS || LINUX
|
#if WINDOWS || LINUX
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
3
Trunk/MonoGameView/app.config
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<configuration>
|
||||||
|
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/></startup></configuration>
|