public SixFields(Maze maze, Random r) : base(Kind.Mixed) { IrregularMazeShape[] opts = new IrregularMazeShape[] { new PreferAxis(true), new PreferAxis(false), new PreferDiagonal(true), new PreferDiagonal(false), new PreferStraightPaths(), new PreferAngledPaths(), new PreferUndulatingPaths(), }; this.maze = maze; this.fields = new IrregularMazeShape[3, 2]; for (int i = 0; i < fields.GetLength(0); i++) { for (int j = 0; j < fields.GetLength(1); j++) { do { this.fields[i, j] = opts[r.Next(opts.Length)]; } while (false || (i > 0 && this.fields[i, j] == this.fields[i - 1, j]) || (j > 0 && this.fields[i, j] == this.fields[i, j - 1]) ); } } }
public MixedIrregularMazeShape(OutlineShape outline, IrregularMazeShape inside, IrregularMazeShape outside) : base(Kind.Mixed) { this.outline = outline; this.inside = inside; this.outside = outside; }
/// <summary> /// Returns the preferred directions, as determined by one of the fields. /// </summary> /// <param name="sq"></param> /// <returns></returns> public override bool[] PreferredDirections(MazeSquare sq) { // Size of one field. int m = ((this.maze.XSize - 1) / this.fields.GetLength(0)) + 1; int n = ((this.maze.YSize - 1) / this.fields.GetLength(1)) + 1; // Index of this field. int i = sq.XPos / m; int j = sq.YPos / n; IrregularMazeShape shape = this.fields[i, j]; return(shape.PreferredDirections(sq)); }
/// <summary> /// Returns an irregular pattern that is only applied to the inside/outside of the given OutlineShape. /// The remainder is a regular pattern (without preferred directions). /// </summary> /// <param name="r"></param> /// <param name="maze"></param> /// <param name="outline"></param> /// <param name="confinedToInside"> /// When true: only the inside is irregular. /// When false: only the outside is irregular. /// </param> /// <returns></returns> private static IrregularMazeShape ConfinedInstance(Random r, Maze maze, OutlineShape outline, bool confinedToInside) { IrregularMazeShape regular = new PreferNothing(); IrregularMazeShape irregular = SimpleInstance(r, maze); if (confinedToInside) { return(new MixedIrregularMazeShape(outline, irregular, regular)); } else { return(new MixedIrregularMazeShape(outline, regular, irregular)); } }
/// <summary> /// Returns a combination of two different patterns on the inside/outside of the given OutlineShape. /// </summary> /// <param name="r"></param> /// <param name="maze"></param> /// <param name="outline"></param> /// <returns></returns> private static IrregularMazeShape MixedInstance(Random r, Maze maze, OutlineShape outline) { IrregularMazeShape inside = null, outside = null; do { inside = SimpleInstance(r, maze); outside = SimpleInstance(r, maze); } while (inside.kind <= Kind.Neutral || outside.kind <= Kind.Neutral || inside.kind == outside.kind || (inside.kind != Kind.Zigzags && outside.kind != Kind.Zigzags) ); return(new MixedIrregularMazeShape(outline, inside, outside)); }