Esempio n. 1
0
        public void SimplifyMove(Board board)
        {
            if (_from == Hex.InvalidHex)
            {
                return;
            }
            Hex neighborHex = Hex.DirectionHex(_from, _to) + _from;

            if (board.Cells[neighborHex].Piece.NumPieces == 0)
            {
                _from = Hex.InvalidHex;
                _to   = neighborHex;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// This will get the "best" direction hex to apply to go from one hex coord to the other.
        /// To ensure axis alignment first, use Hex.AxisAligned()
        /// </summary>
        /// <param name="from"></param>
        /// <param name="to"></param>
        /// <returns>A position enum value for the best direction between the two hexes</returns>
        public static Position GetDirection(Hex from, Hex to)
        {
            // sanity check
            if (from == Hex.InvalidHex || to == Hex.InvalidHex)
            {
                return(Position.center);
            }

            Hex direction = Hex.DirectionHex(from, to);

            for (int i = 0; i < neighborDirections.Length; i++)
            {
                if (neighborDirections[i] == direction)
                {
                    return((Position)i);
                }
            }
            // invalid direction.  I think it will never get here due to integer division rounding down to zero
            return(Position.center);
        }