Exemplo n.º 1
0
        public bool StartMove(int firstCube, int secondCube, out int sum)
        {
            bool isMovedFirst  = true;
            bool isMovedSecond = true;
            int  firstSum;
            int  secondSum;

            board = BackgammonBoard.Instance;
            if (firstCube != secondCube)
            {
                firstSum = OneMoveForStart(firstCube);
                if (firstSum == 0)
                {
                    isMovedFirst = false;
                }
                else if (IsInFinishMode())
                {
                    secondSum = OneMoveForFinish(secondCube);
                    sum       = firstSum + secondSum;
                    return(true);
                }
                secondSum = OneMoveForStart(secondCube);
                if (secondSum == 0)
                {
                    isMovedSecond = false;
                }
                if ((!isMovedFirst) && (secondSum != 0))
                {
                    sum = OneMoveForStart(firstCube);
                }
                sum = firstSum + secondSum;
            }
            else
            {
                sum = 0;
                for (int i = 0; i < 4; i++)
                {
                    if (!IsInFinishMode())
                    {
                        sum += OneMoveForStart(firstCube);
                        if (sum == 0)
                        {
                            isMovedFirst  = false;
                            isMovedSecond = false;
                            break;
                        }
                        else
                        {
                            isMovedFirst = true;
                        }
                    }
                    else
                    {
                        sum += OneMoveForFinish(firstCube);
                    }
                }
            }
            return(isMovedFirst || isMovedSecond);
        }
Exemplo n.º 2
0
        internal override bool IsOutStatus()
        {
            board = BackgammonBoard.Instance;
            bool isOut = false;

            if (board.Out.BlueSum > 0)
            {
                isOut = true;
            }
            return(isOut);
        }
Exemplo n.º 3
0
        public override bool DoMove(int panel, int steps)
        {
            int             sum;
            BackgammonBoard board   = BackgammonBoard.Instance;
            bool            isMoved = false;

            if (this.Status == GameStatus.Start)
            {
                isMoved = move.StartMove(panel, steps, out sum);
            }
            else if (this.Status == GameStatus.Out)
            {
                isMoved = move.OutMove(panel, steps, out sum);
            }
            else
            {
                isMoved = move.FinishMove(panel, steps, out sum);
            }
            Status = Rull.CheckStatus();
            UpdateSum(sum);
            return(isMoved);
        }
Exemplo n.º 4
0
        internal override bool IsValidMoveForStart(int cube)
        {
            board = BackgammonBoard.Instance;
            bool isValid = false;

            for (int i = 23; i > -1; i--)
            {
                if (board.Board[i].CheckersColor == Color.Blue)
                {
                    if ((i - cube) > -1)
                    {
                        if ((board.Board[i - cube].CheckersColor == Color.Blue) || (board.Board[i - cube].CheckersColor == Color.Transparent) ||
                            ((board.Board[i - cube].CheckersColor == Color.Red) && (board.Board[i - cube].Checkers < 2)))
                        {
                            isValid = true;
                            break;
                        }
                    }
                }
            }
            return(isValid);
        }
Exemplo n.º 5
0
        public bool StartMove(int from, int steps, out int sum)
        {
            board = BackgammonBoard.Instance;
            bool isMoved;

            if ((from - steps) > -1)
            {
                if ((board.Board[from - steps].CheckersColor == Color.Blue) || (board.Board[from - steps].CheckersColor == Color.Transparent))
                {
                    isMoved = true;
                    sum     = steps;
                    board.Board[from].RemoveChecker();
                    board.Board[from - steps].CheckersColor = Color.Blue;
                    board.Board[from - steps].AddChecker();
                }
                else if (board.Board[from - steps].Checkers == 1)
                {
                    isMoved = true;
                    sum     = steps;
                    board.Board[from].RemoveChecker();
                    board.Out.Add(Color.Red, (from - steps) + 1);
                    board.Board[from - steps].RemoveChecker();
                    board.Board[from - steps].CheckersColor = Color.Blue;
                    board.Board[from - steps].AddChecker();
                }
                else
                {
                    sum     = 0;
                    isMoved = false;
                }
            }
            else
            {
                sum     = 0;
                isMoved = false;
            }
            return(isMoved);
        }