public void removeQueenFrom(XYLocation l) { if (squares[l.getXCoOrdinate()][l.getYCoOrdinate()] == 1) { squares[l.getXCoOrdinate()][l.getYCoOrdinate()] = 0; } }
public override bool Equals(Object o) { if (null == o || !(o is XYLocation)) { return(base.Equals(o)); } XYLocation anotherLoc = (XYLocation)o; return((anotherLoc.getXCoOrdinate() == xCoOrdinate) && (anotherLoc .getYCoOrdinate() == yCoOrdinate)); }
public int evaluateManhattanDistanceOf(int i, XYLocation loc) { int retVal = -1; int xpos = loc.getXCoOrdinate(); int ypos = loc.getYCoOrdinate(); switch (i) { case 1: retVal = Math.abs(xpos - 0) + Math.abs(ypos - 1); break; case 2: retVal = Math.abs(xpos - 0) + Math.abs(ypos - 2); break; case 3: retVal = Math.abs(xpos - 1) + Math.abs(ypos - 0); break; case 4: retVal = Math.abs(xpos - 1) + Math.abs(ypos - 1); break; case 5: retVal = Math.abs(xpos - 1) + Math.abs(ypos - 2); break; case 6: retVal = Math.abs(xpos - 2) + Math.abs(ypos - 0); break; case 7: retVal = Math.abs(xpos - 2) + Math.abs(ypos - 1); break; case 8: retVal = Math.abs(xpos - 2) + Math.abs(ypos - 2); break; } return retVal; }
public int getValueAt(XYLocation loc) { return getValueAt(loc.getXCoOrdinate(), loc.getYCoOrdinate()); }
public void testXYLocationAtributeSettingOnConstruction() { XYLocation loc = new XYLocation(3, 4); Assert.AreEqual(3, loc.getXCoOrdinate()); Assert.AreEqual(4, loc.getYCoOrdinate()); }
// // PRIVATE METHODS // private bool withinRadius(int radius, XYLocation agentLocation, XYLocation objectLocation) { int xdifference = agentLocation.getXCoOrdinate() - objectLocation.getXCoOrdinate(); int ydifference = agentLocation.getYCoOrdinate() - objectLocation.getYCoOrdinate(); return Math.sqrt((xdifference * xdifference) + (ydifference * ydifference)) <= radius; }
public bool queenExistsAt(XYLocation l) { return (queenExistsAt(l.getXCoOrdinate(), l.getYCoOrdinate())); }
/** * 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. * * @param l */ public void moveQueenTo(XYLocation l) { for (int i = 0; i < size; i++) squares[l.getXCoOrdinate()][i] = 0; squares[l.getXCoOrdinate()][l.getYCoOrdinate()] = 1; }
public void addQueenAt(XYLocation l) { if (!(queenExistsAt(l))) squares[l.getXCoOrdinate()][l.getYCoOrdinate()] = 1; }
public bool isSquareUnderAttack(XYLocation l) { int x = l.getXCoOrdinate(); int y = l.getYCoOrdinate(); return (isSquareHorizontallyAttacked(x, y) || isSquareVerticallyAttacked(x, y) || isSquareDiagonallyAttacked( x, y)); }
public int getNumberOfAttacksOn(XYLocation l) { int x = l.getXCoOrdinate(); int y = l.getYCoOrdinate(); return numberOfHorizontalAttacksOn(x, y) + numberOfVerticalAttacksOn(x, y) + numberOfDiagonalAttacksOn(x, y); }