AIMA.Core.Environment.NQueens.NQueensBoard.isSquareUnderAttack C# (CSharp) Method

isSquareUnderAttack() public method

public isSquareUnderAttack ( XYLocation l ) : bool
l AIMA.Core.Util.DataStructure.XYLocation
return bool
        public bool isSquareUnderAttack(XYLocation l)
        {
            int x = l.getXCoOrdinate();
            int y = l.getYCoOrdinate();
            return (isSquareHorizontallyAttacked(x, y)
                    || isSquareVerticallyAttacked(x, y) || isSquareDiagonallyAttacked(
                    x, y));
        }

Usage Example

コード例 #1
0
            public HashSet <Action> actions(Object state)
            {
                NQueensBoard board = (NQueensBoard)state;

                HashSet <Action> actions = new LinkedHashSet <Action>();

                int numQueens = board.getNumberOfQueensOnBoard();
                int boardSize = board.getSize();

                for (int i = 0; i < boardSize; i++)
                {
                    XYLocation newLocation = new XYLocation(numQueens, i);
                    if (!(board.isSquareUnderAttack(newLocation)))
                    {
                        actions.Add(new QueenAction(QueenAction.PLACE_QUEEN,
                                                    newLocation));
                    }
                }

                return(actions);
            }