private void ScoreGame(IgsGame gameInfo, float blackScore, float whiteScore) { Scores scores = new Scores(blackScore, whiteScore); GamePlayer winner = null; if (scores.BlackScore > scores.WhiteScore) { winner = gameInfo.Controller.Players.Black; } else if (scores.BlackScore < scores.WhiteScore) { winner = gameInfo.Controller.Players.White; } else { winner = null; } if (winner != null) { GetConnector(gameInfo.Info).EndTheGame( GameEndInformation.CreateScoredGame(winner, gameInfo.Controller.Players.GetOpponentOf(winner), scores)); } else { GetConnector(gameInfo.Info).EndTheGame( GameEndInformation.CreateDraw(gameInfo.Controller.Players, scores)); } }
/// <summary> /// Scores the game and moves us to the Finished phase. /// </summary> /// <param name="e">If this parameter is set, then it overriddes scores that would be determined from life/death determination and ruleset.</param> internal void ScoreIt(Scores e = null) { Scores scores = e; if (scores == null) { scores = Controller.Ruleset.CountScore(Controller.GameTree.LastNode, DeadPositions, Controller.Info.Komi); } bool isDraw = Math.Abs(scores.BlackScore - scores.WhiteScore) < 0.2f; GamePlayer winner; GamePlayer loser; if (isDraw) { winner = Controller.Players.Black; loser = Controller.Players.White; Controller.OnDebuggingMessage("It's a draw."); } else if (scores.BlackScore > scores.WhiteScore) { winner = Controller.Players.Black; loser = Controller.Players.White; } else if (scores.BlackScore < scores.WhiteScore) { winner = Controller.Players.White; loser = Controller.Players.Black; } else { throw new Exception("This cannot happen."); } if (!isDraw) { Controller.OnDebuggingMessage(winner + " wins."); } Controller.OnDebuggingMessage("Scoring complete! " + scores.AbsoluteScoreDifference); GameEndInformation gameEndInfo = null; gameEndInfo = isDraw ? GameEndInformation.CreateDraw(Controller.Players, scores) : GameEndInformation.CreateScoredGame(winner, loser, scores); Controller.EndGame(gameEndInfo); }
public override void Process(KgsConnection connection) { var game = connection.Data.GetGame(ChannelId); var controller = game.Controller; var players = game.Controller.Players; var black = game.Controller.Players.Black; var white = game.Controller.Players.White; GameEndInformation gameEndInfo = null; if (Score.IsFloat) { if (Score.Float == 0) { gameEndInfo = GameEndInformation.CreateDraw(controller.Players, new Rules.Scores(0, 0)); } else { if (Score.Float > 0) { gameEndInfo = GameEndInformation.CreateScoredGame(controller.Players.Black, controller.Players.White, new Rules.Scores(Score.Float, 0)); } else { gameEndInfo = GameEndInformation.CreateScoredGame(controller.Players.White, controller.Players.Black, new Rules.Scores(0, -Score.Float)); } } } else { switch (Score.String) { case "B+RESIGN": case "B+FORFEIT": gameEndInfo = GameEndInformation.CreateResignation(white, players); break; case "W+RESIGN": case "W+FORFEIT": gameEndInfo = GameEndInformation.CreateResignation(black, players); break; case "B+TIME": gameEndInfo = GameEndInformation.CreateTimeout(white, players); break; case "W+TIME": gameEndInfo = GameEndInformation.CreateTimeout(black, players); break; case "NO_RESULT": gameEndInfo = GameEndInformation.CreateDraw(players, new Rules.Scores(0, 0)); break; case "UNKNOWN": case "UNFINISHED": default: gameEndInfo = GameEndInformation.CreateCancellation(players); break; } } controller.KgsConnector.EndTheGame(gameEndInfo); }