1

我想为游戏实施 ELO 评级系统。这意味着在结束一场比赛后,我必须根据他们的实际得分计算获胜者的增加和较松的减少。

我有“最新分数”类型的排行榜,只能查看最后发送的分数。我使用 loadScoresWithCompletionHandler 加载分数,然后计算(现在只是添加不同的值),然后 endMatchInTurnWithMatchData:scores:achievements:completionHandler: 用于结束比赛并更新分数。

GKTurnBasedParticipant* player1 = [match.participants firstObject];
    GKTurnBasedParticipant* player2 = [match.participants lastObject];
    GKLeaderboard *leaderboardRequest = [[GKLeaderboard alloc] initWithPlayerIDs:@[player1.playerID, player2.playerID]];
    leaderboardRequest.timeScope = GKLeaderboardTimeScopeAllTime;
    leaderboardRequest.identifier = LEADERBOARD_ELO_RATING_ID;

[leaderboardRequest loadScoresWithCompletionHandler:^(NSArray *scores, NSError *error) {
        if(error){
            NSLog(@"%@", error);
            return;
        }
        GKScore *player1Score = [scores firstObject];
        GKScore *player2Score = [scores lastObject];

        float score1 = ((float)player1Score.value) / 1000.0f;
        float score2 = ((float)player2Score.value) / 1000.0f;

        // calculation of new score
        score1 +=10;
        score2 +=1;

        GKScore *player1NewScore = [[GKScore alloc] initWithLeaderboardIdentifier:LEADERBOARD_ELO_RATING_ID forPlayer:player1Score.playerID];
        GKScore *player2NewScore = [[GKScore alloc] initWithLeaderboardIdentifier:LEADERBOARD_ELO_RATING_ID forPlayer:player2Score.playerID];

        player1NewScore.value = (int64_t)(score1 * 1000.0f);
        player2NewScore.value = (int64_t)(score2 * 1000.0f);

        [match endMatchInTurnWithMatchData:[game.board matchData]
                                    scores:@[player1NewScore, player2NewScore]
                              achievements:@[]
                         completionHandler:^(NSError *error) {
                             if(error){// todo handle error
                             }
                         }];
    }];

获取分数并上传新分数可以正常工作,但是当我查看排行榜(使用 GKGameCenterViewController 或 GameCenter 应用程序)时,我只能看到本地玩家(结束比赛并发送最终数据的参与者)的更新分数。但是,如果我通过 loadScoresWithCompletionHandler 方法发出请求 - 我可以看到两个玩家的分数都已更新 - 但只有本地玩家的分数显示在 leaderboardController 中。

例子:

Match started:
Player A - 10 pts
Player B - 10 pts
Match ended (Player A sent these scores using method endMatchInTurnWithMatchData:scores:achievements:completionHandler:):
Player A - 15 pts
Player B - 8 pts
Match ended - loadScoresWithCompletionHandler result shows scores:
Player A - 15 pts
Player B - 8 pts
Match ended - GKGameCenterViewController or GameCenter app shows scores:
Player A - 15 pts
Player B - 10 pts

为什么会这样,我是不是做错了什么?是因为使用了 Game Center 沙盒吗?否则我应该如何通过 endMatchInTurnWithMatchData:scores:achievements:completionHandler: 准确更新两个玩家的分数?

4

1 回答 1

1

我发现,这可能只是因为使用了 Game Center Sandbox。

于 2014-04-18T07:22:15.913 回答