diff options
Diffstat (limited to 'examples/chess')
-rwxr-xr-x | examples/chess/board.sh | 40 | ||||
-rw-r--r-- | examples/chess/camera.pos | 2 | ||||
-rwxr-xr-x | examples/chess/gnuchess-to-hackvr.sh | 31 | ||||
-rwxr-xr-x | examples/chess/hackvr-to-gnuchess.sh | 18 | ||||
-rw-r--r-- | examples/chess/pieces/bishop | 2 | ||||
-rw-r--r-- | examples/chess/pieces/king | 2 | ||||
-rw-r--r-- | examples/chess/pieces/knight | 2 | ||||
-rw-r--r-- | examples/chess/pieces/pawn | 1 | ||||
-rw-r--r-- | examples/chess/pieces/queen | 1 | ||||
-rw-r--r-- | examples/chess/pieces/rook | 1 | ||||
-rwxr-xr-x | examples/chess/run | 4 |
11 files changed, 104 insertions, 0 deletions
diff --git a/examples/chess/board.sh b/examples/chess/board.sh new file mode 100755 index 0000000..f574065 --- /dev/null +++ b/examples/chess/board.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +width=8 +height=8 +cols="a b c d e f g h" + +for x in $(seq 1 $width);do + for y in $(seq 1 $height);do + color=$[((($y % 2) + ($x % 2))%2)+16] +### board is on the wall. draw in x and y. +# printf "%s%s addshape %s 4 %s %s 0 %s %s 0 %s %s 0 %s %s 0\n" $(printf "%s\n" "$cols" | cut '-d ' -f$x) $y $color $x $y $[x+1] $y $[x+1] $[y+1] $x $[y+1] +### board is on floor. draw in x and z. + printf "%s%s addshape %s 4 %s 0 %s %s 0 %s %s 0 %s %s 0 %s\n" $(printf "%s\n" "$cols" | cut '-d ' -f$x) $y $color $x $y $[x+1] $y $[x+1] $[y+1] $x $[y+1] + done +done + +row8="rook knight bishop queen king bishop knight rook" +row1="$row8" + +color="19 19 0 0 0 0 20 20" + +#draw pawns. triangles. +for x in $(seq $width);do + for y in 2 7;do + locat="$(printf "%s\n" "$cols" | cut '-d ' "-f$x")$y" + cat "./pieces/pawn" | sed 's/^[^ ][^ ]* addshape [0-9][0-9]* /piece_'"${locat}"' addshape '"$(printf "%s\n" "$color" | cut '-d ' "-f$y")"' /g' +### board is on wall. use x and y. +# printf "piece_%s move %s %s 0\n" "$locat" "$x" "$y" +### board is on floor. use x and z. + printf "piece_%s move %s 0 %s\n" "$locat" "$x" "$y" + done + for y in 1 8;do + locat="$(printf "%s\n" "$cols" | cut '-d ' "-f$x")$y" + cat "./pieces/$(printf "%s\n" "$row1" | cut '-d ' "-f$x")" | sed 's/^[^ ][^ ]* addshape [0-9][0-9]* /piece_'"${locat}"' addshape '"$(printf "%s\n" "$color" | cut '-d ' "-f$y")"' /g' +### board is on wall. use x and y. +# printf "piece_%s move %s %s 0\n" "$locat" "$x" "$y" +### board is on floor. use x and z. + printf "piece_%s move %s 0 %s\n" "$locat" "$x" "$y" + done +done diff --git a/examples/chess/camera.pos b/examples/chess/camera.pos new file mode 100644 index 0000000..32433c2 --- /dev/null +++ b/examples/chess/camera.pos @@ -0,0 +1,2 @@ +epoch move 5 5 -6 +derp set global.zoom 60 diff --git a/examples/chess/gnuchess-to-hackvr.sh b/examples/chess/gnuchess-to-hackvr.sh new file mode 100755 index 0000000..0b94a87 --- /dev/null +++ b/examples/chess/gnuchess-to-hackvr.sh @@ -0,0 +1,31 @@ +#!/bin/sh +tee /dev/stderr | while read first second third;do + if [ "_$first" = "_feature" ];then + printf "# just gnuchess saying what features it has: %s %s %s\n" "$first" "$second" "$third" >&2 + elif printf "%s\n" "$first" | grep '^[0-9][0-9]*\.$' >/dev/null 2>&1;then + #we made a successful move. + ### how to tell hackvr to move the piece now? $second should contain what the move was. + printf "# Hey! Hackvr! do this move: %s\n" "$second" >&2 + if [ "_$second" = "_..." ];then #computer/other person made a move. + move=$third + else + move=$second + fi + from=$(printf "%s\n" "$move" | fold -w1 | head -n2 | tr -d '\n') + to=$(printf "%s\n" "$move" | fold -w1 | tail -n+3 | head -n2 | tr -d '\n') + x=$(echo "a b c d e f g h" | tr ' ' '\n' | grep -n "$(printf "%s\n" "$to" | fold -w1 | head -n1)" | cut -d: -f1) + y=$(printf "%s\n" "$to" | fold -w1 | tail -n1) + magic=$(printf "%s\n" "$move" | fold -w1 | tail -n+5 | tr -d '\n') +### if the board is on the wall we need to use x and y +# printf "piece_%s move %s %s 0\n" "$from" "$x" "$y" | tee /dev/stderr +### the board is on the floor atm. use x and z + printf "piece_%s move %s 0 %s\n" "$from" "$x" "$y" | tee /dev/stderr + + printf "#delete the old piece_%s group\n" + printf "epoch deletegroup piece_%s\n" "$to" + printf "epoch renamegroup piece_%s piece_%s\n" "$from" "$to" | tee /dev/stderr + else + #something else. + printf "oops. something else happened. let's see: %s %s %s\n" "$first" "$second" "$third" >&2 + fi +done diff --git a/examples/chess/hackvr-to-gnuchess.sh b/examples/chess/hackvr-to-gnuchess.sh new file mode 100755 index 0000000..94cd1ab --- /dev/null +++ b/examples/chess/hackvr-to-gnuchess.sh @@ -0,0 +1,18 @@ +#!/bin/sh +part1="" +echo "sleeping 3 seconds. might have gnuchess less likely to not do anything." >&2 +sleep 3 +echo "protover 2" +while read derp command target extra;do + if [ "_$command" = "_action" ];then + if printf "%s\n" "$target" | grep -v "^piece_" 2>&1 > /dev/null;then #we are ignoring clicks on pieces in favor of squares atm. when full 3d probably want pieces. + if [ "_$part1" = "_" ];then + part1=$target + else + #we have two parts. let's tell gnuchess! + printf "%s%s\n" $part1 $target + part1="" + fi + fi + fi +done diff --git a/examples/chess/pieces/bishop b/examples/chess/pieces/bishop new file mode 100644 index 0000000..db6f144 --- /dev/null +++ b/examples/chess/pieces/bishop @@ -0,0 +1,2 @@ +rook addshape 4 4 .4 .1 0 .6 .1 0 .6 .9 0 .4 .9 0 +rook addshape 4 4 .3 .6 0 .7 .6 0 .7 .8 0 .3 .8 0 diff --git a/examples/chess/pieces/king b/examples/chess/pieces/king new file mode 100644 index 0000000..8ca79ef --- /dev/null +++ b/examples/chess/pieces/king @@ -0,0 +1,2 @@ +king addshape 4 4 .1 .7 0 .3 .9 0 .9 .3 0 .7 .1 0 +king addshape 4 4 .3 .1 0 .9 .7 0 .7 .9 0 .1 .3 0 diff --git a/examples/chess/pieces/knight b/examples/chess/pieces/knight new file mode 100644 index 0000000..adc7f53 --- /dev/null +++ b/examples/chess/pieces/knight @@ -0,0 +1,2 @@ +knight addshape 4 4 .1 .1 0 .3 .1 0 .3 .9 0 .1 .9 0 +knight addshape 4 4 .1 .1 0 .9 .1 0 .9 .3 0 .1 .3 0 diff --git a/examples/chess/pieces/pawn b/examples/chess/pieces/pawn new file mode 100644 index 0000000..d7d2d29 --- /dev/null +++ b/examples/chess/pieces/pawn @@ -0,0 +1 @@ +pawn addshape 4 3 .2 .1 0 .8 .1 0 .5 .5 0 diff --git a/examples/chess/pieces/queen b/examples/chess/pieces/queen new file mode 100644 index 0000000..3ebb4ab --- /dev/null +++ b/examples/chess/pieces/queen @@ -0,0 +1 @@ +pawn addshape 4 3 .2 .1 0 .8 .1 0 .5 .9 0 diff --git a/examples/chess/pieces/rook b/examples/chess/pieces/rook new file mode 100644 index 0000000..2550eb5 --- /dev/null +++ b/examples/chess/pieces/rook @@ -0,0 +1 @@ +rook addshape 4 4 .4 .1 0 .6 .1 0 .6 .9 0 .4 .9 0 diff --git a/examples/chess/run b/examples/chess/run new file mode 100755 index 0000000..4f0cdce --- /dev/null +++ b/examples/chess/run @@ -0,0 +1,4 @@ +#!/bin/bash +mknod p p +stdbuf -oL cat camera.pos <(./board.sh) <(cat p | ./gnuchess-to-hackvr.sh) | hackvr "$USER" | ./hackvr-to-gnuchess.sh | gnuchess -x > p +rm p |