微信跳一跳第二天

1. 寻找关键坐标——起跳坐标

算法策略:获取小人的底座中心点的值作为起跳点。

1 获取小人的所有像素点中y坐标的最大值

2 在小人y坐标的最大值那些像素点中,计算出x的平均值,作为小人底座的x的值。

3 y坐标的最大值减去一个偏移值,就作为小人底座的y值。(注意:该偏移值不同的设备是不同的,同一台设备不同场景下是一样的)

比如教师机的设备中最低点的值是(337,1131),中心值是 (337,1113),从而计算出偏移值为1131-1113=18

 

 

2. 寻找目标坐标

获取目标坐标的y值

取屏幕宽和高的一半(x=540和y=960)

 

 

我们会发现,目标格子的边沿(x=563,y=978)和这个是差不多的(y的偏差是18,x的偏差是23.

以后每次跳动的时候,假如已经知道目标格子的边沿,和目标坐标的x值,就可以很轻松计算出目标坐标的y值。

注意:每个格子的宽和高的比例是相同的。

左:(563,847)

右:(1015,847)

上:(788,720)

下:(788,978)

中:(788,847)

高和宽的比例:(978-720)/(1015-563) =258/452。假设该值为p

 

 

已经知道目标坐标的x值,求目标坐标的y值

 

3. 控制屏幕进行跳动

operation.py

    # 控制屏幕进行跳动

    def jump(self, src, dst, press_time):

        press_time = int(press_time)

        cmd = "adb shell input swipe %d %d %d %d %d" % (

            int(src[0]), int(src[1]),

            int(dst[0]), int(dst[1]),

            press_time

        )

        print(cmd)

        os.system(cmd)

 

 

 

 

 

 

 

 

 

 

 

main.py

def test_jump():

    algorithm = Algorithm()

    op = Operation()

    im = op.screen_cap()

    start_x, start_y, end_x, end_y = algorithm.find_point(im)

    start_point = (start_x, start_y)

    end_point = (end_x, end_y)   

    distance = algorithm.euclidean_distance(start_point, end_point)

    press_time = algorithm.distance_to_time(distance)

    op.jump(start_point, end_point, press_time)

 

 

 

 

 

 

 

 

 

 

 

posted @ 2018-06-29 21:36  emmm.m  阅读(76)  评论(0编辑  收藏  举报