From 292411eb8dd2cde5433574672fede080889f3c61 Mon Sep 17 00:00:00 2001 From: PenguinEncounter <49845522+penguinencounter@users.noreply.github.com> Date: Sat, 9 Sep 2023 15:33:25 +0000 Subject: [PATCH 1/2] Aly's swizzle.diff --- elm.json | 1 + gen/source.js | 160 ++++++++++++++++++++- src/Logic/App/Patterns/PatternRegistry.elm | 2 +- src/Logic/App/Patterns/Stack.elm | 74 ++++++++++ 4 files changed, 235 insertions(+), 2 deletions(-) diff --git a/elm.json b/elm.json index 9c7831b..46fa554 100644 --- a/elm.json +++ b/elm.json @@ -23,6 +23,7 @@ "elm-community/array-extra": "2.6.0", "elm-community/json-extra": "4.3.0", "elm-community/list-extra": "8.7.0", + "elm-community/maybe-extra": "5.3.0", "ianmackenzie/elm-geometry": "3.9.1", "ianmackenzie/elm-units": "2.9.0", "jinjor/elm-contextmenu": "2.0.0", diff --git a/gen/source.js b/gen/source.js index 56d76a5..b36e86d 100644 --- a/gen/source.js +++ b/gen/source.js @@ -13054,6 +13054,164 @@ var $author$project$Logic$App$Patterns$Stack$swap = F2( }); return A5($author$project$Logic$App$Patterns$OperatorUtils$action2Inputs, stack, ctx, $author$project$Logic$App$Patterns$OperatorUtils$getAny, $author$project$Logic$App$Patterns$OperatorUtils$getAny, action); }); +var $elm$core$Maybe$map2 = F3( + function (func, ma, mb) { + if (ma.$ === 1) { + return $elm$core$Maybe$Nothing; + } else { + var a = ma.a; + if (mb.$ === 1) { + return $elm$core$Maybe$Nothing; + } else { + var b = mb.a; + return $elm$core$Maybe$Just( + A2(func, a, b)); + } + } + }); +var $author$project$Logic$App$Patterns$Stack$swizzle = F2( + function (stack, ctx) { + var newStack = A3( + $elm$core$Array$slice, + 1, + $elm$core$Array$length(stack), + stack); + var maybeIota = A2($elm$core$Array$get, 0, stack); + if (maybeIota.$ === 1) { + return { + a$: ctx, + fp: A2( + $elm$core$Array$append, + $elm$core$Array$fromList( + _List_fromArray( + [ + $author$project$Logic$App$Types$Garbage(1) + ])), + newStack), + bg: false + }; + } else { + var iota = maybeIota.a; + var _v1 = $author$project$Logic$App$Patterns$OperatorUtils$getInteger(iota); + if (_v1.$ === 1) { + return { + a$: ctx, + fp: A2( + $author$project$Logic$App$Utils$Utils$unshift, + $author$project$Logic$App$Types$Garbage(2), + newStack), + bg: false + }; + } else { + if (!iota.$) { + var number = iota.a; + var permutationSizeRec = F3( + function (accum, accumFact, input) { + permutationSizeRec: + while (true) { + if (_Utils_cmp(input, accumFact) < 0) { + return accum; + } else { + var next = 1 + accum; + var $temp$accum = next, + $temp$accumFact = next * accumFact, + $temp$input = input; + accum = $temp$accum; + accumFact = $temp$accumFact; + input = $temp$input; + continue permutationSizeRec; + } + } + }); + var permutationSize = A2(permutationSizeRec, 1, 1); + var idxToCode = F2( + function (i, permSize) { + if (permSize <= 1) { + return _List_fromArray( + [0]); + } else { + var fact = function (n) { + if (!n) { + return 1; + } else { + var x = n; + return x * fact(x - 1); + } + }; + var multiplier = fact(permSize - 1); + var digit = (i / multiplier) | 0; + return A2( + $elm$core$List$cons, + digit, + A2(idxToCode, i % multiplier, permSize - 1)); + } + }); + var idx = $elm$core$Basics$round(number); + var ps = permutationSize(idx); + var codeToPermutationReverse = F2( + function (c, remaining) { + if (!c.b) { + return $elm$core$Maybe$Just(_List_Nil); + } else { + var h = c.a; + var t = c.b; + var next = A2($elm_community$array_extra$Array$Extra$removeAt, h, remaining); + var elem = A2($elm$core$Array$get, h, remaining); + return A3( + $elm$core$Maybe$map2, + $elm$core$List$cons, + elem, + A2(codeToPermutationReverse, t, next)); + } + }); + var code = A2(idxToCode, idx, ps); + var oldSlice = $elm_community$array_extra$Array$Extra$reverse( + A3( + $elm$core$Array$slice, + 0, + $elm$core$List$length(code), + newStack)); + var maybeNewSlice = A2( + $elm$core$Maybe$map, + $elm$core$List$reverse, + A2(codeToPermutationReverse, code, oldSlice)); + if (maybeNewSlice.$ === 1) { + return { + a$: ctx, + fp: A2( + $author$project$Logic$App$Utils$Utils$unshift, + $author$project$Logic$App$Types$Garbage(1), + stack), + bg: false + }; + } else { + var newSlice = maybeNewSlice.a; + return { + a$: ctx, + fp: A2( + $elm$core$Array$append, + $elm$core$Array$fromList(newSlice), + A3( + $elm$core$Array$slice, + $elm$core$List$length(code), + $elm$core$Array$length(newStack), + newStack)), + bg: true + }; + } + } else { + return { + a$: ctx, + fp: A2( + $author$project$Logic$App$Utils$Utils$unshift, + $author$project$Logic$App$Types$Garbage(12), + stack), + bg: false + }; + } + } + } + }); var $elm$core$Basics$tan = _Basics_tan; var $author$project$Logic$App$Patterns$Math$tangent = F2( function (stack, ctx) { @@ -13862,7 +14020,7 @@ function $author$project$Logic$App$Patterns$PatternRegistry$cyclic$patternRegist {a: $author$project$Logic$App$Patterns$Stack$duplicateN, dY: 'Gemini Gambit', em: 'duplicate_n', bE: _List_Nil, _: $elm$core$Maybe$Nothing, fn: 'aadaadaa', dr: 2}, {a: $author$project$Logic$App$Patterns$Stack$fisherman, dY: 'Fisherman\'s Gambit', em: 'fisherman', bE: _List_Nil, _: $elm$core$Maybe$Nothing, fn: 'ddad', dr: 2}, {a: $author$project$Logic$App$Patterns$Stack$fishermanCopy, dY: 'Fisherman\'s Gambit II', em: 'fisherman/copy', bE: _List_Nil, _: $elm$core$Maybe$Nothing, fn: 'aada', dr: 2}, - {a: $author$project$Logic$App$Patterns$PatternRegistry$noAction, dY: '', em: 'swizzle', bE: _List_Nil, _: $elm$core$Maybe$Nothing, fn: 'qaawdde', dr: 2}, + {a: $author$project$Logic$App$Patterns$Stack$swizzle, dY: 'Swindler\'s Gambit', em: 'swizzle', bE: _List_Nil, _: $elm$core$Maybe$Nothing, fn: 'qaawdde', dr: 2}, {a: $author$project$Logic$App$Patterns$Math$add, dY: 'Additive Distillation', em: 'add', bE: _List_Nil, _: $elm$core$Maybe$Nothing, fn: 'waaw', dr: 2}, {a: $author$project$Logic$App$Patterns$Math$subtract, dY: 'Subtractive Distillation', em: 'sub', bE: _List_Nil, _: $elm$core$Maybe$Nothing, fn: 'wddw', dr: 2}, {a: $author$project$Logic$App$Patterns$Math$mulDot, dY: 'Multiplicative Distillation', em: 'mul_dot', bE: _List_Nil, _: $elm$core$Maybe$Nothing, fn: 'waqaw', dr: 2}, diff --git a/src/Logic/App/Patterns/PatternRegistry.elm b/src/Logic/App/Patterns/PatternRegistry.elm index bafcb45..42f3ea0 100644 --- a/src/Logic/App/Patterns/PatternRegistry.elm +++ b/src/Logic/App/Patterns/PatternRegistry.elm @@ -423,7 +423,7 @@ patternRegistry = , { signature = "aadaadaa", internalName = "duplicate_n", action = duplicateN, displayName = "Gemini Gambit", outputOptions = [], selectedOutput = Nothing, startDirection = East } , { signature = "ddad", internalName = "fisherman", action = fisherman, displayName = "Fisherman's Gambit", outputOptions = [], selectedOutput = Nothing, startDirection = East } , { signature = "aada", internalName = "fisherman/copy", action = fishermanCopy, displayName = "Fisherman's Gambit II", outputOptions = [], selectedOutput = Nothing, startDirection = East } - , { signature = "qaawdde", internalName = "swizzle", action = noAction, displayName = "", outputOptions = [], selectedOutput = Nothing, startDirection = East } -- do this + , { signature = "qaawdde", internalName = "swizzle", action = swizzle, displayName = "Swindler's Gambit", outputOptions = [], selectedOutput = Nothing, startDirection = East } -- do this , { signature = "waaw", internalName = "add", action = add, displayName = "Additive Distillation", outputOptions = [], selectedOutput = Nothing, startDirection = East } , { signature = "wddw", internalName = "sub", action = subtract, displayName = "Subtractive Distillation", outputOptions = [], selectedOutput = Nothing, startDirection = East } , { signature = "waqaw", internalName = "mul_dot", action = mulDot, displayName = "Multiplicative Distillation", outputOptions = [], selectedOutput = Nothing, startDirection = East } diff --git a/src/Logic/App/Patterns/Stack.elm b/src/Logic/App/Patterns/Stack.elm index 7e14da7..ab85eca 100644 --- a/src/Logic/App/Patterns/Stack.elm +++ b/src/Logic/App/Patterns/Stack.elm @@ -1,11 +1,13 @@ module Logic.App.Patterns.Stack exposing (..) import Array exposing (Array) +import Array.Extra as Array import FontAwesome.Attributes exposing (stack) import Html.Attributes exposing (action) import Logic.App.Patterns.OperatorUtils exposing (action1Input, action2Inputs, action3Inputs, actionNoInput, getAny, getInteger) import Logic.App.Types exposing (ActionResult, CastingContext, Iota(..), Mishap(..)) import Logic.App.Utils.Utils exposing (removeFromArray, unshift) +import Maybe.Extra as Maybe swap : Array Iota -> CastingContext -> ActionResult @@ -206,3 +208,75 @@ fishermanCopy stack ctx = _ -> { stack = unshift (Garbage CatastrophicFailure) stack, ctx = ctx, success = False } + +swizzle : Array Iota -> CastingContext -> ActionResult +swizzle stack ctx = + let + maybeIota = + Array.get 0 stack + + newStack = + Array.slice 1 (Array.length stack) stack + in + case maybeIota of + Nothing -> + { stack = Array.append (Array.fromList [ Garbage NotEnoughIotas ]) newStack, ctx = ctx, success = False } + + Just iota -> + case getInteger <| iota of + Nothing -> + { stack = unshift (Garbage IncorrectIota) newStack, ctx = ctx, success = False } + + _ -> + case iota of + Number number -> + -- HexCasting does something weird here I don't know how to replicate + -- [0, 1, 1.5, Swindle] will error on the 0 with an error message about 1.5 + -- Very odd. + let + permutationSizeRec accum accumFact input = + if input < accumFact then accum + else let next = 1 + accum in permutationSizeRec next (next * accumFact) input + + permutationSize = permutationSizeRec 1 1 + + idx = round number + ps = permutationSize idx + + idxToCode : Int -> Int -> List Int + idxToCode i permSize = + if permSize <= 1 then [0] + else + let + fact n = + case n of + 0 -> 1 + x -> x * fact (x - 1) + + multiplier = fact (permSize - 1) + digit = i // multiplier + in digit :: (idxToCode (remainderBy multiplier i) (permSize - 1)) + + code = idxToCode idx ps + oldSlice = Array.reverse (Array.slice 0 (List.length code) newStack) + + codeToPermutationReverse c remaining = + case c of + [] -> Just [] + h :: t -> + let + elem = Array.get h remaining + next = Array.removeAt h remaining + in Maybe.map2 (::) elem (codeToPermutationReverse t next) + + maybeNewSlice = Maybe.map List.reverse (codeToPermutationReverse code oldSlice) + in case maybeNewSlice of + Nothing -> + -- needs to be more garbage iotas here to represent reality + { stack = unshift (Garbage NotEnoughIotas) stack, ctx = ctx, success = False } + + Just newSlice -> + { stack = Array.append (Array.fromList newSlice) (Array.slice (List.length code) (Array.length newStack) newStack), ctx = ctx, success = True } + + _ -> + { stack = unshift (Garbage CatastrophicFailure) stack, ctx = ctx, success = False } From 374a5011dd3dab529920ac9ec45a20b9f3abc036 Mon Sep 17 00:00:00 2001 From: Master-Bw3 Date: Sat, 9 Sep 2023 10:38:06 -0500 Subject: [PATCH 2/2] update readme --- README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b96357f..c8453bf 100644 --- a/README.md +++ b/README.md @@ -4,11 +4,10 @@ https://master-bw3.github.io/Hex-Studio/ ## Features - Save/load projects - Export pattern list to give command -- Emulates actions[\*] as you add patterns - Simulated stack/Ravenmind (With input fields to handle unknowns) - Step through your hex through the timeline bar - Partial support for offhand/entities -[\*] Hex addons are not supported yet ## Attribution -Number Literal Generation uses https://github.com/object-Object/hexnumgen-rs +- Number Literal Generation uses https://github.com/object-Object/hexnumgen-rs +- Swindler's Gambit implemented by Aly