public ActionResult MakeBotStep(PlayerVsGeneticBotMakeBotStepCommand command)
        {
            var answer = this.playerVsGeneticBotCommandHandler.ExecuteCommand(command);

            if (answer.GameProcessStatistic.GameStatus != GameStatus.InProgress)
            {
                if (answer.GameProcessStatistic.GameStatus == GameStatus.Draw)
                {
                    return(RedirectToAction("TakeDraw", new PlayerVsGeneticBotTakeDrawCommand {
                        GameId = command.GameId
                    }));
                }
                else
                {
                    return(RedirectToAction("WinGame", new PlayerVsGeneticBotWinGameCommand {
                        GameId = command.GameId
                    }));
                }
            }

            return(this.View(answer));
        }
        public PlayerVsGeneticBotMakeBotStepCommandResult ExecuteCommand(PlayerVsGeneticBotMakeBotStepCommand command)
        {
            PlayerVsGeneticBotMakeBotStepCommandResult result;

            using (var context = new TicTacToeContext())
            {
                var game  = context.Set <Game>().Include(game1 => game1.Field).FirstOrDefault(game1 => game1.GameId == command.GameId);
                var field = game.Field;

                var fieldCode = GameHelper.GetFieldByNumber(game.FieldNumber, field);
                var gameField = this.fieldStateConverter.StringToGameField(fieldCode);

                var nextStep      = GeneticBot.GetStep(gameField, context);
                var nextGameField = this.stepMaker.MakeStep(gameField, nextStep.X, nextStep.Y);

                var nextFieldCode = this.fieldStateConverter.GameFieldToString(nextGameField);
                var nextField     = GameHelper.GetFieldByCode(nextFieldCode, context);
                var nextNumber    = GameHelper.GetCodeNumber(nextFieldCode, nextField);

                var gameProcessStatistic = this.gameProcessStatisticProvider.GetGameProcessStatistic(nextGameField);

                game.Field       = nextField;
                game.FieldNumber = nextNumber;
                game.Proccess   += "|" + nextField.FieldId;
                context.Set <Game>().AddOrUpdate(game);
                context.SaveChanges();

                result = new PlayerVsGeneticBotMakeBotStepCommandResult
                {
                    CellSize             = GameFieldConstants.LineLength,
                    GameId               = command.GameId,
                    GameField            = nextGameField,
                    GameProcessStatistic = gameProcessStatistic,
                    BotStep              = nextStep
                };
            }

            return(result);
        }