Created
December 27, 2013 13:48
-
-
Save GideonPARANOID/8147098 to your computer and use it in GitHub Desktop.
Generates a snakes & ladders board in the form of a folder structure, using symbolic links for snakes & ladders. Snakes & ladders are taken from a file in the format: <start> <end>\n
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
#!/bin/bash | |
# @author gideon mw jones | |
# @created 2013-12-27 | |
# @version 1 | |
# creates a directory structure board for snakes & ladders | |
BRDSZ=100 | |
# initialising board & links | |
if [ $1 ] && [ -d $1 ]; then | |
rm $1/* -r | |
for ((i=0; i<=$BRDSZ; i++)); do | |
mkdir $1/$i | |
touch $1/$i/square-$i | |
((mx = $BRDSZ-$i>6 ? 6 : $BRDSZ-$i)) | |
for ((j=1; j<=$mx; j++)); do | |
ln -s ../$(($i+$j)) $1/$i/$j | |
done | |
done | |
# reading snakes & ladders file | |
# format: <start> <end>\n | |
if [ $2 ] && [ -f $2 ]; then | |
while read l; do | |
arr=(${l// / }); | |
rm $1/${arr[0]} -r | |
ln -s ${arr[1]} $1/${arr[0]} | |
done < $2 | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment