This commit is contained in:
ryuga4 2019-05-14 23:05:37 +02:00
parent 1215d9549e
commit 627a9c7fc0
16 changed files with 12248 additions and 73 deletions

View File

@ -27,7 +27,7 @@ namespace MonoGameView.Algorithms
int count = 0;
public List<Coords> Houses { get; set; }
public List<IStep> BestPath(ContentManager content, GarbageCollector collector, ICloneable[,] grid)
public KeyValuePair<List<IStep>,int> BestPath(ContentManager content, GarbageCollector collector, ICloneable[,] grid)
{
Houses = new List<Coords>();
for (int x = 0; x < grid.GetLength(0); x++)
@ -44,9 +44,9 @@ namespace MonoGameView.Algorithms
var r = SearchBfs(content, collector, grid, 0).Key;
var r = SearchBfs(content, collector, grid, 0);
Console.WriteLine($"Counts : {count}");
if (r == null) return new List<IStep>();
if (r.Key == null) return new KeyValuePair<List<IStep>,int>(new List<IStep>(), 0);
return r;
}
@ -138,15 +138,17 @@ namespace MonoGameView.Algorithms
while (true)
{
Console.WriteLine(count);
Console.WriteLine(nodes.Count);
count++;
//Console.WriteLine(count);
//Console.WriteLine(nodes.Count);
//var nodes2 = new List<Tuple<List<IStep>, GarbageCollector, ICloneable[,]>>();
while (true)
{
count++;
var item = nodes.Dequeue();
//Thread.Sleep(100);
this.Collector.Coords = item.Item2.Coords;
/*this.Collector.Coords = item.Item2.Coords;
this.Collector.TrashContainers = item.Item2.TrashContainers;
for (int x = 0; x < item.Item3.GetLength(0); x++)
{
@ -154,14 +156,15 @@ namespace MonoGameView.Algorithms
{
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))
&&
item.Item2.TrashContainers.All(i => i.FillPercent == 0.0)
)
{
return new KeyValuePair<List<IStep>, int>(item.Item1, length);
Console.WriteLine(count);
return new KeyValuePair<List<IStep>, int>(item.Item1, count);
}
if (true)//item.Item2.Counter <= 12)
{

View File

@ -24,11 +24,12 @@ namespace MonoGameView.Algorithms
this.Collector = collector;
this.Grid = grid;
}
int count = 0;
int count;
public List<Coords> Houses { get; set; }
public List<Coords> Dumps { get; set; }
public List<IStep> BestPath(ContentManager content, GarbageCollector collector, ICloneable[,] grid)
{
Houses = new List<Coords>();
Dumps = new List<Coords>();
for (int x = 0; x < grid.GetLength(0); x++)
@ -48,7 +49,7 @@ namespace MonoGameView.Algorithms
var r = SearchBfs(content, collector, grid, 0).Key;
var r = SearchBestFirst(content, collector, grid, 0).Key;
Console.WriteLine($"Counts : {count}");
if (r == null) return new List<IStep>();
return r;
@ -182,17 +183,17 @@ namespace MonoGameView.Algorithms
var closestDump = (closestDumps.Any()) ? closestDumps.Min(b => Math.Pow(t.Item2.Coords.X - b.Coords.X, 2) + Math.Pow(t.Item2.Coords.Y - b.Coords.Y, 2)) : 0.0;
return (int) (p1 * 1000 + 10*closestHouse + closestDump);
return (int) (p1 * 1000 + 100*closestHouse + closestDump);
}
}
KeyValuePair<List<IStep>, int> SearchBfs(ContentManager content, GarbageCollector collector, ICloneable[,] grid, int length)
KeyValuePair<List<IStep>, int> SearchBestFirst(ContentManager content, GarbageCollector collector, ICloneable[,] grid, int length)
{
//Thread.Sleep(1);
int count = 0;
count = 0;
var nodes = new PriorityQueue<Tuple<List<IStep>, GarbageCollector, ICloneable[,]>>();
@ -201,11 +202,12 @@ namespace MonoGameView.Algorithms
nodes.Enqueue(f,Priority(f));
while (true)
{
count++;
var p = nodes.Dequeue();
var item = p.Key;
var priority = p.Value;
Thread.Sleep(100);
/*Thread.Sleep(10);
this.Collector.Coords = item.Item2.Coords;
this.Collector.TrashContainers = item.Item2.TrashContainers;
for (int x = 0; x < item.Item3.GetLength(0); x++)
@ -214,7 +216,7 @@ namespace MonoGameView.Algorithms
{
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

@ -28,7 +28,7 @@ namespace CzokoŚmieciarka.MonoGameView.Algorithms
int count = 0;
public List<Coords> Houses { get; set; }
public List<IStep> BestPath(ContentManager content, GarbageCollector collector, ICloneable[,] grid)
public KeyValuePair<List<IStep>,int> BestPath(ContentManager content, GarbageCollector collector, ICloneable[,] grid)
{
Houses = new List<Coords>();
for (int x = 0; x < grid.GetLength(0); x++)
@ -47,8 +47,8 @@ namespace CzokoŚmieciarka.MonoGameView.Algorithms
var r=Search(content, collector, grid, 0).Key;
Console.WriteLine($"Counts : {count}");
if (r == null) return new List<IStep>();
return r;
if (r == null) return new KeyValuePair<List<IStep>,int>(new List<IStep>(),0);
return new KeyValuePair<List<IStep>, int>(r,count);
}
@ -130,8 +130,8 @@ namespace CzokoŚmieciarka.MonoGameView.Algorithms
KeyValuePair<List<IStep>, int> Search(ContentManager content, GarbageCollector collector, ICloneable[,] grid, int length)
{
Thread.Sleep(100);
this.Collector.Coords = collector.Coords;
//Thread.Sleep(10);
/*this.Collector.Coords = collector.Coords;
this.Collector.TrashContainers = collector.TrashContainers;
for (int x = 0; x < grid.GetLength(0); x++)
@ -142,11 +142,11 @@ namespace CzokoŚmieciarka.MonoGameView.Algorithms
this.Grid[x, y] = (ICloneable) grid[x, y].Clone();
}
}
*/
//Console.WriteLine(collector.HouseCounter);
Console.WriteLine(collector.HouseCounter);
if (collector.Counter> 100 || length > 1000)
if (collector.Counter> 1000 || length > 10000)
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

@ -6,6 +6,6 @@ namespace CzokoŚmieciarka.MonoGameView.DataModels.Interfaces
{
public interface IDrawables : ICloneable
{
void Draw(SpriteBatch spriteBatch, int size);
void Draw(SpriteBatch spriteBatch, int size, int width);
}
}

View File

@ -14,10 +14,10 @@ namespace CzokoŚmieciarka.MonoGameView.DataModels.GeneralModels.Models
{
}
public void Draw(SpriteBatch batch, int size)
public void Draw(SpriteBatch batch, int size, int width)
{
batch.Draw(ImageContainer.GetImage(TypeOfGarbage.GarbageType.ToString()), new Rectangle(Coords.X * 500 / size, Coords.Y * 500 / size, 500 / size, 500 / size), Color.White);
batch.Draw(ImageContainer.GetImage(TypeOfGarbage.GarbageType.ToString()+"Bar"), new Rectangle(Coords.X * 500 / size, Coords.Y * 500 / size, (int)Math.Round(FillPercent * 500) / size, 50 / size), Color.White);
batch.Draw(ImageContainer.GetImage(TypeOfGarbage.GarbageType.ToString()), new Rectangle(Coords.X * width / size, Coords.Y * width / size, width / size, width / size), Color.White);
batch.Draw(ImageContainer.GetImage(TypeOfGarbage.GarbageType.ToString()+"Bar"), new Rectangle(Coords.X * width / size, Coords.Y * width / size, (int)Math.Round(FillPercent * width) / size, 50 / size), Color.White);
}
public override object Clone()

View File

@ -21,9 +21,9 @@ namespace MonoGameView.DataModels.Models
Coords = coords;
TrashCans = new List<ATrashCan>();
}
public void Draw(SpriteBatch batch, int size)
public void Draw(SpriteBatch batch, int size, int width)
{
batch.Draw(ImageContainer.GetImage("road2"), new Rectangle(Coords.X * 500 / size, Coords.Y * 500 / size, 500 / size, 500 / size), Color.White);
batch.Draw(ImageContainer.GetImage("road2"), new Rectangle(Coords.X * width / size, Coords.Y * width / size, width / size, width / size), Color.White);
}
public object Clone()

View File

@ -20,9 +20,9 @@ namespace CzokoŚmieciarka.MonoGameView.DataModels.Models
{
}
public void Draw(SpriteBatch batch,int size)
public void Draw(SpriteBatch batch,int size,int width)
{
batch.Draw(ImageContainer.GetImage("collector"), new Rectangle(Coords.X*500/size, Coords.Y*500/size, 500/size, 500/size), Color.White);
batch.Draw(ImageContainer.GetImage("collector"), new Rectangle(Coords.X*width/size, Coords.Y*width/size, width/size, width/size), Color.White);
}

View File

@ -25,9 +25,9 @@ namespace MonoGameView.DataModels.Models
return new Grass((Coords)Coords.Clone());
}
public void Draw(SpriteBatch batch, int size)
public void Draw(SpriteBatch batch, int size, int width)
{
batch.Draw(ImageContainer.GetImage("grass"), new Rectangle(Coords.X * 500 / size, Coords.Y * 500 / size, 500 / size, 500 / size), Color.White);
batch.Draw(ImageContainer.GetImage("grass"), new Rectangle(Coords.X * width / size, Coords.Y * width / size, width / size, width / size), Color.White);
}

