ło panie
This commit is contained in:
parent
dc380b2b89
commit
9668e23646
@ -9,6 +9,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Xna.Framework.Content;
|
||||
|
||||
namespace CzokoŚmieciarka.MonoGameView.Algorithms
|
||||
{
|
||||
@ -20,14 +21,14 @@ namespace CzokoŚmieciarka.MonoGameView.Algorithms
|
||||
int count = 0;
|
||||
|
||||
|
||||
public List<IStep> BestPath(AGarbageCollector collector, object[,] grid)
|
||||
public List<IStep> 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);
|
||||
return r;
|
||||
}
|
||||
|
||||
List<IStep> PossibleSteps(AGarbageCollector collector, object[,] grid)
|
||||
List<IStep> PossibleSteps(ContentManager content, AGarbageCollector collector, object[,] grid)
|
||||
{
|
||||
|
||||
|
||||
@ -42,7 +43,7 @@ namespace CzokoŚmieciarka.MonoGameView.Algorithms
|
||||
var filteredMoveSteps = new List<IStep>();
|
||||
foreach (var item in moveSteps)
|
||||
{
|
||||
var copyCollector = (AGarbageCollector)collector.Clone();
|
||||
var copyCollector = (AGarbageCollector)collector.Clone(content);
|
||||
var copyGrid = (object[,])grid.Clone();
|
||||
try
|
||||
{
|
||||
@ -63,26 +64,21 @@ namespace CzokoŚmieciarka.MonoGameView.Algorithms
|
||||
return result;
|
||||
}
|
||||
|
||||
KeyValuePair<List<IStep>, int> Search(AGarbageCollector collector, object[,] grid, int length)
|
||||
KeyValuePair<List<IStep>, int> Search(ContentManager content, 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);
|
||||
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);
|
||||
|
@ -6,6 +6,7 @@ using System.Threading.Tasks;
|
||||
using CzokoŚmieciarka.MonoGameView.DataModels.Exceptions;
|
||||
using CzokoŚmieciarka.MonoGameView.DataModels.Interfaces.TrashCans;
|
||||
using CzokoŚmieciarka.MonoGameView.DataModels.Models;
|
||||
using Microsoft.Xna.Framework.Content;
|
||||
|
||||
namespace CzokoŚmieciarka.MonoGameView.DataModels.Interfaces.GarbageCollector
|
||||
{
|
||||
@ -57,11 +58,15 @@ namespace CzokoŚmieciarka.MonoGameView.DataModels.Interfaces.GarbageCollector
|
||||
Coords.X += 1;
|
||||
}
|
||||
|
||||
public virtual object Clone()
|
||||
public virtual object Clone(ContentManager content)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public IEnumerable<AGarbageCollectorContainer> TrashContainers { get; }
|
||||
public object Clone()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,10 @@
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Microsoft.Xna.Framework.Content;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
|
||||
namespace CzokoŚmieciarka.MonoGameView.DataModels.Interfaces
|
||||
{
|
||||
public interface IDrawables
|
||||
{
|
||||
void Draw(SpriteBatch spriteBatch, int size);
|
||||
void Draw(ContentManager content, SpriteBatch spriteBatch, int size);
|
||||
}
|
||||
}
|
||||
|
55
Trunk/MonoGameView/DataModels/MapLoader.cs
Normal file
55
Trunk/MonoGameView/DataModels/MapLoader.cs
Normal file
@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml;
|
||||
using CzokoŚmieciarka.MonoGameView.DataModels.GeneralModels.Models;
|
||||
using CzokoŚmieciarka.MonoGameView.DataModels.Models;
|
||||
using MonoGameView.DataModels.Models;
|
||||
|
||||
namespace MonoGameView.DataModels
|
||||
{
|
||||
public class MapLoader
|
||||
{
|
||||
public void Load(out int size, out object[,] grid, string filename)
|
||||
{
|
||||
XmlDocument xml = new XmlDocument();
|
||||
xml.Load(filename);
|
||||
XmlNode node = xml.GetElementsByTagName("Map").Item(0);
|
||||
XmlNode sizeNode = node.SelectSingleNode("/Map/Size");
|
||||
size = Convert.ToInt32(sizeNode.InnerText);
|
||||
grid = new object[size,size];
|
||||
for (int x = 0; x < size; x++)
|
||||
{
|
||||
for (int y = 0; y < size; y++)
|
||||
{
|
||||
grid[x, y] = new Grass(new Coords(x,y));
|
||||
}
|
||||
}
|
||||
foreach(XmlNode objectNode in node.SelectNodes("/Map/Objects/Object"))
|
||||
{
|
||||
XmlNode positionNode;
|
||||
int x;
|
||||
int y;
|
||||
switch (objectNode.SelectSingleNode("Type").InnerText)
|
||||
{
|
||||
case "Road":
|
||||
positionNode = objectNode.SelectSingleNode("Position");
|
||||
x = Convert.ToInt32(positionNode.SelectSingleNode("X").InnerText);
|
||||
y = Convert.ToInt32(positionNode.SelectSingleNode("Y").InnerText);
|
||||
Road1 road = new Road1(new Coords(x,y));
|
||||
grid[x, y] = road;
|
||||
break;
|
||||
case "House":
|
||||
positionNode = objectNode.SelectSingleNode("Position");
|
||||
x = Convert.ToInt32(positionNode.SelectSingleNode("X").InnerText);
|
||||
y = Convert.ToInt32(positionNode.SelectSingleNode("Y").InnerText);
|
||||
House house = new House(new Coords(x,y));
|
||||
grid[x, y] = house;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -14,27 +14,20 @@ namespace CzokoŚmieciarka.MonoGameView.DataModels.Models
|
||||
{
|
||||
public class GarbageCollector : AGarbageCollector, IDrawables
|
||||
{
|
||||
public Texture2D Image { get; set; }
|
||||
public GarbageCollector(ContentManager content, Coords c, List<AGarbageCollectorContainer> l, int rows, int cols) : base(c,l,rows,cols)
|
||||
public GarbageCollector(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)
|
||||
|
||||
public void Draw(ContentManager content, SpriteBatch batch,int size)
|
||||
{
|
||||
Image = image;
|
||||
batch.Draw(content.Load<Texture2D>("collector"), new Rectangle(Coords.X*500/size, Coords.Y*500/size, 500/size, 500/size), Color.White);
|
||||
}
|
||||
|
||||
|
||||
public void Draw(SpriteBatch batch,int size)
|
||||
{
|
||||
batch.Draw(Image, new Rectangle(Coords.X*500/size, Coords.Y*500/size, 500/size, 500/size), Color.White);
|
||||
}
|
||||
|
||||
|
||||
public override object Clone()
|
||||
public override object Clone(ContentManager content)
|
||||
{
|
||||
var cloneList = new List<AGarbageCollectorContainer>();
|
||||
return new GarbageCollector(Image, new Coords(Coords.X,Coords.Y), cloneList, rows,columns);
|
||||
return new GarbageCollector(new Coords(Coords.X,Coords.Y), cloneList, rows,columns);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
28
Trunk/MonoGameView/DataModels/Models/Grass.cs
Normal file
28
Trunk/MonoGameView/DataModels/Models/Grass.cs
Normal file
@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using CzokoŚmieciarka.MonoGameView.DataModels.Interfaces;
|
||||
using CzokoŚmieciarka.MonoGameView.DataModels.Models;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Content;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
|
||||
namespace MonoGameView.DataModels.Models
|
||||
{
|
||||
public class Grass : IDrawables
|
||||
{
|
||||
private Coords Coords;
|
||||
|
||||
public Grass(Coords coords)
|
||||
{
|
||||
Coords = coords;
|
||||
}
|
||||
|
||||
public void Draw(ContentManager content, SpriteBatch batch, int size)
|
||||
{
|
||||
batch.Draw(content.Load<Texture2D>("grass"), new Rectangle(Coords.X * 500 / size, Coords.Y * 500 / size, 500 / size, 500 / size), Color.White);
|
||||
}
|
||||
}
|
||||
}
|
@ -4,10 +4,23 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using CzokoŚmieciarka.MonoGameView.DataModels.Interfaces;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Content;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
|
||||
namespace CzokoŚmieciarka.MonoGameView.DataModels.Models
|
||||
{
|
||||
public class House : IHouse
|
||||
public class House : IDrawables
|
||||
{
|
||||
private Coords Coords;
|
||||
|
||||
public House(Coords coords)
|
||||
{
|
||||
Coords = coords;
|
||||
}
|
||||
public void Draw(ContentManager content, SpriteBatch batch, int size)
|
||||
{
|
||||
batch.Draw(content.Load<Texture2D>("house"), new Rectangle(Coords.X * 500 / size, Coords.Y * 500 / size, 500 / size, 500 / size), Color.White);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,10 +4,24 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Content;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
|
||||
namespace CzokoŚmieciarka.MonoGameView.DataModels.Models
|
||||
{
|
||||
public class Road1 :IRoad1
|
||||
{
|
||||
private Coords Coords;
|
||||
|
||||
public Road1(Coords coords)
|
||||
{
|
||||
Coords = coords;
|
||||
}
|
||||
|
||||
public void Draw(ContentManager content, SpriteBatch batch, int size)
|
||||
{
|
||||
batch.Draw(content.Load<Texture2D>("grass"), new Rectangle(Coords.X * 500 / size, Coords.Y * 500 / size, 500 / size, 500 / size), Color.White);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using CzokoŚmieciarka.MonoGameView.Algorithms;
|
||||
using MonoGameView.DataModels;
|
||||
|
||||
namespace CzokoŚmieciarka.MonoGameView
|
||||
{
|
||||
@ -17,20 +18,21 @@ namespace CzokoŚmieciarka.MonoGameView
|
||||
/// </summary>
|
||||
public class Game1 : Game
|
||||
{
|
||||
private static int size = 20;
|
||||
private static int size;
|
||||
GraphicsDeviceManager graphics;
|
||||
SpriteBatch spriteBatch;
|
||||
Texture2D road1;
|
||||
Texture2D road2;
|
||||
Texture2D grass;
|
||||
Texture2D house;
|
||||
MapLoader mapLoader = new MapLoader();
|
||||
Vector2 roadPos;
|
||||
float timer;
|
||||
const float TIMER = 0.2f;
|
||||
int stepN;
|
||||
List<IStep> steps;
|
||||
GarbageCollector collector;
|
||||
object[,] grid = new object[size, size];
|
||||
object[,] grid;
|
||||
public Game1()
|
||||
{
|
||||
graphics = new GraphicsDeviceManager(this);
|
||||
@ -52,23 +54,14 @@ namespace CzokoŚmieciarka.MonoGameView
|
||||
// TODO: Add your initialization logic here
|
||||
roadPos = new Vector2(0, 0);
|
||||
timer = 0.2f;
|
||||
for (int x=0;x<size;x++)
|
||||
{
|
||||
for (int y=0;y<size;y++)
|
||||
{
|
||||
if (x % 2 == 0 || y == 1 || y == 5 || y == 9 || y == 13 || y == 17) grid[x, y] = new Road1();
|
||||
else grid[x, y] = null;
|
||||
}
|
||||
}
|
||||
|
||||
grid[4, 0] = new House();
|
||||
grid[6, 4] = new House();
|
||||
collector = new GarbageCollector(Content,new Coords(0, 0), new List<AGarbageCollectorContainer>(), size, size);
|
||||
mapLoader.Load(out size,out grid,"map.xml");
|
||||
collector = new GarbageCollector(new Coords(0, 0), new List<AGarbageCollectorContainer>(), size, size);
|
||||
|
||||
|
||||
stepN = 0;
|
||||
var dfs = new DFS();
|
||||
steps = dfs.BestPath(collector, grid);
|
||||
steps = dfs.BestPath(Content, collector, grid);
|
||||
|
||||
base.Initialize();
|
||||
}
|
||||
@ -120,11 +113,6 @@ namespace CzokoŚmieciarka.MonoGameView
|
||||
}
|
||||
// TODO: Add your update logic here
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
base.Update(gameTime);
|
||||
}
|
||||
|
||||
@ -147,7 +135,7 @@ namespace CzokoŚmieciarka.MonoGameView
|
||||
else spriteBatch.Draw(grass, new Rectangle(x * 500 / size, y * 500 / size, 500 / size, 500 / size), Color.White);
|
||||
}
|
||||
}
|
||||
collector.Draw(spriteBatch, size);
|
||||
collector.Draw(Content, spriteBatch, size);
|
||||
|
||||
spriteBatch.End();
|
||||
// TODO: Add your drawing code here
|
||||
|
@ -62,11 +62,13 @@
|
||||
<Compile Include="DataModels\Interfaces\TrashCans\ADump.cs" />
|
||||
<Compile Include="DataModels\Interfaces\TrashCans\AGarbageCollectorContainer.cs" />
|
||||
<Compile Include="DataModels\Interfaces\TrashCans\ATrashCan.cs" />
|
||||
<Compile Include="DataModels\MapLoader.cs" />
|
||||
<Compile Include="DataModels\Models\Coords.cs" />
|
||||
<Compile Include="DataModels\Models\Dump.cs" />
|
||||
<Compile Include="DataModels\Models\Garbage.cs" />
|
||||
<Compile Include="DataModels\Models\GarbageCollectorContainer.cs" />
|
||||
<Compile Include="DataModels\Models\GarbageLocalization.cs" />
|
||||
<Compile Include="DataModels\Models\Grass.cs" />
|
||||
<Compile Include="DataModels\Models\House.cs" />
|
||||
<Compile Include="DataModels\Models\Map.cs" />
|
||||
<Compile Include="DataModels\Models\Road1.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user