Merge pull request #403 from xexyl/1991-westley

This commit is contained in:
Landon Curt Noll authored and GitHub committed 2023-04-11 11:00:30 -07:00
commit 3a6de965c5
4 files changed
+87 -21

No files matched your search

+74 -2
View File
@@ -13,6 +13,14 @@ USA
make all make all
``` ```
[Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) fixed a segfault in
this program which prevented it from working. The problem was the read-only
char array `char *z[]` was being written to. The fix was to change it to `char
z[][100]` in two spots (see if you can determine why two places, not one!). Why
100 when the longest string is < 100? Because a shorter value caused strange
output and it's easier to just choose a larger value that works without having
to find the correct value. Thank you Cody for your assistance!
## To run: ## To run:
Make and run as follows: Make and run as follows:
@@ -37,13 +45,13 @@ make nextmove
./nextmove move_location | tee nextmove.c ./nextmove move_location | tee nextmove.c
``` ```
## Judges' remarks: ## Try:
We have provided the shell script, [ttt](ttt.sh), to make it easier to play the game: We have provided the shell script, [ttt](ttt.sh), to make it easier to play the game:
```sh ```sh
make ttt make ttt
./ttt [first_move] <- omit first arg to have it move first ./ttt [first_move] # <- omit first arg to have it move first
./ttt next_move ./ttt next_move
``` ```
@@ -57,6 +65,70 @@ has two other modes:
./ttt clobber # remove all game files, revert to original source ./ttt clobber # remove all game files, revert to original source
``` ```
For example here is a potentially losing game:
```sh
./ttt 1
./ttt 4
./ttt 6
```
The final might look like:
```c
a(X){/*/X=- a(X){/*/X=-
X -1;F;X=- -1;F;X=-
-1;F;}/*/ -1;F;}/*/
char z[][100]={"char z[][100]={","a(X){/*/X=-","-1;F;X=-","-1;F;}/*/","1999999999 :-) ",
"int q,i,j,k,X,O=0,H;S(x)int*x;{X+=X;O+=O;*x+1?*x+2||X++:O++;*x=1;}L(n){for(*",
"z[i=1]=n+97;i<4;i++)M(256),s(i),M(128),s(i),M(64),N;X*=8;O*=8;}s(R){char*r=z",
"[R];for(q&&Q;*r;)P(*r++);q&&(Q,P(44));}M(m){P(9);i-2||P(X&m?88:O&m?48:32);P(",
"9);}y(A){for(j=8;j;)~A&w[--j]||(q=0);}e(W,Z){for(i-=i*q;i<9&&q;)y(W|(1<<i++&",
"~Z));}R(){for(k=J[*J-48]-40;k;)e(w[k--],X|O);}main(u,v)char**v;{a(q=1);b(1);",
"c(1);*J=--u?O?*J:*v[1]:53;X|=u<<57-*v[u];y(X);K=40+q;q?e(O,X),q&&(K='|'),e(X",
",O),R(),O|=1<<--i:J[*J-48+(X=O=0)]--;L(q=0);for(s(i=0);q=i<12;)s(i++),i>4&&N",
";s(q=12);P(48);P('}');P(59);N;q=0;L(1);for(i=5;i<13;)s(i++),N;L(2);}",0};
b(X){/*/X=- b(X){/*/X=-
X -1;F;X=- -1;F;X=- X
-1;F;}/*/ -1;F;}/*/
int q,i,j,k,X,O=0,H;S(x)int*x;{X+=X;O+=O;*x+1?*x+2||X++:O++;*x=1;}L(n){for(*
z[i=1]=n+97;i<4;i++)M(256),s(i),M(128),s(i),M(64),N;X*=8;O*=8;}s(R){char*r=z
[R];for(q&&Q;*r;)P(*r++);q&&(Q,P(44));}M(m){P(9);i-2||P(X&m?88:O&m?48:32);P(
9);}y(A){for(j=8;j;)~A&w[--j]||(q=0);}e(W,Z){for(i-=i*q;i<9&&q;)y(W|(1<<i++&
~Z));}R(){for(k=J[*J-48]-40;k;)e(w[k--],X|O);}main(u,v)char**v;{a(q=1);b(1);
c(1);*J=--u?O?*J:*v[1]:53;X|=u<<57-*v[u];y(X);K=40+q;q?e(O,X),q&&(K='|'),e(X
,O),R(),O|=1<<--i:J[*J-48+(X=O=0)]--;L(q=0);for(s(i=0);q=i<12;)s(i++),i>4&&N
;s(q=12);P(48);P('}');P(59);N;q=0;L(1);for(i=5;i<13;)s(i++),N;L(2);}
c(X){/*/X=- c(X){/*/X=-
0 -1;F;X=- 0 -1;F;X=- 0
-1;F;}/*/ -1;F;}/*/
ttt: I win!
```
## Judges' remarks:
Can you figure out why the board looks different than the
[westley.c](westley.c)?
What happens if you make a move already made?
Now go try and draw or better yet win!
Why is win better than draw? Because everyone knows how to draw:
> Professor Falken: Did you ever play tic-tac-toe?
> Jennifer Mack: Yeah. Of course.
> Falken: But you don't any more.
> Jennifer: No.
> Falken: Why?
> Jennifer: Because it's a boring game. It's always a tie.
> Falken: Exactly. There's no way to win. The game itself is pointless. But back
at the [International Obfuscated C Code Contest judges'
room](https://www.ioccc.org/https://www.ioccc.org/judges.html) they believe that
you can win tic-tac-toe, that there can be acceptable draws.
Try not to cheat, the computer has not learned how to catch you doing it. Try not to cheat, the computer has not learned how to catch you doing it.
## Author's remarks: ## Author's remarks:
+12 -12
View File
@@ -5,9 +5,9 @@
# parse args # parse args
# #
if [ $# -gt 1 ]; then if [ $# -gt 1 ]; then
echo "usage: ttt [move_digit]" 1>&2 echo "usage: ./ttt [move_digit]" 1>&2
echo " ttt quitgame" 1>&2 echo " ./ttt quitgame" 1>&2
echo " ttt clobber" 1>&2 echo " ./ttt clobber" 1>&2
exit 1 exit 1
elif [ $# -eq 1 ]; then elif [ $# -eq 1 ]; then
move="$1" move="$1"
@@ -41,9 +41,9 @@ if [ $# -eq 1 ]; then
case "$move" in case "$move" in
1|2|3|4|5|6|7|8|9) ;; 1|2|3|4|5|6|7|8|9) ;;
*) echo "ttt: bad argument" 1>&2 *) echo "ttt: bad argument" 1>&2
echo "usage: ttt [move_digit]" 1>&2 echo "usage: ./ttt [move_digit]" 1>&2
echo " ttt quitgame" 1>&2 echo " ./ttt quitgame" 1>&2
echo " ttt clobber" 1>&2 echo " ./ttt clobber" 1>&2
exit 2 ;; exit 2 ;;
esac esac
fi fi
@@ -74,7 +74,7 @@ if [ ! -f merlyn ]; then
status=$? status=$?
if [ "$status" -ne 0 ]; then if [ "$status" -ne 0 ]; then
echo "ttt: something is wrong, fix merlyn.c and build it yourself!" 1>&2 echo "ttt: something is wrong, fix merlyn.c and build it yourself!" 1>&2
echo " or maybe type: ttt clobber" 1>&2 echo " or maybe type: ./ttt clobber" 1>&2
exit 5 exit 5
fi fi
rm -f ttt_game.c rm -f ttt_game.c
@@ -100,13 +100,13 @@ else
status=$? status=$?
if [ "$status" -ne 0 ]; then if [ "$status" -ne 0 ]; then
echo "ttt: something is wrong, fix ttt_game.c and build it yourself!" 1>&2 echo "ttt: something is wrong, fix ttt_game.c and build it yourself!" 1>&2
echo " or maybe type: ttt quitgame" 1>&2 echo " or maybe type: ./ttt quitgame" 1>&2
exit 6 exit 6
fi fi
if [ -z "$move" ]; then if [ -z "$move" ]; then
ttt_game | tee ttt_new.c ./ttt_game | tee ttt_new.c
else else
ttt_game "$move" | tee ttt_new.c ./ttt_game "$move" | tee ttt_new.c
fi fi
chmod +w ttt_new.c chmod +w ttt_new.c
if [ -s ttt_new.c ]; then if [ -s ttt_new.c ]; then
@@ -143,8 +143,8 @@ else
else else
echo "ttt: something is wrong, maybe ttt_old.c will help" 1>&2 echo "ttt: something is wrong, maybe ttt_old.c will help" 1>&2
echo " or maybe type: ttt quitgame" 1>&2 echo " or maybe type: ./ttt quitgame" 1>&2
echo " or maybe type: ttt clobber" 1>&2 echo " or maybe type: ./ttt clobber" 1>&2
exit 7 exit 7
fi fi
fi fi
+1 -1
View File
@@ -1,7 +1,7 @@
a(X){/*/X=- a(X){/*/X=- a(X){/*/X=- a(X){/*/X=-
-1;F;X=- -1;F;X=- -1;F;X=- -1;F;X=-
-1;F;}/*/ -1;F;}/*/ -1;F;}/*/ -1;F;}/*/
char*z[]={"char*z[]={","a(X){/*/X=-","-1;F;X=-","-1;F;}/*/","9999999999 :-| ", char z[][100]={"char z[][100]={","a(X){/*/X=-","-1;F;X=-","-1;F;}/*/","9999999999 :-| ",
"int q,i,j,k,X,O=0,H;S(x)int*x;{X+=X;O+=O;*x+1?*x+2||X++:O++;*x=1;}L(n){for(*", "int q,i,j,k,X,O=0,H;S(x)int*x;{X+=X;O+=O;*x+1?*x+2||X++:O++;*x=1;}L(n){for(*",
"z[i=1]=n+97;i<4;i++)M(256),s(i),M(128),s(i),M(64),N;X*=8;O*=8;}s(R){char*r=z", "z[i=1]=n+97;i<4;i++)M(256),s(i),M(128),s(i),M(64),N;X*=8;O*=8;}s(R){char*r=z",
"[R];for(q&&Q;*r;)P(*r++);q&&(Q,P(44));}M(m){P(9);i-2||P(X&m?88:O&m?48:32);P(", "[R];for(q&&Q;*r;)P(*r++);q&&(Q,P(44));}M(m){P(9);i-2||P(X&m?88:O&m?48:32);P(",
-6
View File
@@ -542,12 +542,6 @@ will be fixed in time but it's noted here for now.
# 1991 # 1991
## [1991/westley](1991/westley/westley.c) ([README.md](1991/westley/README.md))
## STATUS: compiled executable crashes - please help us fix
This program crashes. This will be worked on in the near future.
# 1992 # 1992
## [1992/buzzard.1](1992/buzzard.1/buzzard.1.c) ([README.md](1992/buzzard.1/README.md)) ## [1992/buzzard.1](1992/buzzard.1/buzzard.1.c) ([README.md](1992/buzzard.1/README.md))