public object Result(object s, IAction a) { if (a is QueenAction) { QueenAction qa = (QueenAction)a; NQueensBoard board = (NQueensBoard)s; NQueensBoard newBoard = new NQueensBoard(board.Size); newBoard.SetBoard(board.GetQueenPositions()); if (qa.GetName() == QueenAction.PlaceQueen) { newBoard.AddQueenAt(qa.GetLocation()); } else if (qa.GetName() == QueenAction.RemoveQueen) { newBoard.RemoveQueenFrom(qa.GetLocation()); } else if (qa.GetName() == QueenAction.MoveQueen) { newBoard.MoveQueenTo(qa.GetLocation()); } s = newBoard; } // if action is not understood or is a NoOp // the result will be the current state. return(s); }