New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

更新距离与时间的计算关系(根据跳一跳源码计算) #841

Merged
merged 2 commits into from Feb 2, 2018

Conversation

@baolw
Copy link
Contributor

baolw commented Jan 3, 2018

本次 PR 主要做的事情:

  • 根据官网源码推导出的计算公式

  • 增加head_diameter参数,即棋子顶部圆球的直径。

  • 获取截图测得的距离,通过比例换算得到在代码中的距离长度

  • 从此不需要再去一个个试参数,只需要测量顶部圆球的直径即可,测试的机子使用
    1920x1080,截图中圆球直径是60px。

  • TODO : 如果可以加入自动测量圆球直径的代码,则可实现全自动,无须手动测量。

  • TODO : 由于游戏视角是倾斜了60°的,因此截图测得的长度与代码中的长度有个关系存在,目前
    math.sqrt(6) / 2这个值是根据每次倾斜都是圆心到圆心测量的,因为确实每次跳跃都在combo。即使不
    是圆心到圆心,误差也不大,如果想确保计算严谨性,那么这个比例需要根据每次倾斜的角度,并且需要知道原路径是怎么样的一个角度才能得到截图中测得的角度。

修改后最高分数:2000多分,主动退了。

@binderclip

This comment has been minimized.

Copy link
Collaborator

binderclip commented Jan 3, 2018

@baolw

This comment has been minimized.

Copy link
Contributor Author

baolw commented Jan 3, 2018

习惯用ide做了格式化,主要修改代码就是增加了一个圆球直径和计算公式

# 计算程序长度与截图测得的距离的比例
scale = 0.945 * 2 / head_diameter
actual_distance = distance * scale * (math.sqrt(6) / 2)
press_time = (-945 + math.sqrt(945 ** 2 + 4 * 105 * 36 * actual_distance)) / (2 * 105) * 1000

This comment has been minimized.

@chenjiandongx

chenjiandongx Jan 3, 2018

Collaborator

这是写死了吗,数字固定的?945 这个就是根据源码得来的?

This comment has been minimized.

@baolw

baolw Jan 3, 2018

Author Contributor

@chenjiandongx e.BOTTLE = {
headRadius: .945,
bodyWidth: 2.34,
bodyDepth: 2.34,
bodyHeight: 3.2,
reduction: .005,
minScale: .5,
velocityYIncrement: 15,
velocityY: 135,
velocityZIncrement: 70
})

This comment has been minimized.

@baolw

baolw Jan 3, 2018

Author Contributor

下面的计算公式其实是在解一个一元二次方程

This comment has been minimized.

@baolw

baolw Jan 3, 2018

Author Contributor

其实不是写死的,只是我把源码略掉了math.min的情况,源码对速度做了限制

This comment has been minimized.

@binderclip

binderclip Jan 3, 2018

Collaborator

@baolw 可以贴一下源码里时间到速度的计算公式吗?

This comment has been minimized.

@baolw

baolw Jan 3, 2018

Author Contributor
var i = (Date.now() - t.mouseDownTime) / 1e3;
t.bottle.velocity.vz = Math.min(i * d.BOTTLE.velocityZIncrement, 150), t.bottle.velocity.vz = +t.bottle.velocity.vz.toFixed(2), t.bottle.velocity.vy = Math.min(d.BOTTLE.velocityY + i * d.BOTTLE.velocityYIncrement, 180), t.bottle.velocity.vy = +t.bottle.velocity.vy.toFixed(2), t.direction = new o.Vector2(t.nextBlock.obj.position.x - t.bottle.obj.position.x, t.nextBlock.obj.position.z - t.bottle.obj.position.z), t.direction.x = +t.direction.x.toFixed(2), t.direction.y = +t.direction.y.toFixed(2);

This comment has been minimized.

@pluieciel

pluieciel Jan 8, 2018

@baolw 能问下二次方程代表的什么吗?谢谢!

This comment has been minimized.

@SaneBow

SaneBow Jan 9, 2018

