示例#1
0
 /// <summary>
 /// Determines the coordinates in a desired direction
 /// </summary>
 /// <param name="coord"></param>
 /// <param name="direction"></param>
 /// <returns></returns>
 public static ICoordinates NextCoordinates(ICoordinates coordinates, Direction direction)
 {
     if (coordinates is BoardCoordinates)
     {
         BoardCoordinates board = new BoardCoordinates(coordinates);
         board.Modify(direction);
         if (board.Valid)
         {
             return(board);
         }
         else
         {
             return(new OuterRingCoordinates(board));
         }
     }
     else if (coordinates is OuterRingCoordinates)
     {
         if (direction != Direction.Clockwise && direction != Direction.Counterclockwise)
         {
             direction = ConvertDirection(coordinates as OuterRingCoordinates, direction);
         }
         ICoordinates outer = new OuterRingCoordinates(coordinates);
         outer.Modify(direction);
         return(outer);
     }
     return(null);
 }
示例#2
0
 public override bool Equals(object obj)
 {
     if (obj is OuterRingCoordinates)
     {
         OuterRingCoordinates other = obj as OuterRingCoordinates;
         return(other.Position == Position);
     }
     return(false);
 }
示例#3
0
        /// <summary>
        /// Converts the pushing direction into a direction of outer ring movement
        /// </summary>
        /// <param name="coord">the coordinates a marble got pushed out to</param>
        /// <param name="direction">the direction the push was done</param>
        /// <returns></returns>
        public static Direction ConvertDirection(OuterRingCoordinates coordinates, Direction direction)
        {
            if (direction == Direction.Clockwise || direction == Direction.Counterclockwise)
            {
                return(direction);
            }
            Direction clw = Direction.None, ccw = Direction.None;

            if (coordinates.Position < 6)
            {
                clw = Direction.UpRight;    //2
                ccw = Direction.DownLeft;   //5
            }
            else if (coordinates.Position < 11)
            {
                clw = Direction.UpLeft;     //1
                ccw = Direction.DownRight;  //4
            }
            else if (coordinates.Position < 16)
            {
                clw = Direction.Left;       //6
                ccw = Direction.Right;      //3
            }
            else if (coordinates.Position < 21)
            {
                clw = Direction.DownLeft;   //5
                ccw = Direction.UpRight;    //2
            }
            else if (coordinates.Position < 26)
            {
                clw = Direction.DownRight;  //4
                ccw = Direction.UpLeft;     //1
            }
            else
            {
                clw = Direction.Right;      //3
                ccw = Direction.Left;       //6
            }
            int       clwCount = 0, ccwCount = 0;
            Direction mod = direction;

            while (mod != clw)
            {
                clwCount++;
                if ((byte)mod + 1 == 7)
                {
                    mod = (Direction)1;
                }
                else
                {
                    mod = mod + 1;
                }
            }
            mod = direction;
            while (mod != ccw)
            {
                ccwCount++;
                if ((byte)mod - 1 == 0)
                {
                    mod = (Direction)6;
                }
                else
                {
                    mod = mod - 1;
                }
            }
            if (clwCount < ccwCount)
            {
                return(Direction.Clockwise);
            }
            return(Direction.Counterclockwise);
        }