From ac1334c84d87713b494046b6034e4eb805d9ec28 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Sun, 12 Nov 2023 03:16:10 -0800 Subject: [PATCH] Make 1992/kivinen/kivinen.c alt code Originally the main version was changed to have a call to usleep(3) as the game moves so fast. It was discussed a while back however to in cases like this to make it so that the build/use/try sections refer to the alt code and then instead of an alternate code section have an original code section. Because of this the modified code was changed to be an alt version and then restore the original with the fixed code. As for the fixed code (and also alt code) I have made it look more like the original by changing the 'ext' macro to be 'exit' (with the comma operator). I tried and believe I succeeded (mostly if not totally) in making the lines start and end on the same columns and in at least some lines the same character starts and ends the lines as the original. --- 1992/kivinen/.gitignore | 1 + 1992/kivinen/Makefile | 6 ++--- 1992/kivinen/README.md | 46 +++++++++++++++++++++++++++++++------- 1992/kivinen/kivinen.alt.c | 39 ++++++++++++++++++++++++++++++++ 1992/kivinen/kivinen.c | 8 +++---- thanks-for-fixes.md | 17 +++++++------- 6 files changed, 94 insertions(+), 23 deletions(-) create mode 100644 1992/kivinen/kivinen.alt.c diff --git a/1992/kivinen/.gitignore b/1992/kivinen/.gitignore index afc417ed0..6319554d0 100644 --- a/1992/kivinen/.gitignore +++ b/1992/kivinen/.gitignore @@ -1,3 +1,4 @@ kivinen +kivinen.alt kivinen.orig prog.orig diff --git a/1992/kivinen/Makefile b/1992/kivinen/Makefile index 2c2e017ff..252aac044 100644 --- a/1992/kivinen/Makefile +++ b/1992/kivinen/Makefile @@ -58,7 +58,7 @@ ARCH= # Defines that are needed to compile # -CDEFINE= -DZ=15000 +CDEFINE= -DZ=20000 # Include files that are needed to compile # @@ -113,8 +113,8 @@ OBJ= ${PROG}.o DATA= TARGET= ${PROG} # -ALT_OBJ= -ALT_TARGET= +ALT_OBJ= ${PROG}.alt.o +ALT_TARGET= ${PROG}.alt ################# diff --git a/1992/kivinen/README.md b/1992/kivinen/README.md index a25029e1e..6e86a1a4f 100644 --- a/1992/kivinen/README.md +++ b/1992/kivinen/README.md @@ -3,14 +3,14 @@ If your machine support the X Window System, Version 11: ```sh -make all +make alt ``` -NOTE: this entry requires `X11/Xlib.h` header file and the X11 library to -compile. macOS users running Mountain Lion and later will need to download and -install [XQuartz](https://www.xquartz.org) in order to compile and run this -entry. +We recommend the alt version first as the original goes too fast on modern +systems. See [original code](#original-code) for the original should you wish to +see what we mean. +You can reconfigure the value to `usleep(3)`; see [try](#try) section below. ### Bugs and (Mis)features: @@ -26,15 +26,45 @@ For more detailed information see [1992 kivinen in bugs.md](/bugs.md#1992-kivine ### Try: ```sh -./kivinen +./kivinen.alt -./kivinen a +./kivinen.alt a -./kivinen a b +./kivinen.alt a b ``` See also the author's remarks for other variations. +Also try changing the speed this game moves. For instance if you wish to change +the `usleep(3)` value to `30000` from `20000`, try: + +```sh +make clobber CDEFINE="-DZ=30000" alt # make it slower + +make clobber CDEFINE="-DZ=10000" alt # make it faster +``` + +Then use the same syntax as above and described by the author. + + +## Original code: + +As noted above, the alt version is recommended because the code goes too fast in +modern systems. If you wish to see the original you may do so with the original +code. + + +### Original build: + +```sh +make all +``` + + +### Original use: + +Use `kivinen` as you would `kivinen.alt`. + ## Judges' remarks: diff --git a/1992/kivinen/kivinen.alt.c b/1992/kivinen/kivinen.alt.c new file mode 100644 index 000000000..abb713dcd --- /dev/null +++ b/1992/kivinen/kivinen.alt.c @@ -0,0 +1,39 @@ +#include +#define exit(a) (exit(a),0) +# define X( x,v,y) XMoveWindow(d,s[x],(v)*z,(y)*z) +# define _ ButtonPressMask|ButtonReleaseMask +# define I( x,y) XSelectInput(d,s[x],y) +# define N( v) (XMapWindow(d,s[v]),v) +# define V VisibilityChangeMask +# define A XCreateSimpleWindow +# define D DefaultScreen(d) +# define E r.xbutton.button +# define R BlackPixel(d,D) +# define S r.xvisibility + + int main(a)int a;{Window s[53];int w,u,i,c,y,l=0 + ,q,e=32,t,k,j=~0,z=(a+1)/2,x=a&1,v=z&1;XEvent r;Display* + d=XOpenDisplay("");s[0]=A(d,DefaultRootWindow(d),200,200,(x& + v?330:120)*z,215*z,2,R,R);I(N(c=0),_);for(;c<(x?32:52);c++){s[ + c+1]=A(d,s[0],x ?c*20*z:(c-1)%10 *12*z,x?-20*z:( + c-1)/10*12*z,x ?z*(c^31?10: 2):z*10*(c?1:2 + ), x& v?z*10: (c &&!x?10:1+ x) *z,k =q=1, R, + WhitePixel(d ,D));I (N(c+1), V);}X( N(1),y=(x&v) + *115+50,x*70+ 60 ); X(N(c-- )+ 1,x?-10:(i=y) + ,u=!x*130-20); while(c &&e< 160){if(x){if( + v){l=!(e &32)*9; for(w=30; w--;){ if(s[w+2]){ k=w% + 10;l=e&32?k>l?k:l:k300?e++:0)):(q--,q+l<10?e++:0); } u>140? + exit(c):u>-20?X(32,i,u-=(v?5:-1 )):(!v?(u =5,srandom(time(0)),i= + random()%88+6):0); } else{k>0?i+=(i>105?k= -k:k):(i+=(i<1?k= -k: + k)); j>0?u +=(u>140?exit(++c):j):(u+=(u <1?j= -j:j + )); X( 52,i,u);}XSync(d,0); while( + XCheckMaskEvent(d ,_|V,&r))if(!(r. type==ButtonPress + ?(E&1||!x||!v?t=E*4-8 :u<0?i=y+4,u=122:1):r + .type==ButtonRelease&&E?t=0,1:r.type^VisibilityNotify|S.state^1) + )for(x&v?(u= -15),w++:(w=0);++w <52-x*20;)if + (s[w] ==S.window)x&&v|| w ^1? + XUnmapWindow (d,s[w]) ,s[w]=0,c--: + 0,l=1; if(!x&&l)j= -j,l=0; if(l&x&&!v + )u=~19,c--,l=0;t=(!x||!v) &&(y<5&&t<0||y>95&&t>0)?0:t + ;s[1]?X(1,y+=x&v?t:t/(x+1),130):exit(++c);usleep(Z);};return c;} diff --git a/1992/kivinen/kivinen.c b/1992/kivinen/kivinen.c index bfd7ae901..562a85ea6 100644 --- a/1992/kivinen/kivinen.c +++ b/1992/kivinen/kivinen.c @@ -1,5 +1,5 @@ #include -#define ext(a) (exit(a),0) +#define exit(a) (exit(a),0) # define X( x,v,y) XMoveWindow(d,s[x],(v)*z,(y)*z) # define _ ButtonPressMask|ButtonReleaseMask # define I( x,y) XSelectInput(d,s[x],y) @@ -24,9 +24,9 @@ v){l=!(e &32)*9; for(w=30; w--;){ if(s[w+2]){ k=w% 10;l=e&32?k>l?k:l:k300?e++:0)):(q--,q+l<10?e++:0); } u>140? - ext(c):u>-20?X(32,i,u-=(v?5:-1 )) :(!v?(u =5,srandom(time(0)),i= + exit(c):u>-20?X(32,i,u-=(v?5:-1 )):(!v?(u =5,srandom(time(0)),i= random()%88+6):0); } else{k>0?i+=(i>105?k= -k:k):(i+=(i<1?k= -k: - k)); j>0?u +=(u>140?ext(++c):j):(u+=(u <1?j= -j:j + k)); j>0?u +=(u>140?exit(++c):j):(u+=(u <1?j= -j:j )); X( 52,i,u);}XSync(d,0); while( XCheckMaskEvent(d ,_|V,&r))if(!(r. type==ButtonPress ?(E&1||!x||!v?t=E*4-8 :u<0?i=y+4,u=122:1):r @@ -36,4 +36,4 @@ XUnmapWindow (d,s[w]) ,s[w]=0,c--: 0,l=1; if(!x&&l)j= -j,l=0; if(l&x&&!v )u=~19,c--,l=0;t=(!x||!v) &&(y<5&&t<0||y>95&&t>0)?0 - :t;s[1]?X(1,y+=x&v?t:t/(x+1),130):ext(++c);usleep(Z);};return(c);} + :t;s[1]?X(1,y+=x&v?t:t/(x+1),130):exit(++c);};return(c);} diff --git a/thanks-for-fixes.md b/thanks-for-fixes.md index fafe196fc..290a35864 100644 --- a/thanks-for-fixes.md +++ b/thanks-for-fixes.md @@ -1542,15 +1542,16 @@ operator so that it could be used in binary expressions. It was observed that on modern systems this goes much too quick. Yusuke created a patch that calls `usleep(3)` but Cody thought the value was too slow so he -made it a macro in the Makefile `Z`, defaulting at 15000. You can reconfigure it -like: +made it a macro in the Makefile `Z`, defaulting at 15000. This was made an [alt +version](1992/kivinen/kivinen.alt.c) and it is recommended one use the alt +version first. See the README.md file to see how to reconfigure it. -```sh -make clobber Z=1000 all -``` - -This was not made an alternate version because it moves so fast that it's nigh -impossible to use otherwise. +Cody also made the fixed version (the code relied on `exit(3)` returning to use +in binary expressions) (and alt code from it) more like the original by renaming +the `ext` macro to be `exit` which uses the comma operator. He made it so the +line lengths match the original code, at least as best as possible (if not +perfectly), including start and end columns, often (if not all) with the same +start and end character. Yusuke also noted that there is a bug in the program where right after starting it moves towards the right but if you click the mouse it goes back.