Last active
July 23, 2022 03:32
-
-
Save derrickturk/5e5e8bd279535e542f726f9da83f5c10 to your computer and use it in GitHub Desktop.
play a game of "Guess or Die", with aggressive save-scumming
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
effect QuickSave: int option | |
effect QuickLoad: int -> empty | |
let quicksave () = perform QuickSave | |
let quickload n = absurd (perform (QuickLoad n)) | |
let quicksaving = handler | |
| effect QuickSave k -> | |
let rec quickloading () = handler | |
| effect (QuickLoad n) _ -> | |
with quickloading () handle | |
continue k (Some n) | |
in | |
with quickloading () handle | |
continue k None | |
type outcome = | |
| Success | |
| Death | |
let guess_or_die () = | |
let r = perform (RandomInt 10) in | |
fun n -> if n = r then Success else Death;; | |
let game = guess_or_die ();; | |
let play game = | |
let n = match quicksave () with | |
| None -> 0 | |
| Some n -> n | |
in | |
match game n with | |
| Success -> n | |
| Death -> quickload (n + 1) | |
;; | |
with quicksaving handle | |
play game |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment