Exemple #1
0
        public Draught clone()
        {
            Draught d = new Draught(isBlack(), this.pos);

            d._isKing = this._isKing;
            return(d);
        }
Exemple #2
0
        public static bool needAttack(Draught d, List <Draught> list)
        {
            List <Position> listPos = d.getAttackMoves();

            foreach (Draught dr in list)
            {
                foreach (Position p in listPos)
                {
                    if (dr != d && dr.isBlack() != d.isBlack() && dr.isMyPosition(p) && canAttack(d, p, list))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Exemple #3
0
 public static bool canMove(Draught from, Position to, List <Draught> list)
 {
     if (needAttack(from, list))
     {
         return(isAttack(from, to, list));
     }
     else
     {
         foreach (Draught d in list)
         {
             if (d.isMyPosition(to))
             {
                 return(false);
             }
         }
         return(from.canMoveTo(to));
     }
 }
Exemple #4
0
        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));
        }
Exemple #5
0
        public void turnAI()
        {
            Turn t = comp.doTurn(draughts);

            if (t.d.getPosition().x != -1)
            {
                select = t.d;
                if (t.isAttack)
                {
                    aiAttack(t.to);
                    while (Arbiter.getDraughtsNeedToMove(isBlackTurn, draughts) != null)
                    {
                        Turn tur = comp.doTurn(draughts);
                        if (tur.d.getPosition().x != -1)
                        {
                            select = tur.d;
                            aiAttack(tur.to);
                        }
                        else
                        {
                            mw.errorMessage();
                        }
                    }
                }
                else
                {
                    moveTo(t.to);
                }
                if (Arbiter.isVictory(isBlackTurn, draughts))
                {
                    mw.victoryMessage();
                }
            }
            else
            {
                mw.errorMessage();
            }

            isBlackTurn = !isBlackTurn;
        }
Exemple #6
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);
        }
Exemple #7
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);
        }
Exemple #8
0
 public void startOfTurn(Position pos)
 {
     attackers = Arbiter.getDraughtsNeedToMove(isBlackTurn, draughts);
     select    = Arbiter.findDraught(pos, draughts);
 }
Exemple #9
0
 public Turn(Draught d, bool isAttack, Position to)
 {
     this.d        = d;
     this.isAttack = isAttack;
     this.to       = to;
 }