View File

@ -23,24 +23,24 @@ namespace CzokoŚmieciarka.MonoGameView.DataModels.Models
Coords = coords;
TrashCans = trashCans.Select(x=>(x as ATrashCan)).ToList();
}
public void Draw(SpriteBatch batch, int size)
public void Draw(SpriteBatch batch, int size,int width)
{
batch.Draw(ImageContainer.GetImage("house"), new Rectangle(Coords.X * 500 / size, Coords.Y * 500 / size, 500 / size, 500 / size), Color.White);
batch.Draw(ImageContainer.GetImage("house"), new Rectangle(Coords.X * width / size, Coords.Y * width / size, width / size, width / size), Color.White);
foreach (TrashCan can in TrashCans)
{
switch (can.Garbage.TypeOfGarbage.GarbageType)
{
case GarbageType.Glass:
batch.Draw(ImageContainer.GetImage("GlassBar"), new Rectangle(Coords.X * 500 / size, Coords.Y * 500 / size, (int)Math.Round(can.FillPercent * 500) / size, 50 / size), Color.White);
batch.Draw(ImageContainer.GetImage("GlassBar"), new Rectangle(Coords.X * width / size, Coords.Y * width / size + width/200, (int)Math.Round(can.FillPercent * width) / size, width/5 / size), Color.White);
break;
case GarbageType.Paper:
batch.Draw(ImageContainer.GetImage("PaperBar"), new Rectangle(Coords.X * 500 / size, Coords.Y * 500 / size + 5, (int)Math.Round(can.FillPercent * 500) / size, 50 / size), Color.White);
batch.Draw(ImageContainer.GetImage("PaperBar"), new Rectangle(Coords.X * width / size, Coords.Y * width / size + 2*width / 200, (int)Math.Round(can.FillPercent * width) / size, width/5 / size), Color.White);
break;
case GarbageType.PlasticMetal:
batch.Draw(ImageContainer.GetImage("PlasticMetalBar"), new Rectangle(Coords.X * 500 / size, Coords.Y * 500 / size + 10, (int)Math.Round(can.FillPercent * 500) / size, 50 / size), Color.White);
batch.Draw(ImageContainer.GetImage("PlasticMetalBar"), new Rectangle(Coords.X * width / size, Coords.Y * width / size + 3*width / 200, (int)Math.Round(can.FillPercent * width) / size, width/5 / size), Color.White);
break;
case GarbageType.Organic:
batch.Draw(ImageContainer.GetImage("OrganicBar"), new Rectangle(Coords.X * 500 / size, Coords.Y * 500 / size + 15, (int)Math.Round(can.FillPercent * 500) / size, 50 / size), Color.White);
batch.Draw(ImageContainer.GetImage("OrganicBar"), new Rectangle(Coords.X * width / size, Coords.Y * width / size + 4*width / 200, (int)Math.Round(can.FillPercent * width) / size, width/5 / size), Color.White);
break;
}
}

View File

@ -25,9 +25,9 @@ namespace CzokoŚmieciarka.MonoGameView.DataModels.Models
return new Road1((Coords)Coords.Clone());
}
public void Draw(SpriteBatch batch, int size)
public void Draw(SpriteBatch batch, int size, int width)
{
batch.Draw(ImageContainer.GetImage("road1"), new Rectangle(Coords.X * 500 / size, Coords.Y * 500 / size, 500 / size, 500 / size), Color.White);
batch.Draw(ImageContainer.GetImage("road1"), new Rectangle(Coords.X * width / size, Coords.Y * width / size, width / size, width / size), Color.White);
}
}
}

