예제 #1
0
파일: AI.cs 프로젝트: garayzuev/draughts
        private int attack(Draught d, List <Draught> list)
        {
            List <Position> pos = d.getAttackMoves();

            foreach (Position p in pos)
            {
                if (Arbiter.canAttack(d, p, list))
                {
                    Position to = new Position();
                    to.x = p.x - d.getPosition().x > 0 ? p.x + 1 : p.x - 1;
                    to.y = p.y - d.getPosition().y > 0 ? p.y + 1 : p.y - 1;

                    List <Draught> newList = copyList(list);
                    newList.Remove(Arbiter.findDraught(p, newList));
                    Arbiter.findDraught(d.getPosition(), newList).moveTo(to);
                    return(POINTS_FOR_EAT + (Arbiter.findDraught(to, newList).isKing() != d.isKing()?POINTS_FOR_KING:0) + attack(Arbiter.findDraught(to, newList), newList));
                }
            }
            return(checkDraught(d.getPosition(), list));
        }
예제 #2
0
        public static bool isAttack(Draught attacker, Position to, List <Draught> list)
        {
            if (!attacker.canMoveWithAttack(to))
            {
                return(false);
            }
            Position attacked = new Position();

            attacked.x = to.x - attacker.getPosition().x > 0 ? to.x - 1 : to.x + 1;
            attacked.y = to.y - attacker.getPosition().y > 0 ? to.y - 1 : to.y + 1;
            if (attacker.isMyPosition(attacked))
            {
                return(false);
            }
            foreach (Draught d in list)
            {
                if (d.isMyPosition(attacked))
                {
                    return(canAttack(attacker, attacked, list));
                }
            }

            return(false);
        }
예제 #3
0
        public static bool canAttack(Draught from, Position attacked, List <Draught> list)
        {
            Position to = new Position((from.getPosition().x - attacked.x > 0 ? attacked.x - 1 : attacked.x + 1), (from.getPosition().y - attacked.y > 0 ? attacked.y - 1 : attacked.y + 1));

            if (to.x > 7 || to.x < 0 || to.y > 7 || to.y < 0)
            {
                return(false);
            }
            List <Position> pos = from.getRoutTo(to);

            if (pos == null)
            {
                return(false);
            }
            bool isFind = false;

            foreach (Draught d in list)
            {
                if (d.isMyPosition(attacked) && d.isBlack() != from.isBlack())
                {
                    isFind = true;
                }
            }
            if (!isFind)
            {
                return(false);
            }
            foreach (Draught d in list)
            {
                foreach (Position p in pos)
                {
                    if (!d.isMyPosition(attacked) && d.isMyPosition(p))
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
예제 #4
0
파일: Table.cs 프로젝트: garayzuev/draughts
        public void moveTo(Position to)
        {
            Position from   = select.getPosition();
            bool     isKing = select.isKing();

            if (Arbiter.isAttack(select, to, draughts))
            {
                attack(to);
            }
            else
            {
                select.moveTo(to);
            }

            if (isKing != select.isKing())
            {
                mw.setKing(from.x, from.y);
            }
            mw.turnOn(from.x, from.y, to.x, to.y);
        }