diff --git a/Solution/CubeService/Controllers/CubeController.cs b/Solution/CubeService/Controllers/CubeController.cs index f842a9e..2e074c1 100644 --- a/Solution/CubeService/Controllers/CubeController.cs +++ b/Solution/CubeService/Controllers/CubeController.cs @@ -1,6 +1,7 @@ using LibNetCube; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; +using System.Collections.Generic; namespace CubeService.Controllers { @@ -21,12 +22,39 @@ public IActionResult Reset() return Ok(); } + [HttpPost("[action]")] public IActionResult ApplyShuffle([FromQuery] string? shuffle = null) { + List moves = new List(); + + if (shuffle is string moveString && moveString.Length > 0) + { + try + { + moves = MoveParser.ParseMoveSequence(moveString); + } + catch + { + return BadRequest(); + } + } + + if (moves.Count == 0) + { + moves = ScrambleAlgorithm.GenerateScramble(); + } + + _cubePuzzle.Reset(); + foreach(CubeMove move in moves) + { + _cubePuzzle.PerformMove(move); + } + return Ok(); } + [HttpPost("[action]")] public IActionResult PerformMove([FromQuery] string? move = null) {