From 1181899ed98cbc01c2dd5e605fa1f44f828860bb Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Sat, 11 Nov 2023 06:26:47 -0800 Subject: [PATCH] Fix bug of 1994/dodsond2 wrt arrows stolen The problem was that one could never get their arrows back from the robber if they ended up shooting an arrow because that means the number of arrows stolen could never be the right number of arrows. Now if the number of arrows stolen (when you encounter the robber) is equal to the number of arrows you found - the number of arrows you shot you get arrows back: as long as the robber took some of course. At this point the counters are reset so that the check does not fail the next time. Previously it compared to just 3 as there are only three arrows. But in the alt version (which was helpful to test this out more) this is obviously a problem even if it wasn't in the original. It was however a problem in the original because if you shot an arrow you could not get them back even if you have zero and encounter the robber. Of course now the check has to verify first (&&...) that the number of arrows stolen > 0 as otherwise the variables could get messed up. This should actually complete 1994/dodsond2 unless of course I missed something/made a mistake here. --- 1994/dodsond2/README.md | 1 - 1994/dodsond2/dodsond2.alt.c | 12 ++++++------ 1994/dodsond2/dodsond2.c | 12 ++++++------ bugs.md | 24 +----------------------- thanks-for-fixes.md | 13 ++++++++++--- 5 files changed, 23 insertions(+), 39 deletions(-) diff --git a/1994/dodsond2/README.md b/1994/dodsond2/README.md index d41688329..1284155da 100644 --- a/1994/dodsond2/README.md +++ b/1994/dodsond2/README.md @@ -15,7 +15,6 @@ The current status of this entry is: ``` STATUS: INABIAF - please **DO NOT** fix -STATUS: known bug - please help us fix ``` For more detailed information see [1994 dodsond2 in bugs.md](/bugs.md#1994-dodsond2). diff --git a/1994/dodsond2/dodsond2.alt.c b/1994/dodsond2/dodsond2.alt.c index 68ec43cd0..e241c9250 100644 --- a/1994/dodsond2/dodsond2.alt.c +++ b/1994/dodsond2/dodsond2.alt.c @@ -15,7 +15,7 @@ #define M isdigit #define N 30 #define P getchar() -G a[N][3],b[N],c[N],d[N],e[N],f[N],g[N],i=W>0?W:0,j=0,k,l=0; +G a[N][3],b[N],c[N],d[N],e[N],f[N],g[N],i=W>0?W:0,j=0,X=0,Y=W>0?W:0,k,l=0; main(){m();n();A;}m(){G o;srandom(getpid());do{I(o=0; o0?W:0)){E"You catch the robber and recover all %d arrows!\n",(W>0?W:0)+3); -i=(W>0?W:0)+3;j+=200;k=-1;}L{E"The robber scurries away\n");do{k=D;} +}K(l&&l==Y-X){E"You catch the robber and recover all %d arrow%s!\n",Y-X,Y-X!=1?"s":""); +i=l;l=Y=X=0;j+=200;k=-1;}L{E"The robber scurries away\n");do{k=D;} F((c[k])||(d[k])||(b[k]==0)||(k==r));}}K(c[r]){c[r]=0;c[D]=1;r=D; E"The bats pick you up and drop you in room %d\n",r);j-=10;}L{ K(b[r]<3)E"You smell a wumpus\n"); @@ -45,11 +45,11 @@ K(!g[r]){j+=10;g[r]=1;}do{v=P;K(v=='s')q(r);K(v=='l')break; K(v=='i')E"You have %d arrow%c\n",i,i-1?'s':' ');K(v=='q')A;} F(!M(v));K(M(v)){n=v-'0';v=P;K(M(v))n=n*10+v-'0'; K((J(r,0)==n)||(J(r,1)==n)||(J(r,2)==n))r=n;}}}}q(r)G r;{G z,n; -char v;K(i==0){E"You have no arrows\n");H;}i--; +char v;K(i==0){E"You have no arrows\n");H;}i--;X++; E"Shoot into which rooms? ");I(z=0;z<4;z++){j-=20*z;do{v=P; K((v=='\n')&&(i>0)){j-=50;E"You have %d arrow%c\n",i,i-1?'s':' ');H;}else K(i==0)H;}F(!M(v)); n=v-'0';v=P;K(M(v))n=10*n+v-'0';K((J(r,0)==n)||(J(r,1)==n)||(J(r,2) ==n)){r=n;K(b[r]==0){E"You have killed the Wumpus!\n");j+=500+i*100; A;}}L K(random()%3==1){E"The arrow bounces back and kills you\n"); j-=100;A;}L{I(n=0;n0)){j-=50;E"You have %d arrow%c\n",i,i-1?'s':' ');H;}else K(i==0)H;}F(!M(v)); n=v-'0';v=P;K(M(v))n=10*n+v-'0';K((J(r,0)==n)||(J(r,1)==n)||(J(r,2) ==n)){r=n;K(b[r]==0){E"You have killed the Wumpus!\n");j+=500+i*100; A;}}L K(random()%3==1){E"The arrow bounces back and kills you\n"); j-=100;A;}L{I(n=0;n