Clearly the octopus was simply playing a bit of a shell game. The cephalopods really are intelligent creatures. It is a good thing fire is not possible in their domain or they would probably give us a run for our money.
Below is an excerpt from a site dealing with octopus intelligence.
Octopus: Encyclopedia II - Octopus - Intelligence
Octopus - Intelligence
Octopuses are highly intelligent, probably the most intelligent of any of the invertebrates, with their intelligence supposedly comparable to that of the average housecat. Maze and problem-solving experiments show that they have both short- and long-term memory, although their short lifespans limit the amount they can ultimately learn.
An octopus has a highly complex nervous system, only part of which is localized in its brain. Two-thirds of an octopus's neurons are found in the nerve cords of its arms, which have a remarkable amount of autonomy. Octopus arms show a wide variety of complex reflex actions arising on at least three different levels of the nervous system. Some octopuses, such as the mimic octopus, will move their arms in ways that emulate the movements of other sea creatures.
In laboratory experiments, octopuses can be readily trained to distinguish between different shapes and patterns. They are able to open jars after learning from observation.[1] Octopuses have also been observed in what may be described as play; repeatedly releasing bottles or toys into a circular current in their aquariums and then catching them. Octopuses often break out of their aquariums and sometimes into others in search of food. They have even boarded fishing ships and opened holds to eat crabs.
In many countries, including the United States and the United Kingdom, octopuses are on the list of experimental animals on which surgery may not be performed without anesthesia.