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.
This commit is contained in:
1 parent
9c568df22f
commit
1181899ed9
5 files changed
+23
-39
No files matched your search
@@ -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).
|
||||
|
||||
@@ -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;
|
||||
o<N;e[o++]=3){J(o,0)=J(o,1)=J(o,2)=-1;c[o]=d[o]=g[o]=0;
|
||||
b[o]=N*2;}r(0);s();}F(s());t();}s(){G o,p;I(o=0;o<N;o++){
|
||||
@@ -30,11 +30,11 @@ J(x,e[x])=y;J(y,e[y])=x;K(!r(y)){J(x,e[x])=J(y,e[y])=-1;(e[y])++;
|
||||
(e[x])++;}L t=0;}H(1);}n(){G r,n;char v;do{r=D;}
|
||||
F(c[r]||d[r]||(b[r]<3)||d[J(r,0)]||d[J(r,1)]||d[J(r,2)]||
|
||||
c[J(r,0)]||c[J(r,1)]||c[J(r,2)]);F(1){E"You are in room %d\n",r);
|
||||
K(f[r]){i++;E"You found an arrow\n");j+=20;f[r]=0;}K(b[r]==0){
|
||||
K(f[r]){i++;E"You found an arrow\n");Y++;j+=20;f[r]=0;Y++;}K(b[r]==0){
|
||||
E"Wumpus meat\n");j-=100;A;}K(d[r]){E"You fell in a pit\n");j-=50;
|
||||
A;}K(r==k){K(i){i--;l++;j-=20;E"You are missing an arrow!\n");
|
||||
}K(l==3+(W>0?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;n<N;n++)b[n]=2*N;w(D,0);j-=100;}K(v=='\n'){j-=50;
|
||||
E"You have %d arrows\n",i);H;}}}
|
||||
E"You have %d arrow%s\n",i,i!=1?"s":"");H;}}}
|
||||
@@ -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,j=0,k,l=0;
|
||||
G a[N][3],b[N],c[N],d[N],e[N],f[N],g[N],i,j=0,X=0,Y=0,k,l=0;
|
||||
main(){m();n();A;}m(){G o;srandom(getpid());do{I(o=0;
|
||||
o<N;e[o++]=3){J(o,0)=J(o,1)=J(o,2)=-1;c[o]=d[o]=g[o]=0;
|
||||
b[o]=N*2;}r(0);s();}F(s());t();}s(){G o,p;I(o=0;o<N;o++){
|
||||
@@ -30,11 +30,11 @@ J(x,e[x])=y;J(y,e[y])=x;K(!r(y)){J(x,e[x])=J(y,e[y])=-1;(e[y])++;
|
||||
(e[x])++;}L t=0;}H(1);}n(){G r,n;char v;do{r=D;}
|
||||
F(c[r]||d[r]||(b[r]<3)||d[J(r,0)]||d[J(r,1)]||d[J(r,2)]||
|
||||
c[J(r,0)]||c[J(r,1)]||c[J(r,2)]);F(1){E"You are in room %d\n",r);
|
||||
K(f[r]){i++;E"You found an arrow\n");j+=20;f[r]=0;}K(b[r]==0){
|
||||
K(f[r]){i++;E"You found an arrow\n");Y++;j+=20;f[r]=0;}K(b[r]==0){
|
||||
E"Wumpus meat\n");j-=100;A;}K(d[r]){E"You fell in a pit\n");j-=50;
|
||||
A;}K(r==k){K(i){i--;l++;j-=20;E"You are missing an arrow!\n");
|
||||
}K(l==3){E"You catch the robber and recover all 3 arrows!\n");
|
||||
i=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 arrow\n");H;}i--;
|
||||
char v;K(i==0){E"You have no arrow\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;n<N;n++)b[n]=2*N;w(D,0);j-=100;}K(v=='\n'){j-=50;
|
||||
E"You have %d arrows\n",i);H;}}}
|
||||
E"You have %d arrow%s\n",i,i!=1?"s":"");H;}}}
|
||||
@@ -1126,29 +1126,6 @@ _before you choose where to shoot_.
|
||||
When you shoot it will move you to that room so if you end up shooting into a
|
||||
pit room you will end up dying even though you didn't explicitly move there.
|
||||
|
||||
### STATUS: known bug - please help us fix
|
||||
|
||||
A (mis)feature is that one must have had all arrows stolen in order to recover
|
||||
all the arrows from the robber. This means that if you end up shooting an arrow
|
||||
you can never recover all the arrows from the robber because the count of arrows
|
||||
stolen can never be high enough. There are a number of ways this might be fixed,
|
||||
some of which Cody notes:
|
||||
|
||||
- If you have zero arrows and you come across the robber you could give them all
|
||||
back. This is not correct though because if you never had that many arrows you
|
||||
would end up getting arrows back that you never had in the first place.
|
||||
- A new variable, an `int`, could be added that keeps track of the number of
|
||||
arrows you have fired and then if you come across the robber and they took the
|
||||
number of arrows with the difference of the number fired then you would give
|
||||
back how many (the difference) the robber stole rather than all the arrows. This
|
||||
would be the right approach but there are certainly other ways to go about it.
|
||||
|
||||
A tip is that the number of arrows stolen is `l` and the number of arrows you
|
||||
have is `i`. For the alt version that Cody added the starting number of arrows
|
||||
is in the constant `W`, defaulting to 3.
|
||||
|
||||
You are welcome to try and fix this (mis)feature.
|
||||
|
||||
|
||||
## 1994 ldb
|
||||
|
||||
@@ -1406,6 +1383,7 @@ example is in macOS).
|
||||
|
||||
If you can fix this we welcome it!
|
||||
|
||||
|
||||
## 1996 gandalf
|
||||
|
||||
### STATUS: missing or dead link - please provide them
|
||||
|
||||
+10
-3
@@ -1758,9 +1758,16 @@ As in some places it would properly say that you have '1 arrow' or else, if you
|
||||
have any other number of arrows (including 0), it would say 'arrows', Cody fixed
|
||||
a place where it always said 'arrows'. A minor fix and not that important.
|
||||
|
||||
Cody notes that there is a (mis)feature in the program that might want to be
|
||||
fixed that he has not had the time to fix yet; see [1991/dodsond2 in
|
||||
bugs.md](/bugs.md#1994-dodsond2) for more details.
|
||||
Cody also fixed the problem where one could only get the arrows back from the
|
||||
robber if the robber stole as many arrows as you ever found rather than that
|
||||
minus how many you have shot. In other words if you had three arrows and shot
|
||||
one and found no more you could never get the arrows back from the robber
|
||||
because you could never lose all three since you spent one. This bug manifested
|
||||
itself in another way too: once you got the arrows back the counter was not
|
||||
reset so you could only get the arrows back once even if the robber stole more.
|
||||
Now the counters are reset. The way this bug was fixed is that there is now a
|
||||
counter for how many you have found and how many you shot in addition to the two
|
||||
that already existed, how many you had and how many were stolen.
|
||||
|
||||
|
||||
## [1994/horton](1994/horton/horton.c) ([README.md](1994/horton/README.md))
|
||||
|
||||
Reference in new issue
Block a user