这个公式应该也不是很精确,不知道有没有考虑台子压缩高度,我解出的解析解带虚数,不好用js解,但是可以用线性近似解 t=(1/28)d,js中测试过可以确保无限combo

This comment has been minimized.

@baolw

baolw Jan 9, 2018

Author Contributor

是的,确实没考虑

@@ -3,6 +3,7 @@
"press_coefficient": 1.392,
"piece_base_height_1_2": 20,
"piece_body_width": 70,
"head_diameter":60,

This comment has been minimized.

@binderclip

binderclip Jan 3, 2018

Collaborator

这里对齐一下

@@ -31,13 +33,11 @@
print('请检查项目根目录从的 common 文件夹是否存在')
exit(-1)


VERSION = "1.1.1"

This comment has been minimized.

@binderclip

binderclip Jan 3, 2018

Collaborator

版本号更新到 1.2.1 吧,是重要改动了

@@ -48,6 +48,8 @@
piece_base_height_1_2 = config['piece_base_height_1_2']
# 棋子的宽度,比截图中量到的稍微大一点比较安全,可能要调节
piece_body_width = config['piece_body_width']
# 图形中圆球的直径,可以利用系统自带画图工具,用直线测量像素,如果可以实现自动识别圆球直径,那么此处将可实现全自动。
head_diameter = config['head_diameter']

This comment has been minimized.

@binderclip

binderclip Jan 3, 2018

Collaborator

这里需要 head_diameter = config.get('head_diameter', 60) 否则其他 config 里没有 head_diameter 的要挂

This comment has been minimized.

@baolw

baolw Jan 3, 2018

Author Contributor

这句是什么意思啊,我其实不会python

This comment has been minimized.

@binderclip

binderclip Jan 3, 2018

Collaborator

@baolw 从字典 config 里取 head_diameter,取不到用默认值 60

This comment has been minimized.

@baolw

baolw Jan 3, 2018

Author Contributor

那还是在其他config都加上吧,要不然使用的人不知道怎么加

This comment has been minimized.

@binderclip

binderclip Jan 3, 2018

Collaborator

也行,但那样就得在其他的里面都加上,而且有可能是错的。。

This comment has been minimized.

@baolw

baolw Jan 3, 2018

Author Contributor

嗯嗯,如果能直接检测圆球的直径就最好了,我这边家里git用不了了,要不然您改一下好了,看着需要改的地方

@binderclip

This comment has been minimized.

Copy link
Collaborator

binderclip commented Jan 3, 2018

用这个参数一加 3T 打到了 9075 分,死于水波纹的 bug
image

@baolw

This comment has been minimized.

Copy link
Contributor Author

baolw commented Jan 3, 2018

@binderclip 之前试着是把延迟设置成1.1秒才避免到水波纹bug,还有一种bug就是计算中心点的时候,条纹性色块的,导致中心点计算错误,一般情况下是不会出错的。可以很好解决距离过短和距离过长导致的蓄力不精准的问题

Repository owner deleted a comment from baolw Jan 3, 2018

@binderclip

This comment has been minimized.

Copy link
Collaborator

binderclip commented Jan 3, 2018

  1. 我暂时理解不了公式是啥意思,如果这里能解释清楚就好了
  2. 我的机型和提供的是一样的,不知道其他分辨率怎么样,希望有人能测试下
@baolw

This comment has been minimized.

Copy link
Contributor Author

baolw commented Jan 3, 2018

@binderclip 公式的意义可以私聊

@F-loat

This comment has been minimized.

Copy link
Contributor

F-loat commented Jan 3, 2018

我的手机分辨率是 2040x1080,combo到600+断的,目前还在跳 4278分

@baolw

This comment has been minimized.

Copy link
Contributor Author

baolw commented Jan 3, 2018

@F-loat 一般情况下combo断了主要是测量有些许误差,或者是当误差积累起来之后容易断掉

@F-loat

This comment has been minimized.

Copy link
Contributor

F-loat commented Jan 3, 2018

嗯,找其他分辨率测下吧再,毕竟新加入了一个参数

