(set 'a (exec "python3 go.py"))
(set 'b (a 0))
(replace "\'" b "\"")
"{\"symbol\": \"BURT/USDT\", \"timestamp\": None, \"datetime\": None, \"high\": 0.002463, \"low\": 0.001605, \"bid\": None, \"bidVolume\": 1731397.09898224, \"ask\": None, \"askVolume\": 2732456.21823022, \"vwap\": None, \"open\": 0.002136, \"close\": 0.002051, \"last\": 0.002051, \"previousClose\": None, \"change\": -8.5e-05, \"percentage\": -3.9794007490636703, \"average\": 0.002093, \"baseVolume\": 10255192.67905658, \"quoteVolume\": None, \"markPrice\": None, \"indexPrice\": None, \"info\": {\"close\": \"0.002051\", \"high\": \"0.002463\", \"last\": \"0.002051\", \"low\": \"0.001605\", \"market\": \"BURTUSDT\", \"open\": \"0.002136\", \"period\": \"86400\", \"value\": \"21214.1562025586145\", \"volume\": \"10255192.67905658\", \"volume_buy\": \"1731397.09898224\", \"volume_sell\": \"2732456.21823022\"}}"
(setf ACTIONS '(
(87 up) (119 up)
(65 left) (97 left)
(85 down) (115 down)
(68 right) (100 right)
(48 exit) ; "0" --> quit the game
))
(if (lookup (setf key (read-key)) ACTIONS) (apply $it)
(println "Wrong key.") (setq key-error true))
("{'symbol': 'BURT/USDT', 'timestamp': 1731440509530, 'datetime': '2024-11-12T19:41:49.530Z', 'high': 0.00353408, 'low': 0.00208606, 'bid': None, 'bidVolume': None, 'ask': None, 'askVolume': None, 'vwap': None, 'open': 0.00303488, 'close': 0.00246695, 'last': 0.00246695, 'previousClose': None, 'change': -0.00056793, 'percentage': -18.71, 'average': 0.00275091, 'baseVolume': None, 'quoteVolume': 281487.40662491, 'info': {'s': 'burt_usdt', 't': '1731440509530', 'cv': '-0.00056793', 'cr': '-0.1871', 'o': '0.00303488', 'l': '0.00208606', 'h': '0.00353408', 'c': '0.00246695', 'q': '97965253', 'v': '281487.40662491'}, 'indexPrice': None, 'markPrice': None}")
{"symbol": "BURT/USDT", "timestamp": 1731440509530, "datetime": "2024-11-12T19:41:49.530Z", "high": 0.00353408, "low": 0.00208606, "bid": null, "bidVolume": null, "ask": null, "askVolume": null, "vwap": null, "open": 0.00303488, "close": 0.00246695, "last": 0.00246695, "previousClose": null, "change": -0.00056793, "percentage": -18.71, "average": 0.00275091, "baseVolume": null, "quoteVolume": 281487.40662491, "info": {"s": "burt_usdt", "t": "1731440509530", "cv": "-0.00056793", "cr": "-0.1871", "o": "0.00303488", "l": "0.00208606", "h": "0.00353408", "c": "0.00246695", "q": "97965253", "v": "281487.40662491"}, "indexPrice": null, "markPrice": null}
(set 'a '("{'symbol': 'BURT/USDT', 'timestamp': 1731439797068, 'datetime': '2024-11-12T19:29:57.068Z', 'high': 0.00353408, 'low': 0.00208606, 'bid': None, 'bidVolume': None, 'ask': None, 'askVolume': None, 'vwap': None, 'open': 0.00294771, 'close': 0.00248834, 'last': 0.00248834, 'previousClose': None, 'change': -0.00045937, 'percentage': -15.58, 'average': 0.00271802, 'baseVolume': None, 'quoteVolume': 281817.75855221, 'info': {'s': 'burt_usdt', 't': '1731439797068', 'cv': '-0.00045937', 'cr': '-0.1558', 'o': '0.00294771', 'l': '0.00208606', 'h': '0.00353408', 'c': '0.00248834', 'q': '97998750', 'v': '281817.75855221'}, 'indexPrice': None, 'markPrice': None}"))
(replace "\'" a "\"") ; gave the below with no changes
("{'symbol': 'BURT/USDT', 'timestamp': 1731439797068, 'datetime': '2024-11-12T19:29:57.068Z', 'high': 0.00353408, 'low': 0.00208606, 'bid': None, 'bidVolume': None, 'ask': None, 'askVolume': None, 'vwap': None, 'open': 0.00294771, 'close': 0.00248834, 'last': 0.00248834, 'previousClose': None, 'change': -0.00045937, 'percentage': -15.58, 'average': 0.00271802, 'baseVolume': None, 'quoteVolume': 281817.75855221, 'info': {'s': 'burt_usdt', 't': '1731439797068', 'cv': '-0.00045937', 'cr': '-0.1558', 'o': '0.00294771', 'l': '0.00208606', 'h': '0.00353408', 'c': '0.00248834', 'q': '97998750', 'v': '281817.75855221'}, 'indexPrice': None, 'markPrice': None}")
(set 'timestamp (date-value (now)))
(set 'timestamp (push "000" (string timestamp) -1)) ; convert timestamp to milliseconds
(set 'user "xxx")
(set 'urlbase "https://api.coinex.com/v2")
(set 'urlendpoint "/assets/spot/balance")
(set 'urlbody (string "GET" urlendpoint timestamp))
(set 'urlbodyhash (crypto:sha256 urlbody))
(set 'url (string urlbase urlendpoint))
(set 'call (string "curl -X 'GET' " url " -H 'Content-type: application/json' -H 'X-COINEX-KEY: " user "' -H 'X-COINEX-SIGN: " urlbodyhash "' -H 'X-COINEX-TIMESTAMP: " timestamp "'"))
("{\"code\":25,\"data\":{},\"message\":\"Signature Incorrect\"}")
prepared_str = "GET"+"/v2/spot/balance"+"1700490703564"
;---------------------------------
; Minimalistic 2048 (4x4)
; Use "W" "A" "S" "D" key to move
; (load "g2048.lsp")
;---------------------------------
(define (print-grid)
(for (i 0 3)
(for (j 0 3)
(print (format "%4d " (grid i j))))
(println)) '>)
;
(define (find-zeros)
(let (pts '())
(for (i 0 3)
(for (j 0 3)
(if (zero? (grid i j)) (push (list i j) pts -1)))) pts))
;
(define (new-game)
(setq grid (array-list (array 4 4 '(0))))
(setq zeros (randomize (find-zeros)))
(setf (grid (zeros 0)) 2)
(setf (grid (zeros 1)) 2)
(input))
;
(define (input)
(print-grid)
(case (setq key (read-key))
(87 (up)) (119 (up))
(65 (left)) (97 (left))
(85 (down)) (115 (down))
(68 (right)) (100 (right))
(48 (exit)) ; "0" --> quit the game
(true (begin (println "Wrong key.") (setq key-error true)))
)
(cond ((ref 2048 grid) (println "Bravo! You win.") (print-grid))
((= key-error true) (setq key-error nil) (input))
(true
(setq zeros (randomize (find-zeros)))
(when zeros ; put 2 or 4 in a free cell
(if (zero? (rand 2))
(setf (grid (zeros 0)) 2)
(setf (grid (zeros 0)) 4)))
(input))))
;
(define (shift-right row)
(let ((non-zero (filter (fn (x) (!= x 0)) row))
(zeroes (filter (fn (x) (= x 0)) row)))
(extend zeroes non-zero)))
;
(define (shift-left row)
(let ((non-zero (filter (fn (x) (!= x 0)) row))
(zeroes (filter (fn (x) (= x 0)) row)))
(extend non-zero zeroes)))
;
(define (matrix-left matrix) (map shift-left matrix))
;
(define (matrix-right matrix) (map shift-right matrix))
;
(define (matrix-down matrix)
(let (trans (transpose matrix))
(transpose (map shift-right trans))))
;
(define (matrix-up matrix)
(let (trans (transpose matrix))
(transpose (map shift-left trans))))
;
(define (merge-numbers row)
(let ( (result '()) (idx 0) (len (length row)) )
(while (< idx len)
(if (and (< idx (- len 1)) (= (row idx) (row (+ idx 1))))
(begin
(push (* 2 (row idx)) result -1)
(++ idx 2))
(begin
(push (row idx) result -1)
(++ idx 1))))
(extend result (dup 0 (- len (length result))))))
;
(define (matrix-merge matrix) (map merge-numbers matrix))
;
(define (right)
(println "right")
(setq grid (matrix-right grid)) ; move the numbers to right
(setq grid (matrix-merge grid)) ; merge the numbers
(setq grid (matrix-right grid))) ; move the numbers to right
;
(define (left)
(println "left")
(setq grid (matrix-left grid))
(setq grid (matrix-merge grid))
(setq grid (matrix-left grid)))
;
(define (up)
(println "up")
(setq grid (matrix-up grid))
(setq grid (transpose (matrix-merge (transpose grid))))
(setq grid (matrix-up grid)))
;
(define (down)
(println "down")
(setq grid (matrix-down grid))
(setq grid (transpose (matrix-merge (transpose grid))))
(setq grid (matrix-down grid)))
;
(new-game)