This is a very clever interpretation of a basic AI that would work in Hopscotch. Bravo!
For the rest of us, let me simplify this solution and explain it to make it more understandable.
A simple explanation of AI
AI stands for: Artificial Intelligence.
It basically means to perform a task that usually only humans can do because of how our brain works.
AI is very useful because it can do things that humans can do much faster and more accurately.
How does AI work
The AI strategy that @Stradyvarious used is one of the simplest forms of AI, but it can be used for really cool and complex things.
The AI learns by randomly doing whatever it can with the control you give it until it finds a random thing that works best for the goal you gave it.
Think of it like this:
Somebody (let’s call him Bob) gives you an unlocked iPad and asks you to find the Hopscotch app. You have no idea how to use an iPad, but Bob tells you that you use it by tapping the screen. You start tapping the screen in random places and end up barely ever touching an app and never touching Hopscotch, so Bob tells you that Hopscotch is an app and shows you what apps look like.
With these new instructions, you start tapping every app on the iPad. You start off tapping a lot of apps that are not Hopscotch. When you tap any app that is not Hopscotch, Bob tells you that that’s the wrong app. Finally, you tap the Hopscotch app. When you tap the Hopscotch app, Bob tells you that you picked the right one. Now you know where the Hopscotch app is and you can tap it every time Bob gives you the iPad.
That is how an AI works. Bob was the code and you were the AI. Although finding an app is a very simple task that would’ve probably been easier to do if Bob just showed you where Hopscotch was, there are lot more complex things you can do using the same method. You can even do things that would usually take you years in a day or less. In fact, did you know that YouTube uses a version of that method? In that case Bob (the code) tells the AI to give videos to the user that they will click on. When you click on a video, Bob tells the AI what video you clicked on and the AI gives the user videos that are like that one. With enough information, the AI will be able to get it right every time.
Now read how Stradyvarious created their AI. They told the AI to shoot in the place that gives the highest score. They also told it how to use the cannon. The AI fires the cannon randomly and when it finds a spot that gives it a score higher then the one it had before, it saves that shooting spot and tries to shoot there next time. If you wanted the AI to be even more accurate, you would tell it what number that gives it the highest score and the position of that number. Then it has more information to work with and become a more accurate shooter.