private bool IsSimilarByColores(Directions[] interestingSide, Dictionary<Directions, Colores> originSides) { return interestingSide. Where(side => !Side2Colores[side].Equals(Colores.Uncolored)). Any(side => Side2Colores[side].Equals(originSides[side])); }
private static Int3 DetermineNextLocation(Room room, Int3 currentLocation, Directions[] possibleDirections, ref Directions lastDirection) { Directions invalidDirections = Directions.None; var foundValidDirection = false; var intendedLocation = currentLocation; var currentSide = room.roomBuffer[currentLocation.X, currentLocation.Y, currentLocation.Z]; if (lastDirection == Directions.Left) { invalidDirections |= Directions.Right; } if (lastDirection == Directions.Right) { invalidDirections |= Directions.Left; } if (lastDirection == Directions.Up) { invalidDirections |= Directions.Down; } if (lastDirection == Directions.Down) { invalidDirections |= Directions.Up; } if (lastDirection == Directions.Forward) { invalidDirections |= Directions.Back; } if (lastDirection == Directions.Back) { invalidDirections |= Directions.Forward; } if ((currentSide & Sides.Left) > 0) { invalidDirections |= Directions.Left; invalidDirections |= Directions.Right; } if ((currentSide & Sides.Right) > 0) { invalidDirections |= Directions.Left; invalidDirections |= Directions.Right; } if ((currentSide & Sides.Top) > 0) { invalidDirections |= Directions.Up; invalidDirections |= Directions.Down; } if ((currentSide & Sides.Bottom) > 0) { invalidDirections |= Directions.Up; invalidDirections |= Directions.Down; } if ((currentSide & Sides.Front) > 0) { invalidDirections |= Directions.Back; invalidDirections |= Directions.Forward; } if ((currentSide & Sides.Rear) > 0) { invalidDirections |= Directions.Back; invalidDirections |= Directions.Forward; } while (!foundValidDirection) { intendedLocation = currentLocation; if (invalidDirections >= Directions.NUM_VALUES - 1) { throw new InvalidSolveException(); } var directions = invalidDirections; lastDirection = possibleDirections.Where(d => (directions & d) == 0).SelectRandom(); if (lastDirection == Directions.None) throw new InvalidSolveException(); switch (lastDirection) { case Directions.Forward: intendedLocation.Z += 1; if (intendedLocation.Z == room.Depth) { invalidDirections |= lastDirection; } else { if (room.roomBuffer[intendedLocation.X, intendedLocation.Y, intendedLocation.Z] != Sides.None) { invalidDirections |= lastDirection; } else { foundValidDirection = true; } } break; case Directions.Back: intendedLocation.Z -= 1; if (intendedLocation.Z < 0) { invalidDirections |= lastDirection; } else { if (room.roomBuffer[intendedLocation.X, intendedLocation.Y, intendedLocation.Z] != Sides.None) { invalidDirections |= lastDirection; } else { foundValidDirection = true; } } break; case Directions.Up: intendedLocation.Y += 1; if (intendedLocation.Y == room.Height) { invalidDirections |= lastDirection; } else { if (room.roomBuffer[intendedLocation.X, intendedLocation.Y, intendedLocation.Z] != Sides.None) { invalidDirections |= lastDirection; } else { foundValidDirection = true; } } break; case Directions.Down: intendedLocation.Y -= 1; if (intendedLocation.Y < 0) { invalidDirections |= lastDirection; } else { if (room.roomBuffer[intendedLocation.X, intendedLocation.Y, intendedLocation.Z] != Sides.None) { invalidDirections |= lastDirection; } else { foundValidDirection = true; } } break; case Directions.Left: intendedLocation.X -= 1; if (intendedLocation.X < 0) { invalidDirections |= lastDirection; } else { if (room.roomBuffer[intendedLocation.X, intendedLocation.Y, intendedLocation.Z] != Sides.None) { invalidDirections |= lastDirection; } else { foundValidDirection = true; } } break; case Directions.Right: intendedLocation.X += 1; if (intendedLocation.X == room.Width) { invalidDirections |= lastDirection; } else { if (room.roomBuffer[intendedLocation.X, intendedLocation.Y, intendedLocation.Z] != Sides.None) { invalidDirections |= lastDirection; } else { foundValidDirection = true; } } break; } } return intendedLocation; }
public bool IsEqualByColores(Directions[] interestingSides, Dictionary<Directions, Colores> originSides) { return interestingSides. Where(side => (!Side2Colores[side].Equals(Colores.Uncolored))). All(side => Side2Colores[side].Equals(originSides[side])); }