summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorepoch <epoch@hacking.allowed.org>2017-11-25 21:53:07 -0600
committerepoch <epoch@hacking.allowed.org>2017-11-25 21:53:07 -0600
commite27e8cac3047b54a57fa44ce1dbdc4ea170cd39d (patch)
treef4fdc1aeea402c3f6672054868e94b1549a222d0
parent35ed48987d5511e4df4bd90e0f69303678f5c476 (diff)
downloadhackvr-e27e8cac3047b54a57fa44ce1dbdc4ea170cd39d.tar.gz
hackvr-e27e8cac3047b54a57fa44ce1dbdc4ea170cd39d.zip
moved all tictactoe game logic to game.sh
-rwxr-xr-xtictactoe/game.sh29
1 files changed, 29 insertions, 0 deletions
diff --git a/tictactoe/game.sh b/tictactoe/game.sh
new file mode 100755
index 0000000..29666f0
--- /dev/null
+++ b/tictactoe/game.sh
@@ -0,0 +1,29 @@
+#!/bin/bash
+turn=$( expr $RANDOM % 2)
+echo "go. player: $turn"
+stdbuf -oL uniq \
+ | grep --line-buffered action \
+ | stdbuf -oL cut '-d ' -f1,3 | while read user group;do
+ if grep "_reset" <<<$group >/dev/null;then
+ printf "%s deleteallexcept .\n" "$user"
+ cat board
+ continue
+ elif grep "_" <<<$group >/dev/null;then
+# xmessage "CUT IT OUT"
+ echo CUT IT OUT > /dev/stderr
+ continue
+ else
+ turn=$(expr \( $turn + 1 \) % 2)
+ #printf "# turn: %d\n" "$turn" > /dev/stderr
+ printf "$user deletegroup %s\n" "$group"
+ #printf "$user deletegroup %s\n" "$group" > /dev/stderr
+#need to get the first point of the group clicked and translate the new shape by that much
+ translatex="$(grep "$group" board | grep -v '^#' | tr -s ' ' | cut '-d ' -f4)"
+ translatey="$(grep "$group" board | grep -v '^#' | tr -s ' ' | cut '-d ' -f5)"
+ cat "marker$turn"
+ printf "%s move %s %s 2\n" "_marker" "$(expr "$translatex")" "$(expr "$translatey" - 2 )"
+ #printf "%s move %s %s 2\n" "_marker" "$(expr "$translatex")" "$(expr "$translatey" - 2 )" >/dev/stderr
+ grep "$group" board | sed "s/$group/_marker2/g"
+ printf "%s renamegroup _marker _marker%s%s\n" "$user" "$(date +%s)" "$RANDOM"
+ fi
+ done