/// <summary>
        /// Constructor
        /// </summary>
        /// <param name="_position">Initial position of this checker</param>
        public NetworkBackgammonChecker(NetworkBackgammonPosition _position)
        {
            currentPosition = _position;

            // Create a unique object ID (Is this function really creating just uniqe IDs?)
            uniqueObjectID = System.Guid.NewGuid().GetHashCode();
        }
示例#2
0
        /// <summary>
        /// Calculates a new position based on a given position and a move (dice value) to be applied
        /// </summary>
        /// <param name="a">Position the move is to be based on</param>
        /// <param name="b">Move (dice value)</param>
        /// <returns>New position (after performing the potential move)</returns>
        public static NetworkBackgammonPosition operator +(NetworkBackgammonPosition a, NetworkBackgammonDice b)
        {
            NetworkBackgammonPosition retVal = null;

            switch (a.currentPosition)
            {
            case GameBoardPosition.INVALID:
                retVal = new NetworkBackgammonPosition(GameBoardPosition.INVALID);
                break;

            case GameBoardPosition.BAR:
                retVal = new NetworkBackgammonPosition((GameBoardPosition)Enum.Parse(typeof(GameBoardPosition), Convert.ToUInt32(b.CurrentValue).ToString()));
                break;

            case GameBoardPosition.OFFBOARD:
                retVal = new NetworkBackgammonPosition(GameBoardPosition.OFFBOARD);
                break;

            default:
                UInt32 newPos = Convert.ToUInt32(a.CurrentPosition) + Convert.ToUInt32(b.CurrentValue);

                if (newPos > Convert.ToUInt32(GameBoardPosition.NORMAL_END))
                {
                    retVal = new NetworkBackgammonPosition(GameBoardPosition.OFFBOARD);
                }
                else
                {
                    retVal = new NetworkBackgammonPosition((GameBoardPosition)Enum.Parse(typeof(GameBoardPosition), Convert.ToUInt32(newPos).ToString()));
                }
                break;
            }

            return(retVal);
        }
        /// <summary>
        /// Constructor
        /// </summary>
        /// <remarks>
        /// Parameterless constructor, mainly required for serialization.
        /// </remarks>
        public NetworkBackgammonChecker()
        {
            currentPosition = new NetworkBackgammonPosition(NetworkBackgammonPosition.GameBoardPosition.INVALID);

            // Create a unique object ID (Is this function really creating just uniqe IDs?)
            uniqueObjectID = System.Guid.NewGuid().GetHashCode();
        }
示例#4
0
        /// <summary>
        /// Gets the current position as seen from the opponent's (opposite) side
        /// </summary>
        /// <returns>Opposite position of the current position</returns>
        public NetworkBackgammonPosition GetOppositePosition()
        {
            NetworkBackgammonPosition retVal = null;

            // An opposite position exists only for "normal" positions
            if (currentPosition >= NetworkBackgammonPosition.GameBoardPosition.NORMAL_START &&
                currentPosition <= NetworkBackgammonPosition.GameBoardPosition.NORMAL_END)
            {
                UInt32 oppositeValue = (UInt32)GameBoardPosition.NORMAL_END - (UInt32)currentPosition + 1;

                GameBoardPosition oppositePosition = (GameBoardPosition)oppositeValue;

                retVal = new NetworkBackgammonPosition(oppositePosition);
            }
            else
            {
                retVal = new NetworkBackgammonPosition(GameBoardPosition.INVALID);
            }

            return(retVal);
        }
 /// <summary>
 /// Performs a move of this checker
 /// </summary>
 /// <param name="_move">Move (dice value) to be performed</param>
 public void MoveChecker(NetworkBackgammonDice _move)
 {
     currentPosition += _move;
 }