/**
 * Given a list of game objects, replace the occurrence of a specific element
 * with a new element using slicing and continue statement.
 *
 * @param gameObjects List of game objects.
 * @param elementToReplace The element that needs to be replaced.
 * @param newElement The element to replace with.
 * @return List of game objects with the occurrence of elementToReplace replaced by newElement.
 */
fun sliceAndReplace(gameObjects: MutableList<Any>, elementToReplace: Any, newElement: Any): List<Any> {

    // Iterate through the list of game objects
    for (i in gameObjects.indices) {
        // Check if the current element matches the elementToReplace
        if (gameObjects[i] == elementToReplace) {
            // Use slicing to replace the element and continue to the next iteration
            gameObjects.subList(i, i + 1).clear()
            gameObjects.add(i, newElement)
            continue
        }
    }
    return gameObjects
}
/**
 * Given a list of game objects, replace the occurrence of a specific element
 * with a new element using slicing and continue statement.
 *
 * @param gameObjects List of game objects.
 * @param elementToReplace The element that needs to be replaced.
 * @param newElement The element to replace with.
 * @return List of game objects with the occurrence of elementToReplace replaced by newElement.
 */
fun sliceAndReplace(gameObjects: MutableList<Any>, elementToReplace: Any, newElement: Any): List<Any> {
/**
 * Given a list of game objects, replace the occurrence of a specific element
 * with a new element using slicing and continue statement.
 *
 * @param gameObjects List of game objects.
 * @param elementToReplace The element that needs to be replaced.
 * @param newElement The element to replace with.
 * @return List of game objects with the occurrence of elementToReplace replaced by newElement.
 */
fun sliceAndReplace(gameObjects: MutableList<Any>, elementToReplace: Any, newElement: Any): List<Any> {

    // Iterate through the list of game objects
    for (i in gameObjects.indices) {
        // Check if the current element matches the elementToReplace
        if (gameObjects[i] == elementToReplace) {
            // Use slicing to replace the element and continue to the next iteration
            gameObjects.subList(i, i + 1).clear()
            gameObjects.add(i, newElement)
            continue
        }
    }
    return gameObjects
}