Merge pull request #1295 from xexyl/1991-rince-fixes-alt
Fix 1991/rince and add two alt versions
This commit is contained in:
7 files changed
+107
-8
No files matched your search
@@ -1,3 +1,5 @@
|
||||
rince
|
||||
rince.alt
|
||||
rince.alt2
|
||||
rince.orig
|
||||
prog.orig
|
||||
+9
-3
@@ -58,7 +58,7 @@ ARCH=
|
||||
|
||||
# Defines that are needed to compile
|
||||
#
|
||||
CDEFINE=
|
||||
CDEFINE= -DMAX_MOVES=484
|
||||
|
||||
# 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 ${PROG}.alt2.o
|
||||
ALT_TARGET= ${PROG}.alt ${PROG}.alt2
|
||||
|
||||
|
||||
#################
|
||||
@@ -137,6 +137,12 @@ ${PROG}: ${PROG}.c
|
||||
alt: data ${ALT_TARGET}
|
||||
@${TRUE}
|
||||
|
||||
${PROG}.alt: ${PROG}.alt.c
|
||||
${CC} ${CFLAGS} $< -o $@ ${LDFLAGS}
|
||||
|
||||
${PROG}2.alt: ${PROG}.alt2.c
|
||||
${CC} ${CFLAGS} $< -o $@ ${LDFLAGS}
|
||||
|
||||
# data files
|
||||
#
|
||||
data: ${DATA}
|
||||
|
||||
+57
-4
@@ -4,6 +4,10 @@
|
||||
make all
|
||||
```
|
||||
|
||||
There are two [alternate versions](#alternate-code) which allow one to not be
|
||||
restricted in movements or to change the maximum number of movements, even if
|
||||
that's fewer than the original program.
|
||||
|
||||
|
||||
## To use:
|
||||
|
||||
@@ -12,6 +16,54 @@ make all
|
||||
```
|
||||
|
||||
|
||||
## Alternate code:
|
||||
|
||||
The first alternate version, [rince.alt.c](rince.alt.c), disables a maximum move
|
||||
count so that anyone with enough patience and time can complete the puzzle,
|
||||
without having to worry about how many moves they make. The second version,
|
||||
[rince.alt2.c](rince.alt2.c), allows one to reconfigure at compilation the
|
||||
maximum number of moves, even if that is lowering the count.
|
||||
|
||||
The author set the maximum number of moves to 484.
|
||||
|
||||
|
||||
### Alternate build:
|
||||
|
||||
|
||||
```sh
|
||||
make alt
|
||||
```
|
||||
|
||||
This will build both alt versions where the first one, `rince.alt`, has no
|
||||
restrictions in the number of movements and the second one, `rince.alt2`, has a
|
||||
configurable maximum number of moves allowed, defaulting to the entry's max,
|
||||
484.
|
||||
|
||||
To reconfigure the maximum number of moves:
|
||||
|
||||
```sh
|
||||
make clobber CDEFINE+="-DMAX_MOVES=5" alt
|
||||
```
|
||||
|
||||
### Alternate use:
|
||||
|
||||
To run the first alt version:
|
||||
|
||||
```sh
|
||||
./rince.alt
|
||||
```
|
||||
|
||||
To run the second alt version:
|
||||
|
||||
```sh
|
||||
./rince.alt2
|
||||
```
|
||||
|
||||
Can you figure out how to make the two alternate versions equivalent in
|
||||
functionality without modifying the code? That is can you make the second alt
|
||||
version end up allowing any number of movements?
|
||||
|
||||
|
||||
## Judges' remarks:
|
||||
|
||||
This entry has been updated to allow most ANSI C compilers.
|
||||
@@ -30,7 +82,7 @@ Key to map:
|
||||
|
||||
```
|
||||
|
|
||||
###### | | | /\ /--\ ==| /\ | | Directonal keys\
|
||||
###### | | | /\ /--\ ==| /\ | | Directonal keys
|
||||
###### Solid Wall | ----|| \/ /\ ||---- (unlock doors of
|
||||
###### | \/ ==| \--/ \/ the same direction)
|
||||
|\
|
||||
@@ -46,11 +98,12 @@ Key to map:
|
||||
/@@@\ boulder | < > around (if only!) or manufacture by pushing
|
||||
\@@@/ | \/ two 'crushable' rocks together.
|
||||
|
|
||||
```
|
||||
|
||||
The general idea of the game is to collect all the diamonds. This must
|
||||
be done in the minimum amount of moves. I've allowed a margin of 5
|
||||
moves which brings the moves allowed to 484. (alter the value of 'u' in
|
||||
the program to set the max moves allowed)
|
||||
moves which brings the moves allowed to `484`. (alter the value of `u` in
|
||||
the program to set the max moves allowed).
|
||||
|
||||
There are two types of boulders. Both can be pushed around, but only
|
||||
the hollow (crushable) ones can be turned into diamonds (by pushing it
|
||||
@@ -60,7 +113,7 @@ Of the four types of doors (and keys) only 3 have been defined. This
|
||||
was done to keep the source as low as possible (as I only used 3 in the
|
||||
map). To unlock a door simply push a key into the corresponding door.
|
||||
Take care that it's facing in the correct direction.
|
||||
```
|
||||
|
||||
|
||||
## Copyright and CC BY-SA 4.0 License:
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
#include <curses.h>
|
||||
int X[]={-1,0,0,1},Y[]={0,1,-1,0},x,y,D,i,j,a;
|
||||
char o,m,*t,*O="MNOH",*k="hjkl",*s="######\0######\0######\0 \0 \0 \0 ___ \0 / \\\0 \\___/\0 ___ \0 /@@@\\\0 \\@@@/\0| | /\\\0----||\0 \\/\0 /--\\\0 \\/ \0 ==| \0 ==| \0 /\\ \0 \\--/\0 /O__o\0 \\___/\0 /_\\_ \0 << \0 << \0 << \0 \0vvvvvv\0 \0 \0^^^^^^\0 \0 /\\ \0 < > \0 \\/ \0o__O\\ \0\\___/ \0 _/_\\ \0 O__O \0/----\\\0_/ \\_\0 ^__^ \0/----\\\0_/ \\_" ,
|
||||
M[12][22]={"AAAAAAAAAAAAAAAAAAAAAA" ,"ALCABBBBBBBABBCBBCABBA", "ACCABAKAAABAFBABABAEBA", "ABBBBABBIBBBBBEEABACLA", "ACCBNIBBAAAAGALBBBABCA", "AAAAAAAJACBABBCABAABCA", "ALLAACCBACBAAALLCABBBA", "ABDLAAABABCAAAALCABBLA", "ABCBIBBBBBBBBAAAAACBBA", "ABCCAABBADBBBBDBDBDBCA", "ALBBACCCCDBCABBBDBBBBA", "AAAAAAAAAAAAAAAAAAAAAA" };main(){initscr();clear();
|
||||
noecho();cbreak();x=y=4;D=39,o='M';m=M[y][x] ;while(D){for(i=j=a=0;j<7;!(mvaddstr(
|
||||
j*3+a,i*6,s+(((M[((y-1)/5)*5+j][((x-1)/10)*10+i]-'A')*3+a++)*7)),a^3)&&(a=0,!
|
||||
(++i^12))&&(a=i=0,j++));refresh();M[y][x] ='B';if(t=(char*)strchr(k,getch())){int e=
|
||||
x,g=y,f=x,h=y,d=t-k;o=O[d];f=(e=x+X[d])+X[d];h=(g=y+Y[d])+Y[d];switch(M[g][e] ){case
|
||||
'B':x=e;y=g;break ;case 'C':if(M[h][f] =='B')M[h][f] =M[g][e] ,x=e,y=g; else if(M[h][f] =='C')M[h][f] =M[g][e] ='L';break ;case 'D':if(M[h][f] =='B')M[h][f] =M[g][e] ,x=e,y=g; break ;case'L':x=e;y=g;D
|
||||
--;break ;case 'E':if(M[h][f] =='B')M[h][f] =M[g][e] ,x=e,y=g; else if(M[h][f] =='I'&&d==0)M[h][f] =M[g][e] ='B';break ; case 'F':if(M[h][f] =='B')M[h][f] =M[g][e] ,x=e,y=g; else if(M[h][f] =='J'&&d==1)M[h][f] =M[g][e] ='B';break ; case 'G':if(M[h][f] =='B')M[h][f] =M[g][e] ,x=e,y=g; else if(M[h][f] =='K'&&d==2)M[h][f] =M[g][e] ='B';break ; }}m=M[y][x] ;M[y][x] =o;}clear();mvaddstr(12
|
||||
,31,"Well done!");move(23,0);refresh();endwin();printf("Well done!");return 0;}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
#include <curses.h>
|
||||
int u=MAX_MOVES,X[]={-1,0,0,1},Y[]={0,1,-1,0},x,y,D,i,j,a;
|
||||
char o,m,*t,*O="MNOH",*k="hjkl",*s="######\0######\0######\0 \0 \0 \0 ___ \0 / \\\0 \\___/\0 ___ \0 /@@@\\\0 \\@@@/\0| | /\\\0----||\0 \\/\0 /--\\\0 \\/ \0 ==| \0 ==| \0 /\\ \0 \\--/\0 /O__o\0 \\___/\0 /_\\_ \0 << \0 << \0 << \0 \0vvvvvv\0 \0 \0^^^^^^\0 \0 /\\ \0 < > \0 \\/ \0o__O\\ \0\\___/ \0 _/_\\ \0 O__O \0/----\\\0_/ \\_\0 ^__^ \0/----\\\0_/ \\_" ,
|
||||
M[12][22]={"AAAAAAAAAAAAAAAAAAAAAA" ,"ALCABBBBBBBABBCBBCABBA", "ACCABAKAAABAFBABABAEBA", "ABBBBABBIBBBBBEEABACLA", "ACCBNIBBAAAAGALBBBABCA", "AAAAAAAJACBABBCABAABCA", "ALLAACCBACBAAALLCABBBA", "ABDLAAABABCAAAALCABBLA", "ABCBIBBBBBBBBAAAAACBBA", "ABCCAABBADBBBBDBDBDBCA", "ALBBACCCCDBCABBBDBBBBA", "AAAAAAAAAAAAAAAAAAAAAA" };main(){initscr();clear();
|
||||
noecho();cbreak();x=y=4;D=39,o='M';m=M[y][x] ;while(D&&u){for(i=j=a=0;j<7;!(mvaddstr(
|
||||
j*3+a,i*6,s+(((M[((y-1)/5)*5+j][((x-1)/10)*10+i]-'A')*3+a++)*7)),a^3)&&(a=0,!
|
||||
(++i^12))&&(a=i=0,j++));refresh();M[y][x] ='B';if(t=(char*)strchr(k,getch())){int e=
|
||||
x,g=y,f=x,h=y,d=t-k;o=O[d];f=(e=x+X[d])+X[d];h=(g=y+Y[d])+Y[d];switch(M[g][e] ){case
|
||||
'B':x=e;y=g,u--;break ;case 'C':if(M[h][f] =='B')M[h][f] =M[g][e] ,x=e,y=g,u--; else if(M[h][f] =='C')M[h][f] =M[g][e] ='L';break ;case 'D':if(M[h][f] =='B')M[h][f] =M[g][e] ,x=e,y=g,u--; break ;case'L':x=e;y=g,u--;D
|
||||
--;break ;case 'E':if(M[h][f] =='B')M[h][f] =M[g][e] ,x=e,y=g,u--; else if(M[h][f] =='I'&&d==0)M[h][f] =M[g][e] ='B';break ; case 'F':if(M[h][f] =='B')M[h][f] =M[g][e] ,x=e,y=g,u--; else if(M[h][f] =='J'&&d==1)M[h][f] =M[g][e] ='B';break ; case 'G':if(M[h][f] =='B')M[h][f] =M[g][e] ,x=e,y=g,u--; else if(M[h][f] =='K'&&d==2)M[h][f] =M[g][e] ='B';break ; }}m=M[y][x] ;M[y][x] =o;}clear();mvaddstr(12
|
||||
,31,u?"Well done!":"Too many moves");move(23,0);refresh();endwin();printf("%s\n",u?"Well done!":"Too many moves");return 0;}
|
||||
|
||||
+1
-1
@@ -8,5 +8,5 @@ j*3+a,i*6,s+(((M[((y-1)/5)*5+j][((x-1)/10)*10+i]-'A')*3+a++)*7)),a^3)&&(a=0,!
|
||||
x,g=y,f=x,h=y,d=t-k;o=O[d];f=(e=x+X[d])+X[d];h=(g=y+Y[d])+Y[d];switch(M[g][e] ){case
|
||||
'B':x=e;y=g,u--;break ;case 'C':if(M[h][f] =='B')M[h][f] =M[g][e] ,x=e,y=g,u--; else if(M[h][f] =='C')M[h][f] =M[g][e] ='L';break ;case 'D':if(M[h][f] =='B')M[h][f] =M[g][e] ,x=e,y=g,u--; break ;case'L':x=e;y=g,u--;D
|
||||
--;break ;case 'E':if(M[h][f] =='B')M[h][f] =M[g][e] ,x=e,y=g,u--; else if(M[h][f] =='I'&&d==0)M[h][f] =M[g][e] ='B';break ; case 'F':if(M[h][f] =='B')M[h][f] =M[g][e] ,x=e,y=g,u--; else if(M[h][f] =='J'&&d==1)M[h][f] =M[g][e] ='B';break ; case 'G':if(M[h][f] =='B')M[h][f] =M[g][e] ,x=e,y=g,u--; else if(M[h][f] =='K'&&d==2)M[h][f] =M[g][e] ='B';break ; }}m=M[y][x] ;M[y][x] =o;}clear();mvaddstr(12
|
||||
,31,u?"Well done!":"Too many moves");move(23,0);refresh();endwin();return 0;}
|
||||
,31,u?"Well done!":"Too many moves");move(23,0);refresh();endwin();printf("%s\n",u?"Well done!":"Too many moves");return 0;}
|
||||
|
||||
@@ -1192,6 +1192,20 @@ some fun input for fun but mostly different output. He added a great string from
|
||||
Brian Westley and Cody also added several of his own (can you figure out exactly
|
||||
which ones? :-) )
|
||||
|
||||
## [1991/rince](1991/rince/rince.c) ([README.md](1991/rince/README.md))
|
||||
|
||||
Cody fixed it so that the messages that show if you won or lost will be seen
|
||||
after the end of the game. The reason it did not work before is curses was ended
|
||||
at the end of the program which clears the screen. To make it look most like the
|
||||
original entry Cody left the message before ending curses in and printed another
|
||||
message of the same kind after `endwin()` was called with the exception that he
|
||||
added a newline at the end of the screen to be more user friendly.
|
||||
|
||||
Cody also added two alt versions, one to remove the maximum number of moves you
|
||||
may make and another to let you configure the maximum number of moves, even if
|
||||
that is making it harder to win. Naturally the above fix was applied to these
|
||||
versions too.
|
||||
|
||||
|
||||
## [1991/westley](1991/westley/westley.c) ([README.md](1991/westley/README.md]))
|
||||
|
||||
|
||||
Reference in new issue
Block a user