Merge pull request #1772 from xexyl/tsoj2020
This commit is contained in:
7 files changed
+215
-90
No files matched your search
@@ -21,6 +21,11 @@ play out.wav
|
||||
```
|
||||
|
||||
|
||||
NOTE: `play` comes from SoX, the Swiss Army Knife of sound processing programs.
|
||||
If you don't have this installed, see [FAQ 3.10: How do I compile and use an
|
||||
IOCCC winner that requires sound](/faq.md#faq3_10).
|
||||
|
||||
|
||||
## Judges' remarks:
|
||||
|
||||
Do you need to pretend enjoying a more spacious living environment than you
|
||||
|
||||
+75
-36
@@ -4,6 +4,9 @@
|
||||
make
|
||||
```
|
||||
|
||||
There is an alternate version provided by the author. See [Alternate
|
||||
code](#alternate-code) below.
|
||||
|
||||
|
||||
## To use:
|
||||
|
||||
@@ -35,21 +38,27 @@ An alternate version of this entry, [prog.alt.c](prog.alt.c), is provided. This
|
||||
alternate code lacks the additional rule to flag all unprobed cells. See the
|
||||
Author's remarks for more details.
|
||||
|
||||
To compile this alternate version:
|
||||
|
||||
### Alternate build:
|
||||
|
||||
```sh
|
||||
make alt
|
||||
```
|
||||
|
||||
|
||||
### Alternate use:
|
||||
|
||||
Use `prog.alt` as you would `prog` above.
|
||||
|
||||
|
||||
## Judges' remarks:
|
||||
|
||||
When playing Minesweeper, a misclick might ruin a game, so why not leave the
|
||||
routine to the computer? This program automatically uncovers mines according to
|
||||
several rules, and leaves guessing (and applying the most straightforward of the
|
||||
rules -- just for fun, perhaps?) to the user.
|
||||
When playing
|
||||
[Minesweeper](https://en.wikipedia.org/wiki/Minesweeper_(video_game)), a
|
||||
misclick might ruin a game, so why not leave the routine to the computer? This
|
||||
program automatically uncovers mines according to several rules, and leaves
|
||||
guessing (and applying the most straightforward of the rules -- just for fun,
|
||||
perhaps?) to the user.
|
||||
|
||||
Try creating your own input files according to the author's remarks. Did you
|
||||
encounter any problems?
|
||||
@@ -58,10 +67,10 @@ The submission was in violation of the "2053" size rule by one character, likely
|
||||
a late typo. It was easy to fix.
|
||||
|
||||
|
||||
### for macOS:
|
||||
### For macOS:
|
||||
|
||||
We observe that this entry may not work under macOS using iTerm2.
|
||||
Users on macOS might want to run this entry run under the macOS Terminal,
|
||||
Users on macOS might want to run this entry under the macOS Terminal,
|
||||
which is located in `/System/Applications/Utilities/Terminal.app`.
|
||||
|
||||
|
||||
@@ -71,16 +80,17 @@ which is located in `/System/Applications/Utilities/Terminal.app`.
|
||||
|
||||
Minesweeper is a game to sweep mines, as you know. The task consists of two parts:
|
||||
|
||||
A) choose a random cell based on your sixth sense
|
||||
B) identify a non-mine cell based on logical inference
|
||||
0. Choose a random cell based on your sixth sense.
|
||||
1. Identify a non-mine cell based on logical inference.
|
||||
|
||||
However, (B) is error-prone, and a waste of time. You must use a computer to do
|
||||
However, (1) is error-prone, and a waste of time. You must use a computer to do
|
||||
such a boring task!
|
||||
|
||||
This program is a semi-automatic minesweeper which does Part (B) automatically.
|
||||
All you have to do is (A). You can test if you are lucky or not.
|
||||
This program is a semi-automatic minesweeper which does part (1) automatically.
|
||||
All you have to do is (0). You can test if you are lucky or not.
|
||||
|
||||
#### How to use:
|
||||
|
||||
### How to use:
|
||||
|
||||
It uses ncurses:
|
||||
|
||||
@@ -95,16 +105,21 @@ click.
|
||||
If a cell turns out to have a mine (or not), the program determines whether its
|
||||
neighbors have a mine or not, and automatically probes (or flags) the cell.
|
||||
|
||||
##### Keyboard commands:
|
||||
|
||||
* `R`: new game (You can also click the smiley face at the top line.)
|
||||
* `Q`: quit
|
||||
### Keyboard commands:
|
||||
|
||||
#### Internals:
|
||||
* `r`: new game (You can also click the smiley face at the top line.).
|
||||
* `q`: quit.
|
||||
|
||||
Input is case-sensitive.
|
||||
|
||||
|
||||
### Internals:
|
||||
|
||||
The program uses four types of local inference:
|
||||
|
||||
##### Rule 1:
|
||||
|
||||
#### Rule 1:
|
||||
|
||||
If the number of a cell is equal to the count of the flagged neighbors, all the
|
||||
unprobed neighbors are probed.
|
||||
@@ -121,7 +136,8 @@ Note that `?` is an unprobed cell (it is unknown whether the cell has a mine or
|
||||
not); `!` is a flagged cell (it is already known that the cell has a mine); and
|
||||
`.` is a probed cell (it is already known that the cell has no mine).
|
||||
|
||||
##### Rule 2:
|
||||
|
||||
#### Rule 2:
|
||||
|
||||
If the number of a cell is equal to the count of the unprobed or flagged
|
||||
neighbors, all the unprobed neighbors are flagged.
|
||||
@@ -134,11 +150,11 @@ Example:
|
||||
. 2 ! . 2 !
|
||||
```
|
||||
|
||||
##### Rule 3:
|
||||
#### Rule 3:
|
||||
|
||||
Consider two number cells A and B. If A is equal to the difference of B and the
|
||||
count of B's unprobed and flagged neighbors that are not A's neighbors, all A's
|
||||
unprobed neighbors that are not B's neighbors are probed.
|
||||
Consider two number cells `A` and `B`. If `A` is equal to the difference of `B`
|
||||
and the count of `B`'s unprobed and flagged neighbors that are not `A`'s
|
||||
neighbors, all `A`'s unprobed neighbors that are not `B`'s neighbors are probed.
|
||||
|
||||
Example:
|
||||
|
||||
@@ -149,11 +165,18 @@ Example:
|
||||
? . ! ? . !
|
||||
```
|
||||
|
||||
A and B are probed cells whose numbers are, respectively, 1 and 4. The count of B's unprobed and flagged neighbors that are not A's neighbors is three (one `!` and two `?`s). Since A (1) == B (4) - the count (3), the left and top unprobed cells are probed.
|
||||
`A` and `B` are probed cells whose numbers are, respectively, 1 and 4. The
|
||||
count of `B`'s unprobed and flagged neighbors that are not `A`'s neighbors is
|
||||
three (one `!` and two `?`s). Since `A == B - count` (`1 == 4 - 3`), the left
|
||||
and top unprobed cells are probed.
|
||||
|
||||
|
||||
#### Rule 4
|
||||
|
||||
Consider two number cells A and B. If B is equal to the difference of A and the count of A's unprobed and flagged neighbors that are not B's neighbors, all A's unprobed neighbors that are not B's neighbors are flagged.
|
||||
Consider two number cells `A` and `B`. If `B` is equal to the difference of `A`
|
||||
and the count of `A`'s unprobed and flagged neighbors that are not `B`'s
|
||||
neighbors, all of `A`'s unprobed neighbors that are not `B`'s neighbors are
|
||||
flagged.
|
||||
|
||||
```
|
||||
? ? ? ? ! ? ? ?
|
||||
@@ -161,13 +184,19 @@ Consider two number cells A and B. If B is equal to the difference of A and the
|
||||
2 2 . . 2 2 . .
|
||||
```
|
||||
|
||||
A and B are probed cells whose numbers are, respectively, 3 and 1. The count of A's unprobed and flagged neighbors that are not B's neighbors is two (left `?`s). Since B (1) == A (3) - the count (2), the left unprobed cells are flagged.
|
||||
`A` and `B` are probed cells whose numbers are, respectively, 3 and 1. The
|
||||
count of `A`'s unprobed and flagged neighbors that are not `B`'s neighbors is
|
||||
two (left `?`s). Since `B == A - count` (`1 == 3 - 2`), the left unprobed cells
|
||||
are flagged.
|
||||
|
||||
#### Note
|
||||
|
||||
Interestingly, these complex rules can be integrated to one simple rule. Analyze the code.
|
||||
### Note
|
||||
|
||||
#### One more thing
|
||||
Interestingly, these complex rules can be integrated to one simple rule.
|
||||
Analyze the code.
|
||||
|
||||
|
||||
### One more thing
|
||||
|
||||
You can also play with a prepared map.
|
||||
|
||||
@@ -181,17 +210,27 @@ The format of the text is:
|
||||
width height number-of-mines priorities-of-each-cell...
|
||||
```
|
||||
|
||||
There are mines in a cell whose "priorities-of-each-cell" is less than "number-of-mines".
|
||||
(But the mine in the first-clicked cell is removed.)
|
||||
There are mines in a cell whose "priorities-of-each-cell" is less than
|
||||
"number-of-mines". (But the mine in the first-clicked cell is removed.)
|
||||
|
||||
#### Bug fixes and Credits
|
||||
|
||||
The judges pointed out a bug of the original version that I submitted (prog.alt.c). Because this program does not provide a feature to flag unprobed cells manually, we can do nothing if the number of unprobed cells are equal to the number of mines remaining; unwinnable.txt is an example for such a case.
|
||||
Thus, I implemented an additional rule to flag all unprobed cells in such a case into the final version (prog.c).
|
||||
### Bug fixes and Credits
|
||||
|
||||
Ilya Kurdyukov also pointed out a warning "ignoring return value of 'fscanf'" only when "-O3" is used. So I changed the code a little to pretend to use the return value of fscanf.
|
||||
The judges pointed out a bug of the original version that I submitted
|
||||
([prog.alt.c](prog.alt.c)). Because this program does not provide a feature to
|
||||
flag unprobed cells manually, we can do nothing if the number of unprobed cells
|
||||
are equal to the number of mines remaining; [unwinnable.txt](unwinnable.txt) is
|
||||
an example for such a case.
|
||||
|
||||
Don Yang (omoikane) contributed another example map "megumin.txt" which is the Explosion Arch-Wizard.
|
||||
Thus, I implemented an additional rule to flag all unprobed cells in such a case
|
||||
into the final version ([prog.c](prog.c)).
|
||||
|
||||
[Ilya Kurdyukov](/winners.html#Ilya_Kurdyukov) also pointed out a warning
|
||||
"ignoring return value of 'fscanf'" only when `-O3` is used. So I changed the
|
||||
code a little to pretend to use the return value of `fscanf(3)`.
|
||||
|
||||
[Don Yang](/winners.html#Don_Yang) (omoikane) contributed another example map
|
||||
[megumin.txt](megumin.txt) which is the Explosion Arch-Wizard from KonoSuba.
|
||||
|
||||
|
||||
## Copyright and CC BY-SA 4.0 License:
|
||||
|
||||
@@ -15,15 +15,17 @@ make
|
||||
### Try:
|
||||
|
||||
```sh
|
||||
./prog
|
||||
|
||||
./prog hello.txt
|
||||
|
||||
./prog yoda.txt
|
||||
|
||||
./prog bear.txt
|
||||
./try.sh
|
||||
```
|
||||
|
||||
What happens if you do
|
||||
|
||||
```sh
|
||||
./prog prog.c
|
||||
```
|
||||
|
||||
?
|
||||
|
||||
|
||||
## Judges' remarks:
|
||||
|
||||
|
||||
Executable
+48
@@ -0,0 +1,48 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# try.sh - demonstrate IOCCC winner 2020/endoh2
|
||||
#
|
||||
|
||||
# make sure CC is set so that when we do make CC="$CC" it isn't empty. Doing it
|
||||
# this way allows us to have the user specify a different compiler in an easy
|
||||
# way.
|
||||
if [[ -z "$CC" ]]; then
|
||||
CC="cc"
|
||||
fi
|
||||
|
||||
make CC="$CC" all >/dev/null || exit 1
|
||||
|
||||
# clear screen after compilation so that only the entry is shown
|
||||
clear
|
||||
|
||||
read -r -n 1 -p "Press any key to run: ./prog: "
|
||||
echo 1>&2
|
||||
./prog
|
||||
echo 1>&2
|
||||
|
||||
read -r -n 1 -p "Press any key to show hello.txt: "
|
||||
echo 1>&2
|
||||
cat hello.txt
|
||||
echo 1>&2
|
||||
|
||||
read -r -n 1 -p "Press any key to run: ./prog hello.txt: "
|
||||
echo 1>&2
|
||||
./prog hello.txt
|
||||
echo 1>&2
|
||||
|
||||
read -r -n 1 -p "Press any key to show yoda.txt: "
|
||||
echo 1>&2
|
||||
cat yoda.txt
|
||||
echo 1>&2
|
||||
|
||||
read -r -n 1 -p "Press any key to run: ./prog yoda.txt: "
|
||||
echo 1>&2
|
||||
./prog yoda.txt
|
||||
|
||||
read -r -n 1 -p "Press any key to show bear.txt: "
|
||||
echo 1>&2
|
||||
cat bear.txt
|
||||
read -r -n 1 -p "Press any key to run: ./prog bear.txt: "
|
||||
echo 1>&2
|
||||
./prog bear.txt
|
||||
|
||||
+15
-5
@@ -4,6 +4,9 @@
|
||||
make
|
||||
```
|
||||
|
||||
An alternate version of this program exists. See [Alternate
|
||||
code](#alternate-code) below.
|
||||
|
||||
|
||||
## To use:
|
||||
|
||||
@@ -22,23 +25,30 @@ make
|
||||
|
||||
## Alternate code:
|
||||
|
||||
An alternate version of this entry, `prog.alt.c`, is provided. This alternate code uses Unicode letters.
|
||||
An alternate version of this entry, [prog.alt.c](prog.alt.c), is provided. This
|
||||
alternate code uses Unicode letters.
|
||||
|
||||
To compile this alternate version:
|
||||
|
||||
### Alternate build:
|
||||
|
||||
```sh
|
||||
make alt
|
||||
```
|
||||
|
||||
|
||||
### Alternate use:
|
||||
|
||||
Use `prog.alt` as you would `prog` above.
|
||||
|
||||
|
||||
## Judges' remarks:
|
||||
|
||||
You may be tempted to use a mirror. Resist the temptation! Try figuring out how the clock hands are drawn.
|
||||
Can you change the program to make it draw a familiar (non-mirrored) clock face? Can you add the second hand?
|
||||
You may be tempted to use a mirror. Resist the temptation! Try figuring out how
|
||||
the clock hands are drawn. Can you change the program to make it draw a
|
||||
familiar (non-mirrored) clock face? Can you add the second hand?
|
||||
|
||||
When using the `run_clock` shell script, your perception of time might depend on what time it is.
|
||||
When using the [run_clock.sh](run_clock.sh) shell script, your perception of
|
||||
time might depend on what time it is.
|
||||
|
||||
|
||||
## Author's remarks:
|
||||
|
||||
+50
-33
@@ -5,8 +5,8 @@ make
|
||||
```
|
||||
|
||||
|
||||
There is an [alternate version](#alternate-code) which has controls that will
|
||||
make much more sense to those familiar with vi.
|
||||
There is an alternate version which has controls that will make much more sense
|
||||
to those familiar with vi. See [Alternate code](#alternate-code) below.
|
||||
|
||||
|
||||
## To use:
|
||||
@@ -59,15 +59,13 @@ reverse indentation style.
|
||||
|
||||
## Author's remarks:
|
||||
|
||||
#### Controls
|
||||
- Movement:\
|
||||
`w` (forwards), `a` (left), `s` (backwards), `d` (right)
|
||||
- Fire:\
|
||||
`space`
|
||||
- Quit:\
|
||||
`q`
|
||||
- Pause:\
|
||||
`p`, then use any other key to resume
|
||||
### Controls
|
||||
|
||||
- Movement: `w` (forwards), `a` (left), `s` (backwards), `d` (right)
|
||||
- Fire: space
|
||||
- Quit: `q`
|
||||
- Pause: `p`, then use any other key to resume
|
||||
|
||||
|
||||
```
|
||||
/\
|
||||
@@ -78,20 +76,26 @@ reverse indentation style.
|
||||
```
|
||||
|
||||
|
||||
#### Compile and run
|
||||
###### Linux
|
||||
### Compile and run
|
||||
|
||||
#### Linux
|
||||
```
|
||||
cc -std=c99 -O3 prog.c -o prog
|
||||
./prog
|
||||
```
|
||||
|
||||
###### Windows
|
||||
The only way I found to make it work is to use [MSYS2](https://www.msys2.org). When using the MSYS2 shell you can install gcc via pacman.
|
||||
#### Windows
|
||||
|
||||
The only way I found to make it work is to use [MSYS2](https://www.msys2.org).
|
||||
When using the MSYS2 shell you can install gcc via pacman.
|
||||
|
||||
```
|
||||
cc -std=c99 -O3 prog.c -o prog
|
||||
./prog.exe
|
||||
```
|
||||
|
||||
#### Warnings
|
||||
|
||||
- `-Wno-missing-prototypes`
|
||||
- `-Wno-shorten-64-to-32`
|
||||
- `-Wno-sign-conversion`
|
||||
@@ -106,24 +110,37 @@ cc -std=c99 -O3 prog.c -o prog
|
||||
- `-Wno-empty-body`
|
||||
- `-Wno-misleading-indentation`
|
||||
- `-Wno-maybe-uninitialized`
|
||||
- You may experience a mild [motion aftereffect](https://en.wikipedia.org/wiki/Motion_aftereffect) when playing for too long
|
||||
#### High score
|
||||
Score will be shown in the top left corner.\
|
||||
My best was **156**. If you beat that I'll send you the image of a very expensive chocolate.
|
||||
#### Features
|
||||
- Procedural star generation
|
||||
- Very space-efficient for-loops
|
||||
- No use of `!=` or `==`
|
||||
- Smooth rendering even on slow terminals
|
||||
- Advanced ascii-art
|
||||
- Cutting edge physics engine and collision detection
|
||||
- Probably not many segfaults
|
||||
- Every letter in the English alphabet has a variable or function named after it
|
||||
- Not a virus
|
||||
- Runs on my machine
|
||||
#### Tips
|
||||
- Adjust your terminal size for different experiences
|
||||
- Run this program in a virtual console to immerse yourself in the game
|
||||
- You may experience a mild [motion
|
||||
aftereffect](https://en.wikipedia.org/wiki/Motion_aftereffect) when playing for
|
||||
too long.
|
||||
|
||||
|
||||
### High score
|
||||
|
||||
Score will be shown in the top left corner.
|
||||
My best was **156**. If you beat that I'll send you the image of a very
|
||||
expensive chocolate.
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
- Procedural star generation.
|
||||
- Very space-efficient `for` loops.
|
||||
- No use of `!=` or `==`.
|
||||
- Smooth rendering even on slow terminals.
|
||||
- Advanced ASCII art.
|
||||
- Cutting edge physics engine and collision detection.
|
||||
- Probably not many segfaults.
|
||||
- Every letter in the English alphabet has a variable or function named after
|
||||
it.
|
||||
- Not a virus.
|
||||
- Runs on my machine.
|
||||
|
||||
|
||||
### Tips
|
||||
|
||||
- Adjust your terminal size for different experiences.
|
||||
- Run this program in a virtual console to immerse yourself in the game.
|
||||
|
||||
|
||||
## Copyright and CC BY-SA 4.0 License:
|
||||
|
||||
+13
-9
@@ -4306,8 +4306,11 @@ a friend, whether that's real or imagined.
|
||||
|
||||
## <a name="2020_endoh2"></a>[2020/endoh2](/2020/endoh2/prog.c) ([README.md](/2020/endoh2/README.md))
|
||||
|
||||
[Cody](#cody) copied the files from the spoiler.zip file that was password protected with
|
||||
a password that was no longer known from his preview of 2020.
|
||||
[Cody](#cody) copied the files from the spoiler.zip file (from his copy during
|
||||
the preview period) that was password protected with a password that was no
|
||||
longer known.
|
||||
|
||||
He also added the [try.sh](/2020/endoh2/try.sh) script.
|
||||
|
||||
|
||||
## <a name="2020_endoh3"></a>[2020/endoh3](/2020/endoh3/prog.c) ([README.md](/2020/endoh3/README.md))
|
||||
@@ -4334,13 +4337,14 @@ quick.
|
||||
|
||||
Cody also reported (during the preview period of 2020) for some systems (at some
|
||||
point?) like macOS the use of `make clock` would not work due possibly to a
|
||||
timing issue so [Yusuke](#yusuke) changed it to compile the [clock.c](/2020/endoh3/clock.c)
|
||||
file directly (this might have been fixed in the Makefile later on but it
|
||||
doesn't hurt to keep it in and this way it isn't a problem in any system). How
|
||||
Cody remembers this minor detail more than three years ago is something that
|
||||
many people might wonder but he also once told us that if someone moves
|
||||
something of his even a millimetre from where it was he knows it so he might be
|
||||
called unusual (and he argues, with pride, eccentric :-) ) :-)
|
||||
timing issue so [Yusuke](#yusuke) changed it to compile the
|
||||
[clock.c](/2020/endoh3/clock.c) file directly (this might have been fixed in the
|
||||
Makefile later on but it doesn't hurt to keep it in and this way it isn't a
|
||||
problem in any system). How Cody remembers this minor detail more than three
|
||||
years ago is something that many people might wonder but he also once told us
|
||||
that if someone moves something of his even a millimetre from where it was he
|
||||
knows it so he might be called unusual (and he argues, with pride, eccentric :-)
|
||||
) :-)
|
||||
|
||||
|
||||
## <a name="2020_ferguson2"></a>[2020/ferguson2](/2020/ferguson1/prog.c) ([README.md](/2020/ferguson1/README.md))
|
||||
|
||||
Reference in new issue
Block a user