예제 #1
0
        /// <summary>
        /// Ermittelt, ob die Zelle, die gegenüber der in <paramref name="wall"/> angegebenen Wand der Zelle an Position
        /// <paramref name="cell"/> liegt, bereits Teil des Labyrinths ist.
        /// </summary>
        /// <param name="mazeMap">Die Karte, die angibt, ob eine Zelle Teil des Labyrinthes ist</param>
        /// <param name="cell">Die aktuelle Position</param>
        /// <param name="wall">Die zu testende Wand</param>
        /// <param name="oppositeCell">Die Zelle auf der gegenüberliegenden Seite</param>
        /// <returns><c>true</c>, wenn die Zelle auf der anderen Seite Teil des Labyrinthes ist, ansonsten <c>false</c></returns>
        /// <exception cref="ArgumentException">Ein ungültiger Wert für <paramref name="wall"/> wurde übergeben.</exception>
        private static bool CellOnOppositeSideOfWallIsOnMaze(bool[,] mazeMap, Tuple<int, int> cell, Wall4 wall, out Tuple<int, int> oppositeCell)
        {
            Contract.Requires(mazeMap != null);
            Contract.Requires(cell != null);
            Contract.Requires(wall.ExactlyOneValueSet());
            Contract.Requires(cell.Item1 >= 0 && cell.Item2 >= 0);
            Contract.Ensures(Contract.ValueAtReturn(out oppositeCell) != null);

            switch (wall)
            {
                case Wall4.North:
                    Contract.Assume(cell.Item2 > 0);
                    oppositeCell = new Tuple<int, int>(cell.Item1, cell.Item2 - 1);
                    return mazeMap[oppositeCell.Item1, oppositeCell.Item2];
                case Wall4.South:
                    Contract.Assume(cell.Item2 < mazeMap.GetLength(1) - 1);
                    oppositeCell = new Tuple<int, int>(cell.Item1, cell.Item2 + 1);
                    return mazeMap[oppositeCell.Item1, oppositeCell.Item2];
                case Wall4.East:
                    Contract.Assume(cell.Item1 < mazeMap.GetLength(0) - 1);
                    oppositeCell = new Tuple<int, int>(cell.Item1 + 1, cell.Item2);
                    return mazeMap[oppositeCell.Item1, oppositeCell.Item2];
                case Wall4.West:
                    Contract.Assume(cell.Item1 > 0);
                    oppositeCell = new Tuple<int, int>(cell.Item1 - 1, cell.Item2);
                    return mazeMap[oppositeCell.Item1, oppositeCell.Item2];
                default:
                    throw new ArgumentException("Ungültige Wand-Werte:" + wall, "wall");
            }
        }
예제 #2
0
        /// <summary>
        /// Bezieht die Zelle, die gegenüber der in <paramref name="wall"/> angegebenen Wand der Zelle an Position
        /// <paramref name="cell"/> liegt
        /// </summary>
        /// <param name="cell">Die aktuelle Position</param>
        /// <param name="wall">Die zu testende Wand</param>
        /// <returns>Die Zelle</returns>
        /// <exception cref="ArgumentException">Ein ungültiger Wert für <paramref name="wall"/> wurde übergeben.</exception>
        private static Tuple<int, int> SelectCellOnOppositeSideOfWall(Tuple<int, int> cell, Wall4 wall)
        {
            Contract.Requires(cell != null);
            Contract.Requires(wall.ExactlyOneValueSet());
            Contract.Requires(cell.Item1 >= 0 && cell.Item2 >= 0);

            switch (wall)
            {
                case Wall4.North:
                    Contract.Assume(cell.Item2 > 0);
                    return new Tuple<int, int>(cell.Item1, cell.Item2 - 1);
                case Wall4.South:
                    return new Tuple<int, int>(cell.Item1, cell.Item2 + 1);
                case Wall4.East:
                    return new Tuple<int, int>(cell.Item1 + 1, cell.Item2);
                case Wall4.West:
                    Contract.Assume(cell.Item1 > 0);
                    return new Tuple<int, int>(cell.Item1 - 1, cell.Item2);
                default:
                    throw new ArgumentException("Ungültige Wand-Werte:" + wall, "wall");
            }
        }