近来人工智能的火爆,deepmind已经开始研究玩《星际争霸2》了,这个游戏比较复杂,是否可以像围棋一样超越人类呢?
要想学习这个,可以到DM的开源网站下载源码:
https://github.com/deepmind/pysc2
我这里介绍一下在win10下怎么安装,在CMD窗口里使用:
pip3 install pysc2
在这之前你应该安装libsdl和pygame。这个安装目录如下:
AppData\Local\Programs\Python\Python36\Lib\site-packages\pysc2
然后就可以到网易上下载《星际争霸2》,这个安装目录如下:
F:\game\StarCraft II\Versions\Base56787
然后再下载地图:
https://github.com/deepmind/pysc2/releases/download/v1.0/mini_games.zip
和到网站
https://github.com/Blizzard/s2client-proto#downloads
里下载相关的地图。
由于在windows上运行,原来的源码有些不能运行,需要作一些修改:
找到文件Python36\Lib\site-packages\pysc2\run_configs\platforms.py, 作如下修改:
class Windows(LocalBase):
"""Run on Windows."""
def __init__(self):
super(Windows, self).__init__(
"F:/game/StarCraft II/"#os.environ.get("SC2PATH", "F:/game/StarCraft II"),
"Versions/Base56787/",
"SC2_x64.exe")
然后再修改文件lib.py:
def map_data(self, map_name):
"""Return the map data for a map by name or path."""
temp_name = map_name.split('\\')
map_name = '/' + temp_name[0] + '/' + temp_name[1]
filePath = self.data_dir + 'Maps' + map_name
print(filePath)
with gfile.Open(filePath, "rb") as f:
#with gfile.Open(os.path.join(self.data_dir, "Maps", map_name), "rb") as f:
#with gfile.Open('F:/game/StarCraft II/Maps/DefeatRoaches.SC2Map', "rb") as f:
return f.read()
就可以打开地图文件了。
地图解压放在目录:
F:\game\StarCraft II\Versions\Base56787\maps\mini_games
接着在CMD窗口下就可以运行:
python -m pysc2.bin.agent --map Simple64
运行结果如下: