public void removeQueenFrom(XYLocation l) { if (squares[l.GetXCoOrdinate(), l.GetYCoOrdinate()] == 1) { squares[l.GetXCoOrdinate(), l.GetYCoOrdinate()] = 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; }
// // 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); }
public int getNumberOfAttacksOn(XYLocation l) { int x = l.GetXCoOrdinate(); int y = l.GetYCoOrdinate(); return(numberOfHorizontalAttacksOn(x, y) + numberOfVerticalAttacksOn(x, y) + numberOfDiagonalAttacksOn(x, y)); }
/** Column and row indices start with 0! */ public void addQueenAt(XYLocation l) { if (!(queenExistsAt(l))) { squares[l.GetXCoOrdinate(), l.GetYCoOrdinate()] = 1; } }
public void testXYLocationAtributeSettingOnConstruction() { XYLocation loc = new XYLocation(3, 4); Assert.AreEqual(3, loc.GetXCoOrdinate()); Assert.AreEqual(4, loc.GetYCoOrdinate()); }
public bool isSquareUnderAttack(XYLocation l) { int x = l.GetXCoOrdinate(); int y = l.GetYCoOrdinate(); return(isSquareHorizontallyAttacked(x, y) || isSquareVerticallyAttacked(x, y) || isSquareDiagonallyAttacked(x, y)); }
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; } }
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); }
public void mark(XYLocation action) { mark(action.GetXCoOrdinate(), action.GetYCoOrdinate()); }
public bool queenExistsAt(XYLocation l) { return(queenExistsAt(l.GetXCoOrdinate(), l.GetYCoOrdinate())); }
public int getValueAt(XYLocation loc) { return(getValueAt(loc.GetXCoOrdinate(), loc.GetYCoOrdinate())); }