public Board GetBoardWithDecisonExecuted(Board state) { GameTree gameTree = new GameTree(state, Me, 2, 0); gameTree.Expand(); Board statusQuo = gameTree.Children.ElementAt(0).BoardState; //it may not be true status quo, but only when I can't win Board boardOnWhichIOccupyMiddlePoint = null; foreach (GameTree child in gameTree.Children) { if (IfIWin(GameResultChecker.CheckGameResult(child.BoardState))) { return(child.BoardState); } foreach (GameTree child2 in child.Children) { if (IfILoose(GameResultChecker.CheckGameResult(child2.BoardState))) { goto GoFurther; } } if (child.BoardState.PositionAt(1, 1).Status == Me) { boardOnWhichIOccupyMiddlePoint = child.BoardState; } statusQuo = child.BoardState; GoFurther: continue; } if (boardOnWhichIOccupyMiddlePoint == null) { return(statusQuo); } else { return(boardOnWhichIOccupyMiddlePoint); } }
public async Task <IActionResult> Move([FromBody] List <Position> board, CancellationToken token) { foreach (var pos in board) { pos.TranslateFromInnerSystem(); } var query = new Requests.AiMove.Query() { Board = board }; var result = await Mediator.Send(query, token); var gameResult = GameResultChecker.CheckGameResult(new Board(result)); foreach (var pos in result) { pos.TranslateToInnerSystem(); } return(new JsonResult(new { Game = result, GameResult = gameResult })); }