iT邦幫忙

第 11 屆 iThome 鐵人賽

DAY 16
0
AI & Data

AI&Machine Learning系列 第 16

(不專業的AI介紹) 機器語言-Machine-Learning -> 打磚塊例外探討 Day 16

  • 分享至 

  • xImage
  •  

本文將會延續上一篇的打磚塊繼續做說明,我們在本篇做一個例外探討,在打磚塊上有甚麼是需要注意的?首先我們必須要知道我們的需求是甚麼,需要打完磚塊,就這麼簡單,但是我們要做到的事情比較多,要讓球不要低於板子,並且要一直移動板子去打球,所以我們需要控制的是板子,需要參數判斷的是球,當球下來時要判斷他的位子並且用板子去接手。

if ball_going_down ==1 and ball_position_history[-1][1] >= 150 :

        ball_destination = ball_position_history[-1][0]+(390-ball_position_history[-1][1]/vy)*vx
        #print(platform_center_x)

        print(ball_destination)
        if ball_destination >= 195 :
            ball_destination = 195-(ball_destination - 195)
            #print(ball_destination)

            comm.send_instruction(scene_info.frame, PlatformAction.MOVE_RIGHT)

        elif ball_destination <= 0 :
            ball_destination = -ball_destination
            #print(ball_destination)
            comm.send_instruction(scene_info.frame, PlatformAction.MOVE_LEFT)

    else:
        ball_destination = platform_center_x

以上方的做說明,上次所寫出的程式碼,ball_going_down 是判斷說球有沒有在板子以上,並且要符合ball_position_history[-1][1] >= 150,這段程式碼意思是再說他在板子以上之外還要在畫面的150 以上才會觸發,如果是進行判斷跑以下程式,ball_destination 這個意思就是代表說球的 X 軸方向,一樣左就是-X 右即是 +X
根據這個判斷看球的現在狀況在哪裡,利用comm.send_instruction(scene_info.frame, PlatformAction.MOVE_RIGHT),以及comm.send_instruction(scene_info.frame, PlatformAction.MOVE_LEFT),來控制板子的移動,這樣就可以達到自動打球的程式,我們在這個上面判斷的就是球,輸入端就是利用,板子參數來進行操作。

以上就是這次打磚塊的例外補充說明,謝謝大家,以上為不專業的AI介紹,那我們下篇見~~~~~


上一篇
(不專業的AI介紹) 機器學習-Machine-Learning -> 打磚塊(non-Machine-Learning) Day 15
下一篇
(不專業的AI介紹) 機器學習-Machine-Learning -> 打磚塊 Machine-Learning 起步 Day 17
系列文
AI&Machine Learning30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言