forked from haskell-game/tiny-games-hs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
play
executable file
·96 lines (88 loc) · 2.93 KB
/
play
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env bash
# A front end to run games easily.
# All games in category then submission order, as in README.
# (leave 0th element empty)
games=(
""
prelude/guess1/guess1.hs
prelude/pure-doors/pure-doors.hs
prelude/fifteen/fifteen.hs
prelude/chess/chess.hs
prelude/sudoku/sudoku.hs
prelude/matchmaking/matchmaking.hs
base/timing/timing.hs
base/shoot/shoot.hs
base/log2048/log2048.hs
base/rhythm/rhythm.hs
base/peyton-says/peyton-says.hs
default/type-and-furious/type-and-furious.hs
hackage/guess2/guess2.hs
hackage/wordle/wordle.hs
hackage/ski/ski.hs
hackage/guesscolor/guesscolor.hs
hackage/bulls-n-cows/bulls-n-cows.hs
hackage/hallway-to-hell/hallway-to-hell.hs
hackage/1234-hero/1234-hero.hs
hackage/crappy-flappy/crappy-flappy.hs
hackage/pong/pong.hs
hackage/minesweeper/minesweeper.hs
hackage/pong2/pong2.hs
hackage/brickbreaker/brickbreaker.hs
)
# Games needing special invocation, in alphabetical order.
fifteen() { runghc -XPatternSynonyms -XLambdaCase "$1"; }
brickbreaker() { stack script --compile --resolver lts-20 --package gloss "$1"; }
hallway-to-hell() { stack runghc --resolver lts-20 --package random --package rio "$1"; }
log2048() { runghc "$1"; }
matchmaking() { runghc -cpp -DD='a=replicate;b=putStrLn;c=length;p=map;u=max(2)' "$1"; }
pong2() { stack runghc --resolver lts-20 --package ansi-terminal-game "$1"; }
sudoku() { runghc "$1"; }
type-and-furious() { cd default/type-and-furious || return; ./type-and-furious.hs; }
# Help
gamecat() { echo "$1" | cut -d/ -f1; }
gamename() { basename "$1" .hs; }
help() {
cat <<HERE
--------------------------------------------------------
___ __
|__| _ _| _|| | . _ / _ _ _ _ | _ _ /|
| |(_|_)|((-|| | || )\/ \__)(_||||(- __)(_|||| |
--------------------------------------------------------
Here are the entries from HTGJ1, Feb 2023 !
This script can run each game for you, using ghc or stack.
If you don't have these yet, see https://www.haskell.org/get-started .
Usage: play [NUM|NAME|SUBSTR]
HERE
for k in "${!games[@]}"; do
[[ $k == 0 ]] && continue
g="${games[$k]}"
printf "%2d) %-20s %s\n" "$k" "$(gamename "$g")" "[$(gamecat "$g")]"
done
echo
}
declare -A gamesbyname
for g in "${games[@]}"; do
[[ -z $g ]] && continue
gamesbyname["$(gamename "$g")"]=$g
done
# Main
cd "$(dirname "${BASH_SOURCE[0]}")" || exit 1
if [[ $# == 0 || "$1" == "-h" || "$1" == "--help" || "$2" == "-h" || "$2" == "--help" ]];
then help
else
# select a game
g=${games[$1]}
if [[ -z $g ]]; then g=${gamesbyname[$1]}; fi
if [[ -z $g ]]; then
for h in "${games[@]}"; do
if [[ $(gamename "$h") =~ $1 ]]; then g="$h"; break; fi
done
fi
if [[ -z $g ]]; then echo "$1 is unrecognised, run '$0' to see the list"; exit 1; fi
# run it
gname=$(gamename "$g")
if declare -f "$gname" >/dev/null
then "$gname" "$g"
else $g
fi
fi