private BlockShape Rotate90Clockwise(BlockShape bs) { return(new BlockShape { Units = bs.Units.Select(u => new Unit { X = -u.Y, Y = u.X }).ToList() }); }
private BlockShape ReflectXAxis(BlockShape bs) { return(new BlockShape { Units = bs.Units.Select(u => new Unit { X = -u.X, Y = u.Y }).ToList() }); }
public State GetRandomNeighbour(Random r) { int containerTop = container.Top(); int containerBottom = container.Bottom(); int containerRight = container.Right(); int containerLeft = container.Left(); int pieceIndex = r.Next(pieces.Count); List <BlockShape> orientations = pieces[pieceIndex].Orientations().Select(o => o.Normalize()).ToList(); int orientationIndex = r.Next(orientations.Count); BlockShape po = orientations[orientationIndex]; int pieceRight = po.Right(); int pieceBottom = po.Bottom(); int xOffset = r.Next(containerRight - containerLeft - pieceRight + 1); int yOffset = r.Next(containerBottom - containerTop - pieceBottom + 1); State copy = Copy(); copy.pieces[pieceIndex] = po.Normalize(xOffset, yOffset); return(copy); }
public List <BlockShape> Orientations() { BlockShape r0cw = Copy(); BlockShape r90cw = Rotate90Clockwise(r0cw); BlockShape r180cw = Rotate90Clockwise(r90cw); BlockShape r270cw = Rotate90Clockwise(r180cw); BlockShape r0cwrx = ReflectXAxis(r0cw); BlockShape r90cwrx = ReflectXAxis(r90cw); BlockShape r180cwrx = ReflectXAxis(r180cw); BlockShape r270cwrx = ReflectXAxis(r270cw); return(new List <BlockShape> { r0cw, r90cw, r180cw, r270cw, r0cwrx, r90cwrx, r180cwrx, r270cwrx }); }
public bool Intersects(BlockShape bs) { return(bs.Units.Any(bsu => Units.Any(u => bsu.X == u.X && bsu.Y == u.Y))); }
public bool Contains(BlockShape bs) { return(bs.Units.TrueForAll(bsu => Units.Any(u => bsu.X == u.X && bsu.Y == u.Y))); }
public State(BlockShape container, List <BlockShape> pieces) { this.container = container; this.pieces = pieces; }