From cf4d1e91427c0af8abae92fa2a9742d0620cd158 Mon Sep 17 00:00:00 2001 From: eeoooue Date: Fri, 23 May 2025 13:52:55 +0100 Subject: [PATCH 1/2] implemented ApplyShuffle --- .../CubeService/Controllers/CubeController.cs | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/Solution/CubeService/Controllers/CubeController.cs b/Solution/CubeService/Controllers/CubeController.cs index f842a9e..bb3a34b 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) + { + 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) { From 47aefde265ab45a7821ce39d792f4feef0bc42ac Mon Sep 17 00:00:00 2001 From: eeoooue Date: Fri, 23 May 2025 13:56:49 +0100 Subject: [PATCH 2/2] Update CubeController.cs --- Solution/CubeService/Controllers/CubeController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Solution/CubeService/Controllers/CubeController.cs b/Solution/CubeService/Controllers/CubeController.cs index bb3a34b..2e074c1 100644 --- a/Solution/CubeService/Controllers/CubeController.cs +++ b/Solution/CubeService/Controllers/CubeController.cs @@ -28,7 +28,7 @@ public IActionResult ApplyShuffle([FromQuery] string? shuffle = null) { List moves = new List(); - if (shuffle is string moveString) + if (shuffle is string moveString && moveString.Length > 0) { try {