Ejemplo n.º 1
0
 public void removeQueenFrom(XYLocation l)
 {
     if (squares[l.GetXCoOrdinate(), l.GetYCoOrdinate()] == 1)
     {
         squares[l.GetXCoOrdinate(), l.GetYCoOrdinate()] = 0;
     }
 }
Ejemplo n.º 2
0
 /**
  * Moves the queen in the specified column (x-value of <code>l</code>) to
  * the specified row (y-value of <code>l</code>). The action assumes a
  * complete-state formulation of the n-queens problem.
  */
 public void moveQueenTo(XYLocation l)
 {
     for (int i = 0; i < getSize(); ++i)
     {
         squares[l.GetXCoOrdinate(), i] = 0;
     }
     squares[l.GetXCoOrdinate(), l.GetYCoOrdinate()] = 1;
 }
Ejemplo n.º 3
0
        //
        // PRIVATE METHODS
        //
        private bool withinRadius(int radius, XYLocation agentLocation, XYLocation objectLocation)
        {
            int xdifference = agentLocation.GetXCoOrdinate() - objectLocation.GetXCoOrdinate();
            int ydifference = agentLocation.GetYCoOrdinate() - objectLocation.GetYCoOrdinate();

            return(System.Math.Sqrt((xdifference * xdifference) + (ydifference * ydifference)) <= radius);
        }
Ejemplo n.º 4
0
        public int getNumberOfAttacksOn(XYLocation l)
        {
            int x = l.GetXCoOrdinate();
            int y = l.GetYCoOrdinate();

            return(numberOfHorizontalAttacksOn(x, y) + numberOfVerticalAttacksOn(x, y) + numberOfDiagonalAttacksOn(x, y));
        }
Ejemplo n.º 5
0
 /** Column and row indices start with 0! */
 public void addQueenAt(XYLocation l)
 {
     if (!(queenExistsAt(l)))
     {
         squares[l.GetXCoOrdinate(), l.GetYCoOrdinate()] = 1;
     }
 }
Ejemplo n.º 6
0
        public void testXYLocationAtributeSettingOnConstruction()
        {
            XYLocation loc = new XYLocation(3, 4);

            Assert.AreEqual(3, loc.GetXCoOrdinate());
            Assert.AreEqual(4, loc.GetYCoOrdinate());
        }
Ejemplo n.º 7
0
        public bool isSquareUnderAttack(XYLocation l)
        {
            int x = l.GetXCoOrdinate();
            int y = l.GetYCoOrdinate();

            return(isSquareHorizontallyAttacked(x, y) || isSquareVerticallyAttacked(x, y) ||
                   isSquareDiagonallyAttacked(x, y));
        }
Ejemplo n.º 8
0
        public void setBoard(ICollection <XYLocation> locs)
        {
            int count = 0;

            for (int i = 0; i < locs.Size(); i++)
            {
                XYLocation loc = locs.Get(i);
                this.setValue(loc.GetXCoOrdinate(), loc.GetYCoOrdinate(), count);
                count = count + 1;
            }
        }
Ejemplo n.º 9
0
            private int evaluateManhattanDistanceOf(int i, XYLocation loc)
            {
                int retVal = -1;
                int xpos   = loc.GetXCoOrdinate();
                int ypos   = loc.GetYCoOrdinate();

                switch (i)
                {
                case 1:
                    retVal = System.Math.Abs(xpos - 0) + System.Math.Abs(ypos - 1);
                    break;

                case 2:
                    retVal = System.Math.Abs(xpos - 0) + System.Math.Abs(ypos - 2);
                    break;

                case 3:
                    retVal = System.Math.Abs(xpos - 1) + System.Math.Abs(ypos - 0);
                    break;

                case 4:
                    retVal = System.Math.Abs(xpos - 1) + System.Math.Abs(ypos - 1);
                    break;

                case 5:
                    retVal = System.Math.Abs(xpos - 1) + System.Math.Abs(ypos - 2);
                    break;

                case 6:
                    retVal = System.Math.Abs(xpos - 2) + System.Math.Abs(ypos - 0);
                    break;

                case 7:
                    retVal = System.Math.Abs(xpos - 2) + System.Math.Abs(ypos - 1);
                    break;

                case 8:
                    retVal = System.Math.Abs(xpos - 2) + System.Math.Abs(ypos - 2);
                    break;
                }
                return(retVal);
            }
Ejemplo n.º 10
0
 public void mark(XYLocation action)
 {
     mark(action.GetXCoOrdinate(), action.GetYCoOrdinate());
 }
Ejemplo n.º 11
0
 public bool queenExistsAt(XYLocation l)
 {
     return(queenExistsAt(l.GetXCoOrdinate(), l.GetYCoOrdinate()));
 }
Ejemplo n.º 12
0
 public int getValueAt(XYLocation loc)
 {
     return(getValueAt(loc.GetXCoOrdinate(), loc.GetYCoOrdinate()));
 }