如何在Google App Engine中实施互联网高分 [英] How to implement internet high scores in Google App Engine

查看:93
本文介绍了如何在Google App Engine中实施互联网高分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为我的游戏实现互联网高分。并向玩家反馈他们拥有的位置(不仅是top100或类似的东西)。
在正常的SQL中,它看起来像这样:

SELECT COUNT(*)FROM得分WHERE points>:newUsersPoints

和GQL有类似的东西。

db.GqlQuery(SELECT * FROM Score WHERE points>:1,newUsersPoints).count()



但是由于count()仅限于1000,所以对我而言并不会很有用。
你有什么想法来实现这一点吗?

我有两个

首先:


  1. 使用sharding counters idea( http://code.google.com/intl/pl/appengine/articles/sharding_counters.html
    创建新的表格在一定范围内有多少分数(from_points,to_points)


  2. 总结所有来自上表的计数器,其中range.to_points< newUsersPoints

  3. 查找多少分数大于新分数为
    db的范围内的分数.GqlQuery(SELECT * FROM Score WHERE points> :1 AND points> =:2 AND points <:3,newUsersPoints,range.from_points,range.to_points).count()+ sumfrom2


  4. 查找新分数的范围并增加其计数器


  5. 分割范围哪个计数器大于1000(或999),因此3不会达到限额


  6. 在分数表中添加新分数




  7. 这很复杂且容易出错。在添加分数之前,我们可能会增加一些范围和超时。 (不是交易)



    第二个想法:

    不时(每天一次?)对所有分数进行排序通过点和给他们新的位置(脚本可能会超时,所以我们必须做大块)



    为了找出在哪个地方我们只是做新分数



    db.GqlQuery(SELECT * FROM Score WHERE points>:1 LIMIT 1,newUsersPoints).get()。precalculated_position + 1

    其他想法?

    解决方案

    我在几个GAE应用中实现了Ranker。他们是Facebook应用程序,有数以千计的成千上万的人在玩。它运作良好,但对我的目的来说,它有一个很大的缺点:你需要事先声明参与者的分数落入的最终范围。所以这是不好的,原因有两个:


    1. 如果您的比赛没有结束,人们的分数可以继续攀升而没有上限,那么您就会瘫痪。


    2. 在比赛开始时,当每个人都聚集在零点附近时,ranker.py使用的树结构效率不高。这个树变得很深,几乎没有任何宽度。


    换句话说,ranker.py对于在这种情况下,你的参赛者的得分在一个已知的价值范围内是随机分布的。对于其他用途,它不是最佳的。

    我希望尽快开发一个更普遍有用的排名引擎。当这种情况发生时,肯定会更新这个线程!


    I want to implement internet high scores for my game. And give feedback to players which place they have (not only top100 or something like that). In normal SQL it would look like that:

    SELECT COUNT(*) FROM Scores WHERE points > :newUsersPoints

    and GQL have something similar

    db.GqlQuery("SELECT * FROM Score WHERE points > :1", newUsersPoints).count()

    but since count() is limited only to 1000 it won't be very useful in my case. Do you have any ideas on how to implement this?

    I have two

    First:

    1. Use sharding counters idea (http://code.google.com/intl/pl/appengine/articles/sharding_counters.html) Create new "table" that stores how many scores are in some range(from_points, to_points)

    2. Sum up all counters from above table where range.to_points < newUsersPoints

    3. Find how many scores are bigger than scores in range where the new score is db.GqlQuery("SELECT * FROM Score WHERE points > :1 AND points >= :2 AND points < :3", newUsersPoints, range.from_points, range.to_points).count() + sumfrom2

    4. Find range in which new score is in and increment its counter

    5. Split ranges which counter is bigger than 1000 (or 999) so that 3. wouldn't reach the limit

    6. Add new score to scores table

    Which is quite complicated and error prone. We might increment some range and Timeout before adding the score. (not transactional)

    Second idea:

    From time to time (once every day?) sort all scores by points and give them new positions (script might Timeout so we have to do it in chunks)

    To find out at which place new score is we just do

    db.GqlQuery("SELECT * FROM Score WHERE points > :1 LIMIT 1", newUsersPoints).get().precalculated_position + 1

    Any other ideas?

    解决方案

    I've implemented Ranker in several GAE apps. They're Facebook Applications that have thousands up to hundreds of thousands of people playing. It works well, but for my purposes it has one big drawback: you need to declare in advance the final range over which the participant's scores will fall in. So this is bad for two reasons:

    1. if you have a contest without an end, where people's scores can continue to climb without upper limit, you're hooped.

    2. at the beginning of a contest, when everyone is bunched together near zero, the tree structure used by ranker.py is not efficient. the tree goes very deep and uses barely any of its breadth.

    In other words, ranker.py is excellent for the case where you have contestants whose scores are randomly distributed in an even way over a known range of values. For other uses it is less than optimal.

    I'm hoping to develop a more generally useful ranking engine soon. Will certainly update this thread when that happens!

    这篇关于如何在Google App Engine中实施互联网高分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