注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号
x
玩一个养成类游戏,凡游戏涉及养成和pvp,其本质必然演变为compete to pay for time, 即pay2win。
游戏内容是打怪收集资源建造主城,训练兵力攻击别人。我一开始很致力于维护服务器和平不要打人,但是有个大佬冲了大概三四万刀,到处惹事,别人抱怨,他说:
This is a game for me to pay for fun. Bullying you f2p (free to play) players is exactly the service that I paid a car for. You do not have the ability to earn a spare car to pay Evony (the game's name) so you deserve to be bullied..
我现在觉得他说得话简直是游戏的本质和真理,但是当时情绪上接受不了。我就自己学习了机器学习写脚本把地图上的怪打打完。
大佬抱怨没有怪打,我回答:
You do not have the brain to write a script so you deserve to have no monster to attack.
人家是大佬,有能力赚钱玩游戏的人,领悟能力也不会差。他很快就意识到script = d$/dt,其中$表示充钱,t为时间。
现在他是我队友了
写脚本主要用三个包:
pyautogui,模拟键鼠
opencv 图像识别
pytesseract 文字识别
pytesseract很简单,看一下说明就会。
主要用的函数有locate_pattern 和check_in_page.
在某个界面上,如果找到某个按钮,就将其截图保存为template,使用locate_pattern找到。 点击(pyautogui.click)这个按钮之后,将你预想的新界面截图并存放另一个template,然后用check_in_page来检测你的click有没有生效
#locate position of template in image. return y (list) and x(list) of all matched positions
def locate_pattern(image,template, threshold = 0.73, returnthresh = False, check = True):
w,h = template.shape[::-1]
res = cv2.matchTemplate(image,template,cv2.TM_CCOEFF_NORMED)
if returnthresh:
return np.max(res)
loc = np.where(res > threshold)
newy = loc[0] + h//2
newx = loc[1] + w//2
return newy, newx
# after a click, check whether the click go through, and the new template that you want after the click has appeared.
def check_in_page(self,template,ntries = 0,interval = 0.35,box = None,**kw):
if box is None:
box = self.box
screenshot = pyautogui.screenshot(region = box)
try:
for temp1 in glob.iglob(template):
temp = cv2.imread(temp1)
temp = locate_pattern(screenshot,temp,**kw)
if len(temp[0]) > 0:
return 1
else:
if ntries >= 1:
return 0
time.sleep(interval)
return self.check_in_page(template,ntries+1,interval,box)
except:
return 0
|