Пример #1
0
        // methods (alphabetical)
        private bool AutoMove() // try to find a legal automove if they just clicked on a piece. Give up if not found
        {
            bool    result   = false;
            int     toPoss   = 0;
            BGRules aBGRules = new BGRules();

            if (diceHi != 0)                                              // there is a diceHi throw available (used by default)(diceHi is zero after a successful diceHi move (if not a double))
            {
                toPoss = ((fMove1 - diceHi) < 0) ? 0 : (fMove1 - diceHi); // when bearing off avoid negatives
                if (player == 1)
                {
                    if (aBGRules.IsLegal(fMove1, toPoss, redBoard, blackBoard, diceHi))
                    {
                        tMove1 = fMove1 - diceHi; // use the diceHi
                        result = true;
                    }
                    else // diceHI move blocked
                    {
                        toPoss = ((fMove1 - diceLo) < 0) ? 0 : (fMove1 - diceLo); // when bearing off avoid negatives
                        if (aBGRules.IsLegal(fMove1, toPoss, redBoard, blackBoard, diceLo))
                        {
                            tMove1 = fMove1 - diceLo;
                            result = true;
                        }
                    }
                }
                else
                {
                    if (aBGRules.IsLegal(fMove1, toPoss, blackBoard, redBoard, diceHi))
                    {
                        tMove1 = fMove1 - diceHi; // use the diceHi
                        result = true;
                    }
                    else // diceHI move blocked
                    {
                        toPoss = ((fMove1 - diceLo) < 0) ? 0 : (fMove1 - diceLo); // when bearing off avoid negatives
                        if (aBGRules.IsLegal(fMove1, toPoss, blackBoard, redBoard, diceLo))
                        {
                            tMove1 = fMove1 - diceLo;
                            result = true;
                        }
                    }
                }
            }
            else // diceHi was used already
            {
                if (player == 1)
                {
                    toPoss = ((fMove1 - diceLo) < 0) ? 0 : (fMove1 - diceLo); // when bearing off avoid negatives
                    if (aBGRules.IsLegal(fMove1, toPoss, redBoard, blackBoard, diceLo))
                    {
                        tMove1 = fMove1 - diceLo;
                        result = true;
                    }
                }
                else
                {
                    toPoss = ((fMove1 - diceLo) < 0) ? 0 : (fMove1 - diceLo); // when bearing off avoid negatives
                    if (aBGRules.IsLegal(fMove1, toPoss, blackBoard, redBoard, diceLo))
                    {
                        tMove1 = fMove1 - diceLo;
                        result = true;
                    }
                }
            }
            return(result);
        }