public List<XYLocation> getQueenPositions()
{
List<XYLocation> result = new List<XYLocation>();
for (int i = 0; i < size; i++)
{
for (int j = 0; j < size; j++)
{
if (queenExistsAt(i, j))
result.Add(new XYLocation(i, j));
}
}
return result;
}
public Object result(Object s, Action a) { if (a is QueenAction) { QueenAction qa = (QueenAction)a; NQueensBoard board = (NQueensBoard)s; NQueensBoard newBoard = new NQueensBoard(board.getSize()); newBoard.setBoard(board.getQueenPositions()); if (qa.getName() == QueenAction.PLACE_QUEEN) { newBoard.AddQueenAt(qa.getLocation()); } else if (qa.getName() == QueenAction.REMOVE_QUEEN) { newBoard.removeQueenFrom(qa.getLocation()); } else if (qa.getName() == QueenAction.MOVE_QUEEN) { newBoard.moveQueenTo(qa.getLocation()); } s = newBoard; } // if action is not understood or is a NoOp // the result will be the current state. return(s); }