我想为游戏实施ELO评级系统。这意味着在结束游戏之后,我必须计算胜利者的增加量,并从实际分数中减少松散度。
我的排行榜类型为"最新分数"只看到最后发送的分数。 我使用loadScoresWithCompletionHandler来加载得分,然后计算(现在只是添加不同的值)然后使用endMatchInTurnWithMatchData:scores:achievement: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精确更新两个玩家的得分:得分:achievement:completionHandler:?
答案 0 :(得分:1)
我发现,这可能只是因为使用了Game Center Sandbox。