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.
import mss
sct = mss.mss()
scr = sct.grab({
'left': 0,
'top': 390,
'width': 440,
'height': 50
})
img = np.array(scr)
color = cv2.cvtColor(img, cv2.IMREAD_COLOR)
lines = cv2.Canny(color, threshold1=190, threshold2=135)
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.