public List<Shape> MovableDoubleBlock(Point first, Point second, List<KeyValuePair<Board, int>> result, int parent) { List<Shape> temp = new List<Shape>(); string typeOfContiguous = ContiguousEmptySpaces(first, second); if (typeOfContiguous != string.Empty) { Point spaceAboveEmpty = first; spaceAboveEmpty.X--; Point spaceBelowEmpty = first; spaceBelowEmpty.X++; Point spaceLeftEmpty = first; spaceLeftEmpty.Y--; Point spaceRightEmpty = first; spaceRightEmpty.Y++; // TODO add check confirm that a double shape can move into contiguous space foreach (Shape s in shapes) { if (s.IsEmpty) continue; if (typeOfContiguous == "H") { if ((s.spacesOccupied.Contains(spaceAboveEmpty) || s.spacesOccupied.Contains(spaceBelowEmpty)) && ((s.TopLeftPosition.Y + 1) - (LeastOf(shapes[8].TopLeftPosition.Y, shapes[9].TopLeftPosition.Y) + 1)) == 0) { if (s.Size == 4 || (s.Size == 2 && !s.IsVertical)) { string hTemp; if (!temp.Contains(s)) { Board tempBoard = new Board(); if (s.spacesOccupied.Contains(spaceAboveEmpty)) { this.CopyTo(tempBoard); tempBoard.shapes[this.shapes.IndexOf(s)].DirectionMovable = Shape.Direction.Down; tempBoard.ShiftShapes(shapes.IndexOf(s), 8, 9); hTemp = tempBoard.GetHuffmanCode(); if (!HuffmanCode.HuffmanHistory.Contains(hTemp)) { HuffmanCode.HuffmanHistory.Add(hTemp); result.Add(new KeyValuePair<Board, int>(tempBoard, parent)); } } else { this.CopyTo(tempBoard); tempBoard.shapes[this.shapes.IndexOf(s)].DirectionMovable = Shape.Direction.Up; tempBoard.ShiftShapes(shapes.IndexOf(s), 8, 9); hTemp = tempBoard.GetHuffmanCode(); if (!HuffmanCode.HuffmanHistory.Contains(hTemp)) { HuffmanCode.HuffmanHistory.Add(hTemp); result.Add(new KeyValuePair<Board, int>(tempBoard, parent)); } } temp.Add(s); } } } } if (typeOfContiguous == "V") { if ((s.spacesOccupied.Contains(spaceLeftEmpty) || s.spacesOccupied.Contains(spaceRightEmpty))&& ((s.TopLeftPosition.X+1) - (LeastOf(shapes[8].TopLeftPosition.X, shapes[9].TopLeftPosition.X)+1)) == 0) { if (s.Size == 4 || (s.Size == 2 && s.IsVertical)) { string hTemp; if (!temp.Contains(s)) { Board tempBoard = new Board(); if (s.spacesOccupied.Contains(spaceLeftEmpty)) { this.CopyTo(tempBoard); tempBoard.shapes[this.shapes.IndexOf(s)].DirectionMovable = Shape.Direction.Right; tempBoard.ShiftShapes(shapes.IndexOf(s), 8, 9); hTemp = tempBoard.GetHuffmanCode(); if (!HuffmanCode.HuffmanHistory.Contains(hTemp)) { HuffmanCode.HuffmanHistory.Add(hTemp); result.Add(new KeyValuePair<Board, int>(tempBoard, parent)); } } else { this.CopyTo(tempBoard); tempBoard.shapes[this.shapes.IndexOf(s)].DirectionMovable = Shape.Direction.Left; tempBoard.ShiftShapes(shapes.IndexOf(s), 8, 9); hTemp = tempBoard.GetHuffmanCode(); if (!HuffmanCode.HuffmanHistory.Contains(hTemp)) { HuffmanCode.HuffmanHistory.Add(hTemp); result.Add(new KeyValuePair<Board, int>(tempBoard, parent)); } } temp.Add(s); } } } } } } return temp; }
public List<Shape> MovableAroundEmptySpace(Point p, List<KeyValuePair<Board, int>> result, int parent) { List<Shape> temp = new List<Shape>(); Point spaceAboveEmpty = p; spaceAboveEmpty.X--; Point spaceBelowEmpty = p; spaceBelowEmpty.X++; Point spaceLeftEmpty = p; spaceLeftEmpty.Y--; Point spaceRightEmpty = p; spaceRightEmpty.Y++; foreach (Shape s in shapes) { if (s.IsEmpty) continue; if (s.spacesOccupied.Contains(spaceAboveEmpty) || s.spacesOccupied.Contains(spaceBelowEmpty)) { if (s.Size == 1 || (s.Size == 2 && s.IsVertical)) { string hTemp; if (!temp.Contains(s)) { Board tempBoard = new Board(); if (s.spacesOccupied.Contains(spaceAboveEmpty)) { this.CopyTo(tempBoard); tempBoard.shapes[this.shapes.IndexOf(s)].DirectionMovable = Shape.Direction.Down; tempBoard.ShiftShapes(shapes.IndexOf(s), 8, 9); hTemp = tempBoard.GetHuffmanCode(); if (!HuffmanCode.HuffmanHistory.Contains(hTemp)) { HuffmanCode.HuffmanHistory.Add(hTemp); result.Add(new KeyValuePair<Board, int>(tempBoard, parent)); } } else { this.CopyTo(tempBoard); tempBoard.shapes[this.shapes.IndexOf(s)].DirectionMovable = Shape.Direction.Up; tempBoard.ShiftShapes(shapes.IndexOf(s), 8, 9); hTemp = tempBoard.GetHuffmanCode(); if (!HuffmanCode.HuffmanHistory.Contains(hTemp)) { HuffmanCode.HuffmanHistory.Add(hTemp); result.Add(new KeyValuePair<Board, int>(tempBoard, parent)); } } temp.Add(s); } } } else if (s.spacesOccupied.Contains(spaceLeftEmpty) || s.spacesOccupied.Contains(spaceRightEmpty)) { if (s.Size == 1 || (s.Size == 2 && !s.IsVertical)) { string hTemp; if (!temp.Contains(s)) { Board tempBoard = new Board(); if (s.spacesOccupied.Contains(spaceLeftEmpty)) { this.CopyTo(tempBoard); tempBoard.shapes[this.shapes.IndexOf(s)].DirectionMovable = Shape.Direction.Right; tempBoard.ShiftShapes(shapes.IndexOf(s), 8, 9); hTemp = tempBoard.GetHuffmanCode(); if (!HuffmanCode.HuffmanHistory.Contains(hTemp)) { HuffmanCode.HuffmanHistory.Add(hTemp); result.Add(new KeyValuePair<Board, int>(tempBoard, parent)); } } else { this.CopyTo(tempBoard); tempBoard.shapes[this.shapes.IndexOf(s)].DirectionMovable = Shape.Direction.Left; tempBoard.ShiftShapes(shapes.IndexOf(s), 8, 9); hTemp = tempBoard.GetHuffmanCode(); if (!HuffmanCode.HuffmanHistory.Contains(hTemp)) { HuffmanCode.HuffmanHistory.Add(hTemp); result.Add(new KeyValuePair<Board, int>(tempBoard, parent)); } } temp.Add(s); } } } } return temp; }