private GamePlayer CreateAgentFromComboboxObject(InGameForm form, object text, StoneColor color) { TimeControl timeControl = null; if (rbNoTimeControl.Checked) { timeControl = new NoTimeControl(); } else if (rbAbsoluteTiming.Checked) { timeControl = new AbsoluteTimeControl(1); } else if (rbCanadianTiming.Checked) { timeControl = new CanadianTimeControl(TimeSpan.FromSeconds(10), 5, TimeSpan.FromSeconds(10)); } else if (rbJapaneseTiming.Checked) { timeControl = new JapaneseTimeControl(20, 30, 3); } if (text is string && ((string)text) == "Human") { GamePlayer human = new HumanPlayerBuilder(color) .Name(color.ToString()) .Rank("NR") .Clock(timeControl) .Build(); (human.Agent as HumanAgent).MoveRequested += (e, e2) => { form.GuiAgent_PleaseMakeAMove(null, null); }; return(human); } if (text is IAIProgram) { IAIProgram newInstance = (IAIProgram)Activator.CreateInstance(text.GetType()); GamePlayer aiPlayer = new AiPlayerBuilder(color) .Name(text.ToString() + "(" + color.ToIgsCharacterString() + ")") .Rank("NR") .Clock(timeControl) .AiProgram(newInstance) .Build(); return(aiPlayer); } throw new Exception("This agent cannot be handled yet."); }
public async Task <IgsGame> StartObserving(IgsGameInfo gameInfo) { if (this.igsConnection.GamesBeingObserved.Any(g => g.Info.IgsIndex == gameInfo.IgsIndex)) { // We are already observing this game. return(null); } var response = await MakeRequestAsync("observe " + gameInfo.IgsIndex); if (response.IsError) { // Observing failed. return(null); } var heading = response.GetGameHeading(); if (heading == null) { return(null); } if (heading.BlackName != gameInfo.Black.Name || heading.WhiteName != gameInfo.White.Name) { // It's a different game now. return(null); } TimeControl blackClock = new CanadianTimeControl(TimeSpan.Zero, 25, TimeSpan.FromMinutes(gameInfo.ByoyomiPeriod)).UpdateFrom( heading.BlackTimeRemaining); TimeControl whiteClock = new CanadianTimeControl(TimeSpan.Zero, 25, TimeSpan.FromMinutes(gameInfo.ByoyomiPeriod)).UpdateFrom( heading.WhiteTimeRemaining); if (heading.BlackTimeRemaining.PeriodStonesLeft == 0 && heading.BlackTimeRemaining.PeriodTimeLeft == TimeSpan.Zero && heading.BlackTimeRemaining.MainTimeLeft == TimeSpan.Zero) { blackClock = new NoTimeControl(); whiteClock = new NoTimeControl(); } var titleLine = response.LastOrDefault(line => line.Code == IgsCode.Info); string gameName = null; if (titleLine != null) { gameName = IgsRegex.ParseTitleInformation(titleLine); } var blackPlayer = new IgsPlayerBuilder(StoneColor.Black, this.igsConnection) .Name(gameInfo.Black.Name) .Rank(gameInfo.Black.Rank) .Clock(blackClock) .Build(); var whitePlayer = new IgsPlayerBuilder(StoneColor.White, this.igsConnection) .Name(gameInfo.White.Name) .Rank(gameInfo.White.Rank) .Clock(whiteClock) .Build(); var onlineGame = GameBuilder.CreateOnlineGame(gameInfo) .Connection(this.igsConnection) .BlackPlayer(blackPlayer) .WhitePlayer(whitePlayer) .Ruleset(RulesetType.Japanese) .Komi(gameInfo.Komi) .BoardSize(gameInfo.BoardSize) .Name(gameName) .Build(); this.igsConnection.GamesBeingObserved.Add(onlineGame); this.igsConnection.GamesYouHaveOpened.Add(onlineGame); this.igsConnection.MakeUnattendedRequest("moves " + gameInfo.IgsIndex); return(onlineGame); }