diff --git a/2020/tsoj/.gitignore b/2020/tsoj/.gitignore index a1e7bc695..160504d00 100644 --- a/2020/tsoj/.gitignore +++ b/2020/tsoj/.gitignore @@ -1,2 +1,3 @@ prog +prog.alt prog.orig diff --git a/2020/tsoj/Makefile b/2020/tsoj/Makefile index e09e6a68d..746060749 100644 --- a/2020/tsoj/Makefile +++ b/2020/tsoj/Makefile @@ -114,8 +114,8 @@ OBJ= ${PROG}.o DATA= TARGET= ${PROG} # -ALT_OBJ= -ALT_TARGET= +ALT_OBJ= ${PROG}.alt.o +ALT_TARGET= ${PROG}.alt ################# diff --git a/2020/tsoj/README.md b/2020/tsoj/README.md index 114e7fde7..b4cb5c028 100644 --- a/2020/tsoj/README.md +++ b/2020/tsoj/README.md @@ -11,6 +11,10 @@ make ``` +There is an [alternate version](#alternate-code) which has controls that will +make much more sense to those familiar with vi. + + ## To use: ```sh @@ -27,6 +31,30 @@ make ``` +## Alternate code: + +This version has the difference of moving forwards, left, backwards and right, +where instead of `w`, `a`, `s` and `d`, you can use `k`, `h`, `j` and `l`. + + +### Alternate build: + +```sh +make alt +``` + +### Alternate use: + +```sh +# Make your terminal as large as possible, possibly reduce your font size +# then... +./prog.alt +``` + +..and maybe curse less than you might otherwise, but still probably curse (see +below) :-) + + ## Judges' remarks: This game does not use curses, but you may end up cursing. @@ -54,6 +82,8 @@ reverse indentation style. /______\ /\/\ ``` + + #### Compile and run ###### Linux ``` diff --git a/2020/tsoj/prog.alt.c b/2020/tsoj/prog.alt.c new file mode 100644 index 000000000..cd68e5eb3 --- /dev/null +++ b/2020/tsoj/prog.alt.c @@ -0,0 +1,60 @@ +#include +#include +#include +#include +#include +#include +#include +#include +int t(){struct timeval t;gettimeofday(&t,0);return t.tv_usec/1000+t.tv_sec*1000;} + + #define g(x,y,u,v,s)\ + for(int j=0,X=x,Y=y;j=0&&X>=0;++j)memcpy(&f[Y+j][X],&s[j*u],u) + #define l(x,y,w,h,a,b,c,d)\ + !((x-a>c&&x>=a)||(a-x>w&&a>=x)||(y-b>d&&y>=b)||(b-y>h&&b>=y)) + + int main(){ + struct termios z,o;tcgetattr(0,&z);o=z;z.c_lflag&=~ICANON&~ECHO; + z.c_cc[VMIN]=0;z.c_cc[VTIME]=0;tcsetattr(0,TCSANOW,&z); + srand(time(0));struct winsize v;ioctl(STDOUT_FILENO,TIOCGWINSZ,&v); + int h=v.ws_row,w=v.ws_col,A=w*h/100,l=t(),k,s=0,g=1,i,c=0,L; + struct V{float x,y;}p={w/2,h/2},b={-3*h},a[A],m[A]; + char*r=" /\\ /__\\ ^^ ",*n="o0o0OO",u=0,q,f[h+1][w]; + while(u^'q'){ + float d=(t()-l)*.001; + q=u;do read(0,&u,1);while((u&'p')>=(u|'p')); + l=t();c+=15;i=h*w-1; + K: + L=c*d;L=abs(((i/w)-L)*(i%w)+h*w); + (*f)[i]=L%3+L%5+L%7+L%11+L%13+L%17+L%19>14?32:46; + if(i--)goto K; + u^' '?0:(b.x=p.x+2,b.y=p.y,u=q); + q^'h'?q^'l'?q^'k'?q^'j'?0: + (p.y+=d*15): + (p.y+=d*-15): + (p.x+=d*20): + (p.x+=d*-20); + p.x=p.x<0?0:p.x>=w-4?w-4:p.x; + p.y=p.y<0?0:p.y>=h-3?h-3:p.y; + b.y+=d*-20; + int Y=b.y,X=b.x;Y*w+X>=0?f[Y][X]=64:0; + i=A-1; + L: + k=0;struct V*e=&a[i],*z=&m[i]; + e->x+=d*z->x;e->y+=d*z->y; + l(b.x,b.y,1,1,e->x,e->y,6,4)&&!g?k=1,s++,b.y=-3*h:0; + e->x<0-3||e->x>=w+3||e->y>=h+2||k||g? + e->y=-rand()%h*(1+g), + e->x=rand()%w, + z->x=-8+rand()%15, + z->y=10+rand()%5:0; + l(p.x,p.y,4,3,e->x,e->y,3,2)?u='q':0; + g(e->x,e->y,3,2,n); + if(i--)goto L; + g(p.x,p.y,4,3,r); + *(f[h])=0; + printf("\033[0;4H%s\033[0;0H \033[4D%i\n",&f[0][4],s); + while(t()-l<9);g=0; + } + tcsetattr(0,TCSADRAIN,&o); + } diff --git a/thanks-for-fixes.md b/thanks-for-fixes.md index 58222e219..4192a1cf3 100644 --- a/thanks-for-fixes.md +++ b/thanks-for-fixes.md @@ -2851,3 +2851,10 @@ Cody added `-L`/`-I` paths to the Makefile to let this compile more easily if the user has installed the appropriate library with [MacPorts](https://www.macports.org) (with the default MacPorts prefix `/opt/local`). + + +## [2020/tsoj](2020/tsoj/prog.c) ([README.md](2020/tsoj/README.md)) + +Cody added [alternate code](2020/tsoj/README.md#alternate-code) that will feel +more at home for vi users. One might still end up cursing (see the README.md +file) but probably a lot less :-)