日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
這個丹麥小哥的項(xiàng)目火了!他用Python寫了個游戲機(jī)

最近有一個叫PyBoy的開源項(xiàng)目火了,原因是它使用了Python 2.7重新將那些在GameBoy上的上古游戲的整個模擬器實(shí)現(xiàn)了出來。

利用現(xiàn)代技術(shù)重新實(shí)現(xiàn)上古游戲一直是一件相當(dāng)有意思的事情,大家都知道,Game Boy是任天堂公司在1989年發(fā)售的第一代便攜式游戲機(jī),對于一群80/90后來說,Gameboy是他們童年里不可或缺的一部分,有的人可能忘記了,但是提起《口袋妖怪》,很多人應(yīng)該就能想起來了。

除此之外,PyBoy支持通過API編寫腳本,還添加了類型定義,使其可以使用Cython編譯軟件,從而獲得與用C和C++編寫的模擬器相媲美的性能。

目前,PyBoy在Github上標(biāo)星2.6K,累計(jì)Fork有 239 個(Github地址:https://github.com/Baekalfen/PyBoy/wiki/Scripts,-AI-and-Bots)

特性

PyBoy 被設(shè)計(jì)成通過 Python 訪問,因此支持并鼓勵人們做實(shí)驗(yàn)研究,對機(jī)器人和AI感興趣的人都可以嘗試一下。創(chuàng)建者正在構(gòu)建特定于游戲的包裝器,目前,這些包裝器可讓程序員與俄羅斯方塊和超級瑪麗進(jìn)行交互,而不需要對 Game Boy 有深入的了解。

具體你可以參考該文檔:https://docs.pyboy.dk。

說到這里,不得不提的是,創(chuàng)建這個項(xiàng)目的是一個丹麥小哥,早在2015年,PyBoy就已經(jīng)是一個大學(xué)項(xiàng)目,目前,創(chuàng)建者還想學(xué)習(xí)和嘗試更多奇特的功能,根據(jù)大學(xué)項(xiàng)目的研究,他們向模擬器添加了倒回功能,也就是說,你可以在任何游戲中倒回時間。

PyBoy可作為Python中的對象加載。這意味著它可以從另一個腳本初始化,并可以由該腳本控制和探測??匆幌耮amewrapper_tetris.py與游戲互動的原始“機(jī)器人”。

所有外部組件都可以在PyBoy文檔中找到,以下是從屏幕讀取數(shù)據(jù)的簡短演示。該代碼也可以在gamewrapper_mario.py以下位置找到:

 
 
 
 
  1. import os 
  2. import sys 
  3.  
  4. from pyboy import PyBoy, WindowEvent 
  5.  
  6. # Makes us able to import PyBoy from the directory below 
  7. file_path = os.path.dirname(os.path.realpath(__file__)) 
  8. sys.path.insert(0, file_path + "/..") 
  9.  
  10. # Check if the ROM is given through argv 
  11. if len(sys.argv) > 1: 
  12.     filename = sys.argv[1] 
  13. else: 
  14.     print("Usage: python mario_boiler_plate.py [ROM file]") 
  15.     exit(1) 
  16.  
  17. quiet = "--quiet" in sys.argv 
  18. pyboy = PyBoy(filename, window_type="headless" if quiet else "SDL2", window_scale=3, debug=not quiet, game_wrapper=True) 
  19. pyboy.set_emulation_speed(0) 
  20. assert pyboy.cartridge_title() == "SUPER MARIOLAN" 
  21.  
  22. mario = pyboy.game_wrapper() 
  23. mario.start_game() 
  24.  
  25. assert mario.score == 0 
  26. assert mario.lives_left == 2 
  27. assert mario.time_left == 400 
  28. assert mario.world == (1, 1) 
  29. assert mario.fitness == 0 # A built-in fitness score for AI development 
  30. last_fitness = 0 
  31.  
  32. print(mario) 
  33.  
  34. pyboy.send_input(WindowEvent.PRESS_ARROW_RIGHT) 
  35. for _ in range(1000): 
  36.     assert mario.fitness >= last_fitness 
  37.     last_fitness = mario.fitness 
  38.  
  39.     pyboy.tick() 
  40.     if mario.lives_left == 1: 
  41.         assert last_fitness == 27700 
  42.         assert mario.fitness == 17700 # Loosing a live, means 10.000 points in this fitness scoring 
  43.         print(mario) 
  44.         break 
  45. else: 
  46.     print("Mario didn't die?") 
  47.     exit(2) 
  48.  
  49. mario.reset_game() 
  50. assert mario.lives_left == 2 
  51.  
  52. pyboy.stop() 

如果在加載了Super Mario Land ROM的情況下運(yùn)行上述代碼,則將在下面獲得類似圖片和終端的打印輸出。請注意,Mario的形狀顯示為索引0、1、16和17。

 

 
 
 
 
  1. Super Mario Land: World 1-1 
  2. Coins: 0 
  3. lives_left: 2 
  4. Score: 0 
  5. Time left: 400 
  6. Level progress: 251 
  7. Fitness: 0 
  8. Sprites on screen: 
  9. Sprite [3]: Position: (35, 112), Shape: (8, 8), Tiles: (Tile: 0), On screen: True 
  10. Sprite [4]: Position: (43, 112), Shape: (8, 8), Tiles: (Tile: 1), On screen: True 
  11. Sprite [5]: Position: (35, 120), Shape: (8, 8), Tiles: (Tile: 16), On screen: True 
  12. Sprite [6]: Position: (43, 120), Shape: (8, 8), Tiles: (Tile: 17), On screen: True 
  13. Tiles on screen: 
  14.      0   1   2   3   4   5   6   7   8   9   10  11  12  13  14  15  16  17  18  19 
  15. ____________________________________________________________________________________ 
  16. 0  | 339 339 339 339 339 339 339 339 339 339 339 339 339 339 339 339 339 339 339 339 
  17. 1  | 320 320 320 320 320 320 320 320 320 320 320 320 320 320 320 320 320 320 320 320 
  18. 2  | 300 300 300 300 300 300 300 300 300 300 300 300 321 322 321 322 323 300 300 300 
  19. 3  | 300 300 300 300 300 300 300 300 300 300 300 324 325 326 325 326 327 300 300 300 
  20. 4  | 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 
  21. 5  | 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 
  22. 6  | 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 
  23. 7  | 300 300 300 300 300 300 300 300 310 350 300 300 300 300 300 300 300 300 300 300 
  24. 8  | 300 300 300 300 300 300 300 310 300 300 350 300 300 300 300 300 300 300 300 300 
  25. 9  | 300 300 300 300 300 129 310 300 300 300 300 350 300 300 300 300 300 300 300 300 
  26. 10 | 300 300 300 300 300 310 300 300 300 300 300 300 350 300 300 300 300 300 300 300 
  27. 11 | 300 300 310 350 310 300 300 300 300 306 307 300 300 350 300 300 300 300 300 300 
  28. 12 | 300 368 369 300 0   1   300 306 307 305 300 300 300 300 350 300 300 300 300 300 
  29. 13 | 310 370 371 300 16  17  300 305 300 305 300 300 300 300 300 350 300 300 300 300 
  30. 14 | 352 352 352 352 352 352 352 352 352 352 352 352 352 352 352 352 352 352 352 352 
  31. 15 | 353 353 353 353 353 353 353 353 353 353 353 353 353 353 353 353 353 353 353 353 

文章標(biāo)題:這個丹麥小哥的項(xiàng)目火了!他用Python寫了個游戲機(jī)
網(wǎng)頁URL:http://www.dlmjj.cn/article/dppipgo.html