public void Finish (string matchId, byte[] data, MatchOutcome outcome, Action<bool> callback)
        {
            Logger.d(string.Format("iOSTbmpClient.Finish matchId={0}, outcome={1}", matchId, outcome.ToString()));
            // We probably need to convert our match outcome into something we can read in


            var resultsOutput = new List<Dictionary<string, object>>();
            List<string> allParticipants = outcome.ParticipantIds;
            Dictionary<string, object> nextResult;
            foreach (string participantID in allParticipants) {
                Logger.d("Getting results for " + participantID);
                nextResult = new Dictionary<string, object>();
                // Maybe don't add them if their result is unset? Check with Bruno on this one
                if (outcome.GetResultFor(participantID) != MatchOutcome.ParticipantResult.Unset) {
                    nextResult["participantId"] = participantID;
                    nextResult["placing"] = outcome.GetPlacementFor(participantID);
                    nextResult["result"] = convertParticipantResultToiOSInt(outcome.GetResultFor(participantID));
                }
                resultsOutput.Add(nextResult);
            }
            string resultsAsJson = Json.Serialize(resultsOutput);
            Logger.d("JSonified results are " + resultsAsJson);

            sCallbackSuccessId++;
            sMatchSuccessCallbacks.Add(sCallbackSuccessId, callback);
            GPGSTBMPFinishMatch(matchId, data, data.Length, resultsAsJson, sCallbackSuccessId, TbmpMatchSuccessCallback);

        }
    private void DoTbmpFinish()
    {
        if (mMatch == null)
        {
            mStatus = "No match is active.";
            return;
        }

        if (mMatch.TurnStatus != TurnBasedMatch.MatchTurnStatus.MyTurn)
        {
            mStatus = "Not my turn.";
            return;
        }

        // I win; every one else loses
        MatchOutcome outcome = new MatchOutcome();
        foreach (Participant p in mMatch.Participants)
        {
            if (p.ParticipantId.Equals(mMatch.SelfParticipantId))
            {
                outcome.SetParticipantResult(p.ParticipantId, MatchOutcome.ParticipantResult.Win, 1);
            }
            else
            {
                outcome.SetParticipantResult(p.ParticipantId, MatchOutcome.ParticipantResult.Loss, 2);
            }
        }

        SetStandBy("Finishing match...");
        PlayGamesPlatform.Instance.TurnBased.Finish(
            mMatch,
            System.Text.ASCIIEncoding.Default.GetBytes("the end!"),
            outcome,
            (bool success) =>
            {
                EndStandBy();
                ShowEffect(success);
                mStatus = success ? "Successfully finished match." : "Failed to finish match.";
                if (success)
                {
                    mMatch = null;
                    mUi = Ui.Tbmp;
                }
            });
    }
 private static int convertParticipantResultToiOSInt(MatchOutcome.ParticipantResult result)  {
     switch (result) {
     case MatchOutcome.ParticipantResult.Unset:
         return -1;
     case MatchOutcome.ParticipantResult.None:
         return 3;
     case MatchOutcome.ParticipantResult.Win:
         return 0;
     case MatchOutcome.ParticipantResult.Loss:
         return 1;
     case MatchOutcome.ParticipantResult.Tie:
         return 2;
     }
     // Don't know what this is. Best to leave it as None for now.
     return 3;
 }
    void FinishMatch() {
        bool winnerIsMe = mMatchData.Winner == mMyMark;

        // define the match's outcome
        MatchOutcome outcome = new MatchOutcome();
        outcome.SetParticipantResult(mMatch.SelfParticipantId,
            winnerIsMe ? MatchOutcome.ParticipantResult.Win :
                MatchOutcome.ParticipantResult.Loss);
        outcome.SetParticipantResult(GetAdversaryParticipantId(),
            winnerIsMe ? MatchOutcome.ParticipantResult.Loss :
                MatchOutcome.ParticipantResult.Win);

        // finish the match
        SetStandBy("Sending...");
        PlayGamesPlatform.Instance.TurnBased.Finish(mMatch.MatchId, mMatchData.ToBytes(),
                    outcome, (bool success) => {
            EndStandBy();
            mFinalMessage = success ? (winnerIsMe ? "YOU WON!" : "YOU LOST!") :
                "ERROR finishing match.";
        });
    }
 public static int GetAndroidParticipantResult(MatchOutcome.ParticipantResult result) {
     switch (result) {
         case MatchOutcome.ParticipantResult.Win:
             return JavaConsts.MATCH_RESULT_WIN;
         case MatchOutcome.ParticipantResult.Loss:
             return JavaConsts.MATCH_RESULT_LOSS;
         case MatchOutcome.ParticipantResult.Tie:
             return JavaConsts.MATCH_RESULT_TIE;
         case MatchOutcome.ParticipantResult.None:
             return JavaConsts.MATCH_RESULT_NONE;
         default:
             return JavaConsts.MATCH_RESULT_UNINITIALIZED;
     }
 }
 private static Types.MatchResult ResultToMatchResult(MatchOutcome.ParticipantResult result)
 {
     switch (result)
     {
         case MatchOutcome.ParticipantResult.Loss:
             return Types.MatchResult.LOSS;
         case MatchOutcome.ParticipantResult.None:
             return Types.MatchResult.NONE;
         case MatchOutcome.ParticipantResult.Tie:
             return Types.MatchResult.TIE;
         case MatchOutcome.ParticipantResult.Win:
             return Types.MatchResult.WIN;
         default:
             Logger.e("Received unknown ParticipantResult " + result);
             return Types.MatchResult.NONE;
     }
 }
        public void Finish(TurnBasedMatch match, byte[] data, MatchOutcome outcome,
                       Action<bool> callback)
        {
            callback = Callbacks.AsOnGameThreadCallback(callback);
            FindEqualVersionMatch(match, callback, foundMatch =>
                {
                    ParticipantResults results = foundMatch.Results();

                    foreach (string participantId in outcome.ParticipantIds)
                    {
                        Types.MatchResult matchResult =
                            ResultToMatchResult(outcome.GetResultFor(participantId));
                        uint placing = outcome.GetPlacementFor(participantId);

                        if (results.HasResultsForParticipant(participantId))
                        {
                            // If the match already has results for this participant, make sure that they're
                            // consistent with what's already there.
                            var existingResults = results.ResultsForParticipant(participantId);
                            var existingPlacing = results.PlacingForParticipant(participantId);

                            if (matchResult != existingResults || placing != existingPlacing)
                            {
                                Logger.e(string.Format("Attempted to override existing results for " +
                                        "participant {0}: Placing {1}, Result {2}",
                                        participantId, existingPlacing, existingResults));
                                callback(false);
                                return;
                            }
                        }
                        else
                        {
                            // Otherwise, get updated results and dispose of the old ones.
                            var oldResults = results;
                            results = oldResults.WithResult(participantId, placing, matchResult);
                            oldResults.Dispose();
                        }
                    }

                    mTurnBasedManager.FinishMatchDuringMyTurn(foundMatch, data, results,
                        response => callback(response.RequestSucceeded()));
                });
        }
 public void Finish(string matchId, byte[] data, MatchOutcome outcome, Action<bool> callback) {
     Logger.d(string.Format("AndroidTbmpClient.Finish matchId={0}, data={1} outcome={2}",
             matchId, data == null ? "(null)" : data.Length + " bytes", outcome));
                 
     Logger.d("Preparing list of participant results as Android ArrayList.");
     AndroidJavaObject participantResults = new AndroidJavaObject("java.util.ArrayList");
     if (outcome != null) {
         foreach (string pid in outcome.ParticipantIds) {
             Logger.d("Converting participant result to Android object: " + pid);
             AndroidJavaObject thisParticipantResult = new AndroidJavaObject(
                 JavaConsts.ParticipantResultClass, pid,
                 JavaUtil.GetAndroidParticipantResult(outcome.GetResultFor(pid)),
                 outcome.GetPlacementFor(pid));
             
             // (yes, the return type of ArrayList.add is bool, strangely)
             Logger.d("Adding participant result to Android ArrayList.");
             participantResults.Call<bool>("add", thisParticipantResult);
             thisParticipantResult.Dispose();
         }
     }
     
     TbmpApiCall("tbmp finish w/ outcome", "finishMatch", callback, null, 
             matchId, data, participantResults);
 }