AI Beats Game of ZigZag. Can every trophy be unlocked?

AI Beats Game of ZigZag using OpenCV and Python.

Lets create AI that beats a simple game of ZigZag. We can use this to test our programming skills and unlock that ultra rare trophy in your android acheivements.

We are going to use a library called OpenCV to try and detect the edges in our game and automatically use those lines to stay on the track.

Lets do this in setps.

  1. Let’s pull in our image from a screen shot using the mss library.
import mss
sct = mss.mss()
scr = sct.grab({
    'left': 0,
    'top': 390,
    'width': 440,
    'height': 50
})
  1. Then we can turn it into a numpy array and open it as a color image in OpenCV.
img = np.array(scr)
color = cv2.cvtColor(img, cv2.IMREAD_COLOR)
  1. We can take the color image and use it to find the edges of our image.
lines = cv2.Canny(color, threshold1=190, threshold2=135)
  1. Find the Hough Lines using the code below to give out AI the vision you see in the images below!
HoughLines = cv2.HoughLinesP(lines, 1, np.pi/180, threshold = 19, minLineLength = 20, maxLineGap = 1)
Game Play AI Vision

After that we simply hook up the AI and let it run! Full code and video tutorial are available.

https://discord.gg/cAWW5qq

AI Beats Game of ZigZag. Can every trophy be unlocked?
1.25 GEEK