Gamekit / gamecenter random matchmaking programmatically - ios

I am trying to implement random matchmaking programmatically with my own custom userinterface.
I'm kinda stuck..
using this code found at the apple site I can create a match without problems
- (void)findProgrammaticMatch
{
GKMatchRequest *request = [[GKMatchRequest alloc] init];
request.minPlayers = 2;
request.maxPlayers = 2;
[GKTurnBasedMatch findMatchForRequest: request withCompletionHandler:^(GKTurnBasedMatch *match, NSError *error)
{
if(error)
NSLog(#"ERROR");
if (match) {
NSLog(#"STARTING MATCH");
}
}];
}
and if I do match.participants.count I get the number 2...
but one participant is me and the other is null
What ive done to test is create 2 sandbox accounts and I ran the same code with my other game center account, and I got a new game created,.. but it didnt match them for some reason.. am I missing something?
ive been looking for examples on google, but I can't seem to find any.. if any of you know anywhere I can find some examples, I would be most grateful

Well, you might be missing out an essential point in turn based match making. When the user starts an automatch if he is not connected to an existing match it starts a fresh game and user takes the first turn. Only after HE COMPLETES HIS TURN, other users can connect to this game. So if you are making a 2 player match: one user should start a fresh game with the other user being null at that moment and the other user should connect to this existing game after the first one finished his turn (endTurnWithMatchData called)
This is not very clear in documentation (I despise the gamecenter documentation, unclear & incomplete) but it is the case for sdk 6. I think it will change in the near future.

Related

Getting all the user's friends that are using the app

I know that by the title this question has been asked a lot, but with the new Facebook 4.0 sdk this is a problem.
I know that if i call
[self FCMSendOpenGraphRequestWithPath:#"me/friends" andCompletionHandler:^(BOOL seccess, id result, NSError *error) {
if (seccess) {
}
}else{
}
}];
I will get all the user's friends that are using my app and that fit into one paging page (i have noticed that one page can hold 25 friends).
My problem is what happens when i need to get the page 2,3,4..etc'?
I know that if i call the graph call with the 'next' field i will get the next page. But because the Facebook sdk uses only completionHandlers using recursion won't work, and i don't want to hard code all the method call obviously.
All advices will help,
Thanks

Cannot receive friend invites in Game center

I'm creating a live multiplayer game with 2 players through game center.
I followed Ray Wenderlich's tutorial on game center and I tried to set up the invite friends. I set up the call back just like apple said:
if ([GKLocalPlayer localPlayer].isAuthenticated) {
[GKMatchmaker sharedMatchmaker].inviteHandler = ^(GKInvite *acceptedInvite, NSArray *playersToInvite) {
NSLog(#"Received invite");
self.pendingInvite = acceptedInvite;
self.pendingPlayersToInvite = playersToInvite;
[self inviteReceived];
};
}
I even tested whether the block property is actually set. It is.
I'm in sandbox with a simulator and an iPhone 5 both at iOS7. I couldn't receive ANY invitations (see screenshot). I enabled notification center, checked accept invitation in settings, but the block is never called. Random match worked fine though.
Solved it by borrowing someone else's device instead of using the simulator.

Implement my own a custom GKTurnBasedMatchmakerViewController

I'm sure there are questions similar to this, but I couldn't find an example. I'm trying to recreate the apple GKTurnBasedMatchmakerViewController for my turn based game with my own custom interface for my turn based iphone game. I'm having trouble getting all the options to display correctly so I was hoping someone had a working example. My current code is this:
-(void)getCurrentGamesFromServer {
[GKTurnBasedMatch loadMatchesWithCompletionHandler:^(NSArray *matches, NSError *error) {
if(matches){
for (GKTurnBasedMatch *myMatch in matches) {
//this is, I believe, also where we need to consider invitations. available instance methods provided by GC are: acceptInviteWithCompletionHandler and declineInviteWithCompletionHandler
if(myMatch.status == 1){ //ongoing game
if([myMatch.currentParticipant.playerID isEqualToString:[GKLocalPlayer localPlayer].playerID]){ //if it's my turn
//here we need to populate the table by adding our matches to mcurrentgamesarray. after all the matches have been added, reload the tableview
NSLog(#"active game that is my turn");
[self.mCurrentGamesArray addObject:myMatch];
}
else{
NSLog(#"other turn or an invite from another player waiting to hear from you");
}
}
}
}
[_mCurrentGamesTableView reloadData];
}];
}
As you can see, the only games I'm grabbing right now are games where the status is 1 (ongoing game) and the current participant ID is my ID.
to get games that were not my turn, I tried doing games where it was not my ID, but it included invites with it and I couldn't figure out how to separate them out.
Basically, I'd like to have a section of games where it is my turn, a section where it is not my turn but games are still active, a section of completed old games, and a section for invites. does anyone have a working example, or a page they can send me to that explains the best practices for what I'm trying to do? Thanks for your help.

ios can players form teams of 2 and play other teams of 2 in game center [duplicate]

I have a "Play Now" button in my app that allows players to be auto-matched with other random players. Maybe I'm missing this somewhere in the docs, but how do I write the code to auto match players?
The Game Center sandbox server has been messed up the last few days, so I'm having a hard time trying different things since I have to guess because the Game Kit docs aren't exactly clear on how to do this. Currently, I have code setup (but untested) to create a match with a friend...
NSArray *playerList = [NSArray arrayWithObject:pid];
GKMatchRequest *request = [[[GKMatchRequest alloc] init] autorelease];
request.minPlayers = 2;
request.maxPlayers = 4;
request.playersToInvite = playerList;
[[self waitingIndicator] startAnimating];
[[GKMatchmaker sharedMatchmaker] findMatchForRequest:request withCompletionHandler:^(GKMatch *match, NSError *error) {
if (error)
{
//handle error
}
else if (match != nil)
{
self.myMatch = match;
//start match code
}
}];
But how do I auto match two random people looking for a game? My guess, since the docs don't say it, or I'm missing it, is that in order to create an auto match, I simply set the playersToInvite property of the match object to nil? If not, how do I create an auto match?
One other question, while we're on the topic, the Game Kit docs site a few common matchmaking scenarios, one of them being...
A player can also create a network
match using the Game Center
application. When they invite a friend
into a multiplayer game, your
application is launched on both
devices, and each copy of your
application receives an invitation to
join the game.
But I can't figure out how to do this in the Game Center app for testing purposes. How does a user create a network match using the Game Center app? I don't see any buttons for that anywhere in the Game Center app.
Thanks in advance for your wisdom!
Ok, now that the sandbox Game Center server is back up, I was able to confirm that auto-matching works by setting the playersToInvite property to nil, or not setting it all.

How to get total No. of players from Leaderboard

Is there any way I can get how many player has played my game and successfully reported the score on Leaderboard?
I am currently working on Marmalade for iOS, so I'd prefer if you can let me know the solution in Marmalade. But if not possible, kindly let me know the solution at least in Objective C.
Finally found the solution after searching in the marmalade example. Following is the steps for to get the total count -
1.First you need to authenticate the player to gamecenter, it's like Login. THe authentication method is -
s3eIOSGameCenterAuthenticate(AuthenticationCallback, NULL);
2.Next we need to load the scores from the leaderboard
s3eIOSGameCenterLeaderboardLoadScores(leaderboard,loadScoreCallBack);
3.Now in the callback method i.e. loadScoreCallBack, you will get the TotalCount.
void loadScoreCallBack(s3eIOSGameCenterLoadScoresResult* result)
{
int TotalCount= result->m_ScoreCount;
}

Resources