Skip to content

Commit

Permalink
Fixed last stuff in Divison algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
devedse committed Oct 5, 2016
1 parent ad97c6f commit 12ab14e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 29 deletions.
46 changes: 20 additions & 26 deletions src/DeveMazeGenerator/Generators/AlgorithmDivisionDynamic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public InnerMap GenerateMapPart(int xStart, int yStart, int widthPart, int heigh
}
}


var visibleRectangle = new Rectangle(xStart, yStart, widthPart, heightPart, 0);

var rectangles = new Stack<Rectangle>();
Expand Down Expand Up @@ -118,20 +118,15 @@ public InnerMap GenerateMapPart(int xStart, int yStart, int widthPart, int heigh
}
}

horizontalSplit = true;

if (horizontalSplit)
{
int splitnumber = 2 + random.Next((curRect.Height - 2) / 2) * 2;
int opening = 1 + random.Next((curRect.Width) / 2) * 2;

//Console.WriteLine(splitnumber + " ---- " + opening);
int opening = 1 + random.Next((curRect.Width) / 2) * 2 + curRect.X;

Rectangle rect1 = new Rectangle(curRect.X, curRect.Y, curRect.Width, splitnumber + 1, random.Next());
Rectangle rect2 = new Rectangle(curRect.X, curRect.Y + splitnumber, curRect.Width, curRect.Height - splitnumber, random.Next());



int xStartDraw = Math.Max(0, curRect.X - xStart);
int xEndDraw = Math.Min(widthPart, curRect.X - xStart + curRect.Width);

Expand All @@ -149,35 +144,34 @@ public InnerMap GenerateMapPart(int xStart, int yStart, int widthPart, int heigh
}


//for (int i = curRect.X; i < curRect.X + curRect.Width; i++)
//{
// if (i - curRect.X != opening)
// {
// map[i, curRect.Y + splitnumber] = false;
// //form.drawPixel(i, curRect.Y + splitnumber, Brushes.Black);
// }
//}

rectangles.Push(rect1);
rectangles.Push(rect2);
}
else
{
int splitnumber = 2 + random.Next((curRect.Width - 2) / 2) * 2;
int opening = 1 + random.Next((curRect.Height) / 2) * 2;

//Console.WriteLine(splitnumber + " ---- " + opening);
int opening = 1 + random.Next((curRect.Height) / 2) * 2 + curRect.Y;

Rectangle rect1 = new Rectangle(curRect.X, curRect.Y, splitnumber + 1, curRect.Height, random.Next());
Rectangle rect2 = new Rectangle(curRect.X + splitnumber, curRect.Y, curRect.Width - splitnumber, curRect.Height, random.Next());

//for (int i = curRect.Y; i < curRect.Y + curRect.Height; i++)
//{
// if (i - curRect.Y != opening)
// {
// map[curRect.X + splitnumber, i] = false;
// }
//}

var yStartDraw = Math.Max(0, curRect.Y - yStart);
int yEndDraw = Math.Min(heightPart, curRect.Y - yStart + curRect.Height);

int xPos = curRect.X + splitnumber - xStart;

if (xPos >= 0 && xPos < widthPart - 1)
{
for (int i = yStartDraw; i < yEndDraw; i++)
{
if (i != opening - yStart)
{
map[xPos, i] = false;
}
}
}


rectangles.Push(rect1);
rectangles.Push(rect2);
Expand Down
6 changes: 3 additions & 3 deletions src/DeveMazeGeneratorConsole/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ public static void Main(string[] args)

public static void Test2()
{
int totSize = 16;
int totSize = 32;

var alg = new AlgorithmDivisionDynamic(totSize, totSize, 1337);

var partTot = alg.GenerateMapPart(0, 0, totSize, totSize);
SaveMaze("parttot.png", partTot);

int b = 8;
int b = totSize / 2;

var part1 = alg.GenerateMapPart(0, 0, b, b);
var part2 = alg.GenerateMapPart(b, 0, b, b);
Expand Down Expand Up @@ -53,7 +53,7 @@ public static void Test1()

Console.WriteLine($"Done in: {elapsed}");


//Console.WriteLine(map.GenerateMapAsString());

Console.WriteLine("Written file");
Expand Down

0 comments on commit 12ab14e

Please sign in to comment.