View File

@ -24,9 +24,9 @@ namespace CzokoŚmieciarka.MonoGameView.DataModels.Models
return new Road2((Coords)Coords.Clone());
}
public void Draw(SpriteBatch batch, int size)
public void Draw(SpriteBatch batch, int size, int width)
{
batch.Draw(ImageContainer.GetImage("road2"), new Rectangle(Coords.X * 500 / size, Coords.Y * 500 / size, 500 / size, 500 / size), Color.White);
batch.Draw(ImageContainer.GetImage("road2"), new Rectangle(Coords.X * width / size, Coords.Y * width / size, width / size, width / size), Color.White);
}
}
}

View File

@ -33,7 +33,7 @@ namespace CzokoŚmieciarka.MonoGameView
MapLoader mapLoader = new MapLoader();
Vector2 roadPos;
float timer;
const float TIMER = 0.001f;
const float TIMER = 0.1f;
int stepN;
List<IStep> steps;
GarbageCollector collector;
@ -45,8 +45,8 @@ namespace CzokoŚmieciarka.MonoGameView
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
graphics.PreferredBackBufferWidth =700;
graphics.PreferredBackBufferHeight =500;
graphics.PreferredBackBufferWidth =1400;
graphics.PreferredBackBufferHeight =1000;
}
@ -62,29 +62,29 @@ namespace CzokoŚmieciarka.MonoGameView
ImageContainer.InitContainer(Content);
// TODO: Add your initialization logic here
timer = 0f;
timer = 1f;
mapLoader.Load(out size,out grid,"mapa2.xml");
mapLoader.Load(out size,out grid,"mapa4.xml");
var containers = new List<GarbageCollectorContainer>()
{
new GarbageCollectorContainer(
new TypeOfGarbage(GarbageType.Glass,1),
10000,
1000,
new BasicGarbage(new TypeOfGarbage(GarbageType.Glass,1),0)
),
new GarbageCollectorContainer(
new TypeOfGarbage(GarbageType.Paper,1),
10000,
1000,
new BasicGarbage(new TypeOfGarbage(GarbageType.Paper,1),0)
),
new GarbageCollectorContainer(
new TypeOfGarbage(GarbageType.Organic,1),
10000,
1000,
new BasicGarbage(new TypeOfGarbage(GarbageType.Organic,1),0)
),
new GarbageCollectorContainer(
new TypeOfGarbage(GarbageType.PlasticMetal,1),
10000,
1000,
new BasicGarbage(new TypeOfGarbage(GarbageType.PlasticMetal,1),0)
),
@ -94,11 +94,14 @@ namespace CzokoŚmieciarka.MonoGameView
stepN = 0;
var dfs = new DFS(collector,grid);
//steps = dfs.BestPath(Content, collector, grid);
new Thread(delegate() {
var x = dfs.BestPath(Content, collector, grid);
var r = dfs.BestPath(Content, collector, grid);
steps = r.Key;
Console.WriteLine(r);
//displayer.Add("Count", r.Value.ToString());
//new Thread(delegate() {
// var x = dfs.BestPath(Content, collector, grid);
}).Start();
//}).Start();
base.Initialize();
}
@ -112,6 +115,7 @@ namespace CzokoŚmieciarka.MonoGameView
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
font = Content.Load<SpriteFont>("arial");
// TODO: use this.Content to load your game content here
}
@ -134,7 +138,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;
timer -= elapsed;
if (timer<0)
@ -146,7 +150,7 @@ namespace CzokoŚmieciarka.MonoGameView
steps.RemoveAt(0);
}
}
*/
// TODO: Add your update logic here
var barsDictionary = new Dictionary<string, int>();
var collectorDictionary = new Dictionary<string, string>
@ -177,10 +181,10 @@ namespace CzokoŚmieciarka.MonoGameView
{
for (int y = 0; y < size; y++)
{
grid[x, y].Draw(spriteBatch, size);
grid[x, y].Draw(spriteBatch, size, graphics.PreferredBackBufferHeight);
}
}
collector.Draw(spriteBatch, size);
collector.Draw(spriteBatch, size, graphics.PreferredBackBufferHeight);
Display(displayer.info, displayer.barsPercent);
spriteBatch.End();
@ -194,23 +198,22 @@ namespace CzokoŚmieciarka.MonoGameView
/// <param name="info"></param>
public void Display(Dictionary<string, string> info, Dictionary<string,int> barInfo)
{
int x = 510;
int y = 10;
int width = graphics.PreferredBackBufferHeight;
int x = width + width/50;
int y = width/50;
foreach (KeyValuePair<string, string> item in info)
{
spriteBatch.DrawString(font, item.Key, new Vector2(x, y), Color.Black);
y += 15;
spriteBatch.DrawString(font, item.Value, new Vector2(x, y), Color.White);
y += 30;
try
if (barInfo.ContainsKey(item.Key))
{
var bar = barInfo[item.Key];
spriteBatch.Draw(ImageContainer.GetImage(item.Key+"Bar"), new Rectangle(x, y, bar * 40, 10), Color.White);
y += 50;
}
catch
{
spriteBatch.Draw(ImageContainer.GetImage(item.Key + "Bar"), new Rectangle(x, y, bar * width / 500, width / 50), Color.White);
y += width / 50;
}
spriteBatch.DrawString(font, item.Key, new Vector2(x, y), Color.Black);
y += width*2/100;
spriteBatch.DrawString(font, item.Value, new Vector2(x, y), Color.White);
y += width*3/50;
}
}
}

1
Trunk/mapa1.xml Normal file

File diff suppressed because one or more lines are too long

1
Trunk/mapa2.xml Normal file

File diff suppressed because one or more lines are too long

1
Trunk/mapa3.xml Normal file

File diff suppressed because one or more lines are too long

12164
Trunk/mapa4.xml Normal file

File diff suppressed because it is too large Load Diff