public async Task <IActionResult> SubmitTrainingMove(string id, string trainingSessionId, string origin, string destination, string promotion = null) { PuzzleTrainingSession session = puzzleTrainingSessionRepository.Get(trainingSessionId); SubmittedMoveResponse response = session.ApplyMove(origin, destination, promotion); return(await JsonAfterMove(response, session)); }
IActionResult JsonAfterMove(SubmittedMoveResponse response, PuzzleTrainingSession session) { dynamic jsonResp = new ExpandoObject(); if (response.Correct == 1 || response.Correct == -1) { int?loggedInUser = loginHandler.LoggedInUserId(HttpContext); if (loggedInUser.HasValue) { ratingUpdater.AdjustRating(loggedInUser.Value, session.Current.ID, response.Correct == 1, session.CurrentPuzzleStartedUtc.Value, session.CurrentPuzzleEndedUtc.Value, session.Current.Variant); } jsonResp.rating = (int)session.Current.Rating.Value; } jsonResp.success = response.Success; jsonResp.correct = response.Correct; jsonResp.check = response.Check; if (response.Error != null) { jsonResp.error = response.Error; } if (response.FEN != null) { jsonResp.fen = response.FEN; } if (response.ExplanationSafe != null) { jsonResp.explanation = response.ExplanationSafe; } if (response.Play != null) { jsonResp.play = response.Play; jsonResp.fenAfterPlay = response.FenAfterPlay; jsonResp.checkAfterAutoMove = response.CheckAfterAutoMove; } if (response.Moves != null) { jsonResp.dests = moveCollectionTransformer.GetChessgroundDestsForMoveCollection(response.Moves); } if (response.ReplayFENs != null) { jsonResp.replayFens = response.ReplayFENs; jsonResp.replayChecks = response.ReplayChecks; jsonResp.replayMoves = response.ReplayMoves; jsonResp.replayPockets = response.ReplayPockets; } if (response.Pocket != null) { jsonResp.pocket = response.Pocket; } if (response.PocketAfterAutoMove != null) { jsonResp.pocketAfterAutoMove = response.PocketAfterAutoMove; } if (response.AnalysisUrl != null) { jsonResp.analysisUrl = response.AnalysisUrl; } return(Json(jsonResp)); }
public async Task <IActionResult> SubmitTrainingDrop(string id, string trainingSessionId, string role, string pos) { PuzzleTrainingSession session = puzzleTrainingSessionRepository.Get(trainingSessionId); SubmittedMoveResponse response = session.ApplyDrop(role, pos); if (response.Success && response.Correct == SubmittedMoveResponse.INVALID_MOVE) { return(Json(new { success = true, invalidDrop = true, pos })); } return(await JsonAfterMove(response, session)); }
public IActionResult SubmitMove(string trainingSessionId, string origin, string destination, string promotion = null) { if (promotion != null && promotion.Length != 1) { return(Json(new { success = false, error = "Invalid promotion parameter." })); } EndgameTrainingSession session = endgameTrainingSessionRepository.Get(trainingSessionId); if (session == null) { return(Json(new { success = false, error = "Training session ID not found." })); } Move move = new Move(origin, destination, session.Game.WhoseTurn, promotion?[0]); SubmittedMoveResponse response = session.SubmitMove(move); dynamic jsonResp = new ExpandoObject(); jsonResp.success = response.Success; jsonResp.correct = response.Correct; jsonResp.check = response.Check; if (response.Error != null) { jsonResp.error = response.Error; } if (response.FEN != null) { jsonResp.fen = response.FEN; } if (response.FenAfterPlay != null) { jsonResp.fenAfterPlay = response.FenAfterPlay; jsonResp.checkAfterAutoMove = response.CheckAfterAutoMove; } if (response.Moves != null) { jsonResp.dests = moveCollectionTransformer.GetChessgroundDestsForMoveCollection(response.Moves); } if (response.LastMove != null) { jsonResp.lastMove = response.LastMove; } jsonResp.drawAfterAutoMove = response.DrawAfterAutoMove; jsonResp.winAfterAutoMove = response.WinAfterAutoMove; string jsonStr = JsonConvert.SerializeObject(jsonResp); return(Content(jsonStr, "application/json")); }
public IActionResult SubmitTrainingMove(string id, string trainingSessionId, string origin, string destination, string promotion = null) { PuzzleTrainingSession session = puzzleTrainingSessionRepository.Get(trainingSessionId); SubmittedMoveResponse response = session.ApplyMove(origin, destination, promotion); dynamic jsonResp = new ExpandoObject(); if (response.Correct == 1 || response.Correct == -1) { int?loggedInUser = loginHandler.LoggedInUserId(HttpContext); if (loggedInUser.HasValue) { ratingUpdater.AdjustRating(loggedInUser.Value, session.Current.ID, response.Correct == 1, session.CurrentPuzzleStartedUtc.Value, session.CurrentPuzzleEndedUtc.Value, session.Current.Variant); } jsonResp.rating = (int)session.Current.Rating.Value; } jsonResp.success = response.Success; jsonResp.correct = response.Correct; jsonResp.check = response.Check; if (response.Error != null) { jsonResp.error = response.Error; } if (response.FEN != null) { jsonResp.fen = response.FEN; } if (response.ExplanationSafe != null) { jsonResp.explanation = response.ExplanationSafe; } if (response.Play != null) { jsonResp.play = response.Play; jsonResp.fenAfterPlay = response.FenAfterPlay; jsonResp.checkAfterAutoMove = response.CheckAfterAutoMove; } if (response.Moves != null) { jsonResp.dests = moveCollectionTransformer.GetChessgroundDestsForMoveCollection(response.Moves); } if (response.ReplayFENs != null) { jsonResp.replayFens = response.ReplayFENs; jsonResp.replayChecks = response.ReplayChecks; jsonResp.replayMoves = response.ReplayMoves; } return(Json(jsonResp)); }