Beispiel #1
0
        public MoveList filterMovesThatBlockAttack(MoveList moves, Location blockedAttack)
        {
            if (moves.Count == 0)
            {
                return(moves);
            }


            MoveList filtered = new MoveList();

            foreach (Move move in moves)
            {
                GameBoard copy = this.Copy();
                copy.movePiece(move);

                IList <AbstractPiece> attackers = copy.getAttackers(moves[0].startLocation, getPiece(moves[0].startLocation).color);

                bool allowsAttack = false;
                foreach (AbstractPiece attacker in attackers)
                {
                    MoveList attackerMoves = copy.getMoves(attacker);
                    if (attackerMoves.ContainsAttacked(blockedAttack))
                    {
                        allowsAttack = true;
                        break;
                    }
                }
                if (!allowsAttack)
                {
                    filtered.Add(move);
                }
            }

            return(filtered);
        }
Beispiel #2
0
        public bool isMoveBlockingAttack(Move move, Location blockedAttack)
        {
            GameBoard copy = this.Copy();

            copy.movePiece(move);//Allows for simulation

            IList <AbstractPiece> attackers = getAttackers(getPiece(move.startLocation));

            foreach (AbstractPiece attacker in attackers)
            {
                MoveList moves = copy.getMoves(attacker);
                if (moves.ContainsAttacked(blockedAttack))
                {
                    return(true);
                }
            }

            return(false);
        }