Figuring that it can’t grab an ice cube until it empties one of its two hands, it then reasons that the water bottle is more expendable than the glass of water and sets the bottle down. It then grabs the ice and drops the cube into the glass. Task completed, no extra programming necessary.