@F-loat

This comment has been minimized.

Copy link
Contributor

F-loat commented Jan 3, 2018

@binderclip 或者先合并,找人测试下 dev 分支,没问题就推到 master 了?

@zcjerry229

This comment has been minimized.

Copy link

zcjerry229 commented Jan 3, 2018

iphone6, 用head_diameter=42 测了一下,结果在400左右。

@baolw

This comment has been minimized.

Copy link
Contributor Author

baolw commented Jan 3, 2018

@zcjerry229 死掉之前combo情况怎么样?最后死的时候的块是什么?然后多做几次看一下,排除中心点测量的问题

@zcjerry229

This comment has been minimized.

Copy link

zcjerry229 commented Jan 3, 2018

@baolw 我试的时候combo一直不高。刚打了一局862。看了一下图应该是中心点计算不准确的问题

1514997311_d

@baolw

This comment has been minimized.

Copy link
Contributor Author

baolw commented Jan 3, 2018

@zcjerry229 按公式计算,只要中心点计算无误的话应该是可以一直跳中心点的,即使不跳中心点也是不至于死的

@mkblbj

This comment has been minimized.

Copy link

mkblbj commented Jan 3, 2018

麻烦问下针对iOS怎么改嘛,我放到iOS上,一直蓄力,不跳

@zcjerry229

This comment has been minimized.

Copy link

zcjerry229 commented Jan 3, 2018

@mkblbj 最后时间除以1000

@baolw

This comment has been minimized.

Copy link
Contributor Author

baolw commented Jan 3, 2018

zcjerry229 堆了,他提醒我了,你ios的jump那里的算法改了么,我只改了auto

@mkblbj

This comment has been minimized.

Copy link

mkblbj commented Jan 3, 2018

python初学者,不知道改的对不对,麻烦您看下
def jump(distance):
# press_time = distance * time_coefficient / 1000
# print('press time: {}'.format(press_time))
# s.tap_hold(200, 200, press_time)
# press_time = distance * time_coefficient / 1000
scale = 0.945 * 2 / head_diameter
actual_distance = distance * scale * (math.sqrt(6) / 2)
press_time = (-945 + math.sqrt(945 ** 2 + 4 * 105 * 36 * actual_distance)) / (2 * 105) * 1000 / 1000
press_time = max(press_time, 200) # 设置 200ms 是最小的按压时间
press_time = int(press_time)
print('press time: {}'.format(press_time))
# s.tap_hold(random.uniform(0, 500), random.uniform(0, 500), press_time)
s.tap_hold(random.randint(150, 250), random.randint(728, 850), press_time)

@zcjerry229

This comment has been minimized.

Copy link

zcjerry229 commented Jan 3, 2018

@baolw 我在本地只改的wechat_jump_auto_iOS.py

@zcjerry229

This comment has been minimized.

Copy link

zcjerry229 commented Jan 3, 2018

@mkblbj
press_time = (-945 + math.sqrt(945 ** 2 + 4 * 105 * 36 * actual_distance)) / (2 * 105) * 1000
press_time = max(press_time, 200) / 1000 # 设置 200ms 是最小的按压时间

@mkblbj

This comment has been minimized.

Copy link

mkblbj commented Jan 3, 2018

@zcjerry229 非常感谢,可是我改完以后,只能很小距离一点一点跳,按说我7P也是1920*1080,head_diameter也是60。
去掉这一段时press_time = int(press_time)跳的特别长两下就死了
加上时就一下一下跳,反正跳不到中心点,麻烦您看下了。

@baolw

This comment has been minimized.

Copy link
Contributor Author

baolw commented Jan 3, 2018

我qq号648599802,麻烦加一下,我看看ios怎么样。@mkblbj @zcjerry229

@baolw

This comment has been minimized.

Copy link
Contributor Author

baolw commented Jan 3, 2018

Android 应该是没问题的,才发现现在iOS的代码落后了好多,获取中心点都还是老的,所以容易死。@zcjerry229

@baolw

This comment has been minimized.

