Fixes in 1994/dodsond2 + add alt code
Fixed bug where in some cases the program would enter an infinite loop, forcing one to kill the program. Fixed bug where only if you had more than one arrow would shooting it take you to the room you shoot into (it now will do it even if you're using the last arrow). This fix is done the same way as the above fix was made as they both have to do with shooting the final arrow. The alt code allows one to cheat by configuring (at compile time) the number of arrows to start out with. If one loses (as in stolen) all their arrows it will be (of course) 0 but if one also gets to the robber they'll get back the 3 + starting number of arrows (in the original this is just 3) assuming they have had that many stolen. That is a (mis)feature or maybe a bug that is carried over from the original entry that might or might not want to be fixed. I described how it might be done in the bugs.md but as I don't have time to do it now, focusing instead on the README.md files of the remaining entries. The alt version might allow one to more easily test this. Besides the above (mis)feature or bug added to the bugs.md some features that should not be fixed were added to bugs.md. It is questionable whether or not the above should be fixed but it seems like since there is dead code, if one ends up shooting an arrow then they cannot get back the arrows that were stolen even they have have lost all that they did not shoot, that it should be fixed. But it might be argued that you're not supposed to get any back if you shoot them since in that case these were already spent/used. At the same time one could argue that you should at least get back the ones that were stolen.
This commit is contained in:
1 parent
934ac91291
commit
eecc3146c4
8 files changed
+177
-17
No files matched your search
@@ -1,3 +1,4 @@
|
||||
dodsond2
|
||||
dodsond2.alt
|
||||
dodsond2.orig
|
||||
prog.orig
|
||||
@@ -39,7 +39,7 @@ include ../../var.mk
|
||||
# Common C compiler warnings to silence
|
||||
#
|
||||
CSILENCE= -Wno-error -Wno-implicit-function-declaration -Wno-return-type \
|
||||
-Wno-deprecated-non-prototype -Wno-strict-prototypes
|
||||
-Wno-deprecated-non-prototype -Wno-strict-prototypes -Wno-implicit-int
|
||||
|
||||
# Common C compiler warning flags
|
||||
#
|
||||
@@ -58,7 +58,7 @@ ARCH=
|
||||
|
||||
# Defines that are needed to compile
|
||||
#
|
||||
CDEFINE=
|
||||
CDEFINE= -DW=3
|
||||
|
||||
# Include files that are needed to compile
|
||||
#
|
||||
@@ -114,8 +114,8 @@ OBJ= ${PROG}.o
|
||||
DATA=
|
||||
TARGET= ${PROG}
|
||||
#
|
||||
ALT_OBJ=
|
||||
ALT_TARGET=
|
||||
ALT_OBJ= ${PROG}.alt.o
|
||||
ALT_TARGET= ${PROG}.alt
|
||||
|
||||
|
||||
#################
|
||||
@@ -138,6 +138,9 @@ ${PROG}: ${PROG}.c
|
||||
alt: data ${ALT_TARGET}
|
||||
@${TRUE}
|
||||
|
||||
${PROG}.alt: ${PROG}.alt.c
|
||||
${CC} ${CFLAGS} $< -o $@ ${LDFLAGS}
|
||||
|
||||
# data files
|
||||
#
|
||||
data: ${DATA}
|
||||
|
||||
+52
-11
@@ -5,12 +5,53 @@ make all
|
||||
```
|
||||
|
||||
|
||||
There is an [alternate version](#alternate-code) that allows you to cheat,
|
||||
giving you a configurable amount of arrows at the start of the game.
|
||||
|
||||
|
||||
### Bugs and (Mis)features:
|
||||
|
||||
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).
|
||||
|
||||
|
||||
## To use:
|
||||
|
||||
```sh
|
||||
./dodsond2
|
||||
```
|
||||
|
||||
## Alternate code:
|
||||
|
||||
This version allows you to choose how many arrows to start with, instead of the
|
||||
default 0. If one tried specifying a value < 0 it will set it to 0.
|
||||
|
||||
### Alternate build:
|
||||
|
||||
|
||||
```sh
|
||||
make alt
|
||||
```
|
||||
|
||||
The default number of arrows in this version is 3 but if you want to change it,
|
||||
say to 5, try:
|
||||
|
||||
```sh
|
||||
make clobber CDEFINE="-DW=5" alt
|
||||
```
|
||||
|
||||
### Alternate use:
|
||||
|
||||
```sh
|
||||
./dodsond2.alt
|
||||
```
|
||||
|
||||
|
||||
## Judges' remarks:
|
||||
|
||||
@@ -50,19 +91,19 @@ style hack, the [dodsond2.c](dodsond2.c) is further obfuscated.
|
||||
## Author's remarks:
|
||||
|
||||
Go searching for the Wumpus in the Caverns of Doom! But be careful...
|
||||
There are pits and bats waiting to seal your fate, as well as a\
|
||||
stealthy robber lurking in the shadows. Move through the rooms by\
|
||||
typing the number of the adjacent room you wish to visit. You can\
|
||||
feel a breeze if there is a pit in an adjacent room. A rustling sound\
|
||||
will tell you that bats are nearby. The scent of the evil Wumpus can\
|
||||
There are pits and bats waiting to seal your fate, as well as a
|
||||
stealthy robber lurking in the shadows. Move through the rooms by
|
||||
typing the number of the adjacent room you wish to visit. You can
|
||||
feel a breeze if there is a pit in an adjacent room. A rustling sound
|
||||
will tell you that bats are nearby. The scent of the evil Wumpus can
|
||||
be detected from 2 rooms away.
|
||||
|
||||
To win, you must find one or more arrows, determine where the Wumpus\
|
||||
is, and shoot him, all without falling into a pit or becoming the\
|
||||
next meal for the Wumpus. To shoot an arrow, type `s`. Then give a\
|
||||
list of the rooms you want to shoot into. The rooms must be\
|
||||
connected in the order you list them, or else the arrow may bounce\
|
||||
back and hit you. An arrow can go through as many as four rooms.\
|
||||
To win, you must find one or more arrows, determine where the Wumpus
|
||||
is, and shoot him, all without falling into a pit or becoming the
|
||||
next meal for the Wumpus. To shoot an arrow, type `s`. Then give a
|
||||
list of the rooms you want to shoot into. The rooms must be
|
||||
connected in the order you list them, or else the arrow may bounce
|
||||
back and hit you. An arrow can go through as many as four rooms.
|
||||
But beware that shooting an arrow and missing the Wumpus may
|
||||
awaken him.
|
||||
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#define A { E"Your score is %d\n",j);exit(0);}
|
||||
#define B(x,y) K(x<y){p=x;x=y;y=p;}
|
||||
#define C do{p=random()%N;}F(c[p]||d[p]);
|
||||
#define D random()%N
|
||||
#define E printf(
|
||||
#define F while
|
||||
#define G int
|
||||
#define H return
|
||||
#define I for
|
||||
#define J(r,j) a[r][j]
|
||||
#define K if
|
||||
#define L else
|
||||
#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=(W>0?W:0)*20,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++){
|
||||
B(J(o,2),J(o,1))B(J(o,1),J(o,0))B(J(o,2),J(o,1))K(J(o,0)==-1)H(1);
|
||||
}H(0);}t(){G o,p;I(o=0;o<N;o+=8){C c[p]=1;C d[p]=1;}w(D,0);I(o=0;
|
||||
o<3;o++){do{p=D;}F(c[p]||d[p]||f[p]||!b[p]);f[p]=1;}do{k=D;}
|
||||
F((c[k])||(d[k])||(b[k]==0));}w(o,d)G o,d;{G x;b[o]=d;I(x=0;
|
||||
x<3;x++)K(b[J(o,x)]>d)w(J(o,x),d+1);}G r(x)G x;{G y,t=0,u;
|
||||
F(e[x]){u=3;(e[x])--;do{y=D;K(t++>1000)H(0);K(t%100==0)u--;}
|
||||
F((y==x)||(e[y]<=0)||(y==J(x,2))||(y==J(x,1))||(e[y]<u));(e[y])--;
|
||||
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){
|
||||
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;}
|
||||
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");
|
||||
K(d[J(r,0)]||d[J(r,1)]||d[J(r,2)])E"You feel a breeze\n");
|
||||
K(c[J(r,0)]||c[J(r,1)]||c[J(r,2)])E"You hear a rustling sound\n");
|
||||
E"Passageways to room %d, %d, and %d\n",J(r,0),J(r,1),J(r,2));
|
||||
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--;
|
||||
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;}}}
|
||||
@@ -45,9 +45,9 @@ 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 arrow\n");H;}i--;
|
||||
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 arrows\n",i);H;}}F(!M(v));
|
||||
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");
|
||||
|
||||
Executable → Regular
File mode changed.
@@ -1114,6 +1114,42 @@ not `d-46`.
|
||||
# 1994
|
||||
|
||||
|
||||
## 1994 dodsond2
|
||||
|
||||
### STATUS: INABIAF - please **DO NOT** fix
|
||||
### Source code: [1994/dodsond2/dodsond2.c](1994/dodsond2/dodsond2.c)
|
||||
### Information: [1994/dodsond2/README.md](1994/dodsond2/README.md)
|
||||
|
||||
When you initiate shooting via the `s` command you immediately lose an arrow
|
||||
_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
|
||||
|
||||
### STATUS: INABIAF - please **DO NOT** fix
|
||||
|
||||
@@ -1732,6 +1732,30 @@ NOTE: the `N1` and `N2` are provided as notes in the README.md file describing
|
||||
this code. Other code is also described there.
|
||||
|
||||
|
||||
## [1994/dodsond2](1994/dodsond2/dodsond2.c) ([README.md](1994/dodsond2/README.md))
|
||||
|
||||
Cody fixed an infinite loop that could happen when you shoot an arrow and end up
|
||||
having no arrows, thus making one force quit the game. The problem was in a
|
||||
condition in the outer loop it would repeatedly get input (if `getchar()`
|
||||
returned `'\n'`), only if one has more than one arrow, returning after that.
|
||||
But if there were 0 arrows left it did not return and so the loop started over,
|
||||
doing nothing. This fix also seems to have fixed a problem where if you shoot
|
||||
your last arrow it would not move you to the room you shoot into (whereas if you
|
||||
had more arrows it would).
|
||||
|
||||
Cody added an alt version that allows one to cheat by specifying how many arrows
|
||||
to start with (this was for fun but it turned out a good way to debug the above
|
||||
infinite loop too).
|
||||
|
||||
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.
|
||||
|
||||
|
||||
## [1994/horton](1994/horton/horton.c) ([README.md](1994/horton/README.md))
|
||||
|
||||
Cody fixed this to check that four args were specified. With the use of the C
|
||||
|
||||
Reference in new issue
Block a user