Copy link
Contributor Author

baolw commented Jan 4, 2018

@binderclip 可以merge么?另外发现iOS那边的截图有点问题,似乎做了抗锯齿,导致边缘处并不是整齐的像素块,有过度的,所以中心点不好取

@zcjerry229

This comment has been minimized.

Copy link

zcjerry229 commented Jan 4, 2018

@baolw 晚上回家了加你。 我昨天更新了ios获取中心点的代码(从android版本copy过来的),效果反而更差了。

@baolw

This comment has been minimized.

Copy link
Contributor Author

baolw commented Jan 4, 2018

@zcjerry229 你说的这个我让mkblbj这个人试了,ios的截图做了抗锯齿处理,导致中心点获取有问题

@baolw

This comment has been minimized.

Copy link
Contributor Author

baolw commented Jan 4, 2018

@leniy @Vg1ee @MrLevo520 @wangshub @Sowevo @BeiTown 帮忙测试review一下

@zcjerry229

This comment has been minimized.

Copy link

zcjerry229 commented Jan 4, 2018

@baolw ok 我看了一下这个公式还是很准的。现在的问题就差ios上中心点距离计算的准确度问题了

@MrLevo520

This comment has been minimized.

Copy link
Collaborator

MrLevo520 commented Jan 5, 2018

@baolw 是否可以fork我们的实验版本,然后在此基础上加上你的计算公式?
nightly版本目前已无需依赖配置项,暂未解决按压系数:https://github.com/wangshub/wechat_jump_game/tree/dev-no-config-nightly

@F-loat F-loat closed this Jan 5, 2018

@F-loat F-loat reopened this Jan 5, 2018

@baolw

This comment has been minimized.

Copy link
Contributor Author

baolw commented Jan 5, 2018

@MrLevo520 这个我目前没啥时间,要不你们根据我写的公式自己加一下?

@baolw

This comment has been minimized.

Copy link
Contributor Author

baolw commented Jan 5, 2018

@MrLevo520 现在最主要的问题还是要解决官方屏蔽分数的问题。

@MrLevo520

This comment has been minimized.

Copy link
Collaborator

MrLevo520 commented Jan 5, 2018

@baolw 我们自己加一下是可行的,但这是你的想法和贡献,如果我们私自加上恐怕不好,当然,如果你觉得无所谓,我们是乐于改进的。至于官方的限制,很大概率是上黑名单了

@baolw

This comment has been minimized.

Copy link
Contributor Author

baolw commented Jan 6, 2018

@MrLevo520 要不这样,下周一我提交一个,你们现在可以先用我的算法做测试之类的

@pluieciel
Copy link

pluieciel left a comment

这段计算太强啦,combo完全停不下来~~~

@baolw

This comment has been minimized.

Copy link
Contributor Author

baolw commented Jan 9, 2018

@pluieciel 请问一下你的测试机子的参数是什么,主要是屏幕分辨率和圆球直径分别是多少?公式的意义其实很简单

@pluieciel

This comment has been minimized.

Copy link

pluieciel commented Jan 9, 2018

@baolw MX5 19201080, 直径用的60;但是我玩多了发现距离特别远的时候,就跳不到白点没法combo,跳的距离偏小;
求问二次方程的意思?是速度
t?速度本身是t的函数?没理解...

@baolw

This comment has been minimized.

Copy link
Contributor Author

baolw commented Jan 10, 2018

@baolw 速度和时间确实有关系的,源码中的关系就是我上面挂的那一段。我现在的计算基础是2个块是同等高起跳和降落的。假设vz代表水平向前的速度,vy代表竖直方向的速度,那么会有公式,vzt=L,vyt-1/2gt*t=0。用这个2个式子就可以解出来上面的计算公式

@F-loat F-loat force-pushed the baolw:updae_calculate_formula branch from d3bad0d to 0341f96 Feb 2, 2018

@F-loat F-loat merged commit 6fb7fcd into wangshub:dev Feb 2, 2018

@F-loat F-loat added the label Feb 2, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment