Merge pull request #1772 from xexyl/tsoj2020

This commit is contained in:
Landon Curt Noll authored and GitHub committed 2023-12-22 00:22:15 -08:00
commit a36014096c
7 files changed
+215 -90

No files matched your search

+5
View File
@@ -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: ## Judges' remarks:
Do you need to pretend enjoying a more spacious living environment than you Do you need to pretend enjoying a more spacious living environment than you
+75 -36
View File
@@ -4,6 +4,9 @@
make make
``` ```
There is an alternate version provided by the author. See [Alternate
code](#alternate-code) below.
## To use: ## 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 alternate code lacks the additional rule to flag all unprobed cells. See the
Author's remarks for more details. Author's remarks for more details.
To compile this alternate version:
### Alternate build:
```sh ```sh
make alt make alt
``` ```
### Alternate use:
Use `prog.alt` as you would `prog` above. Use `prog.alt` as you would `prog` above.
## Judges' remarks: ## Judges' remarks:
When playing Minesweeper, a misclick might ruin a game, so why not leave the When playing
routine to the computer? This program automatically uncovers mines according to [Minesweeper](https://en.wikipedia.org/wiki/Minesweeper_(video_game)), a
several rules, and leaves guessing (and applying the most straightforward of the misclick might ruin a game, so why not leave the routine to the computer? This
rules -- just for fun, perhaps?) to the user. 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 Try creating your own input files according to the author's remarks. Did you
encounter any problems? 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. a late typo. It was easy to fix.
### for macOS: ### For macOS:
We observe that this entry may not work under macOS using iTerm2. 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`. 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: 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 0. Choose a random cell based on your sixth sense.
B) identify a non-mine cell based on logical inference 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! such a boring task!
This program is a semi-automatic minesweeper which does Part (B) automatically. This program is a semi-automatic minesweeper which does part (1) automatically.
All you have to do is (A). You can test if you are lucky or not. 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: It uses ncurses:
@@ -95,16 +105,21 @@ click.
If a cell turns out to have a mine (or not), the program determines whether its 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. 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.) ### Keyboard commands:
* `Q`: quit
#### 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: 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 If the number of a cell is equal to the count of the flagged neighbors, all the
unprobed neighbors are probed. 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 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). `.` 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 If the number of a cell is equal to the count of the unprobed or flagged
neighbors, all the unprobed neighbors are flagged. neighbors, all the unprobed neighbors are flagged.
@@ -134,11 +150,11 @@ Example:
. 2 ! . 2 ! . 2 ! . 2 !
``` ```
##### Rule 3: #### Rule 3:
Consider two number cells A and B. If A is equal to the difference of B and the Consider two number cells `A` and `B`. If `A` is equal to the difference of `B`
count of B's unprobed and flagged neighbors that are not A's neighbors, all A's and the count of `B`'s unprobed and flagged neighbors that are not `A`'s
unprobed neighbors that are not B's neighbors are probed. neighbors, all `A`'s unprobed neighbors that are not `B`'s neighbors are probed.
Example: 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 #### 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 . . 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. 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... 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". There are mines in a cell whose "priorities-of-each-cell" is less than
(But the mine in the first-clicked cell is removed.) "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. ### Bug fixes and Credits
Thus, I implemented an additional rule to flag all unprobed cells in such a case into the final version (prog.c).
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: ## Copyright and CC BY-SA 4.0 License:
+9 -7
View File
@@ -15,15 +15,17 @@ make
### Try: ### Try:
```sh ```sh
./prog ./try.sh
./prog hello.txt
./prog yoda.txt
./prog bear.txt
``` ```
What happens if you do
```sh
./prog prog.c
```
?
## Judges' remarks: ## Judges' remarks:
+48
View File
@@ -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
View File
@@ -4,6 +4,9 @@
make make
``` ```
An alternate version of this program exists. See [Alternate
code](#alternate-code) below.
## To use: ## To use:
@@ -22,23 +25,30 @@ make
## Alternate code: ## 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 ```sh
make alt make alt
``` ```
### Alternate use:
Use `prog.alt` as you would `prog` above. Use `prog.alt` as you would `prog` above.
## Judges' remarks: ## Judges' remarks:
You may be tempted to use a mirror. Resist the temptation! Try figuring out how the clock hands are drawn. You may be tempted to use a mirror. Resist the temptation! Try figuring out how
Can you change the program to make it draw a familiar (non-mirrored) clock face? Can you add the second hand? 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: ## Author's remarks:
+50 -33
View File
@@ -5,8 +5,8 @@ make
``` ```
There is an [alternate version](#alternate-code) which has controls that will There is an alternate version which has controls that will make much more sense
make much more sense to those familiar with vi. to those familiar with vi. See [Alternate code](#alternate-code) below.
## To use: ## To use:
@@ -59,15 +59,13 @@ reverse indentation style.
## Author's remarks: ## Author's remarks:
#### Controls ### Controls
- Movement:\
`w` (forwards), `a` (left), `s` (backwards), `d` (right) - Movement: `w` (forwards), `a` (left), `s` (backwards), `d` (right)
- Fire:\ - Fire: space
`space` - Quit: `q`
- Quit:\ - Pause: `p`, then use any other key to resume
`q`
- Pause:\
`p`, then use any other key to resume
``` ```
/\ /\
@@ -78,20 +76,26 @@ reverse indentation style.
``` ```
#### Compile and run ### Compile and run
###### Linux
#### Linux
``` ```
cc -std=c99 -O3 prog.c -o prog cc -std=c99 -O3 prog.c -o prog
./prog ./prog
``` ```
###### Windows #### 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.
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 cc -std=c99 -O3 prog.c -o prog
./prog.exe ./prog.exe
``` ```
#### Warnings #### Warnings
- `-Wno-missing-prototypes` - `-Wno-missing-prototypes`
- `-Wno-shorten-64-to-32` - `-Wno-shorten-64-to-32`
- `-Wno-sign-conversion` - `-Wno-sign-conversion`
@@ -106,24 +110,37 @@ cc -std=c99 -O3 prog.c -o prog
- `-Wno-empty-body` - `-Wno-empty-body`
- `-Wno-misleading-indentation` - `-Wno-misleading-indentation`
- `-Wno-maybe-uninitialized` - `-Wno-maybe-uninitialized`
- You may experience a mild [motion aftereffect](https://en.wikipedia.org/wiki/Motion_aftereffect) when playing for too long - You may experience a mild [motion
#### High score aftereffect](https://en.wikipedia.org/wiki/Motion_aftereffect) when playing for
Score will be shown in the top left corner.\ too long.
My best was **156**. If you beat that I'll send you the image of a very expensive chocolate.
#### Features
- Procedural star generation ### High score
- Very space-efficient for-loops
- No use of `!=` or `==` Score will be shown in the top left corner.
- Smooth rendering even on slow terminals My best was **156**. If you beat that I'll send you the image of a very
- Advanced ascii-art expensive chocolate.
- 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 ### Features
- Not a virus
- Runs on my machine - Procedural star generation.
#### Tips - Very space-efficient `for` loops.
- Adjust your terminal size for different experiences - No use of `!=` or `==`.
- Run this program in a virtual console to immerse yourself in the game - 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: ## Copyright and CC BY-SA 4.0 License:
+13 -9
View File
@@ -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)) ## <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 [Cody](#cody) copied the files from the spoiler.zip file (from his copy during
a password that was no longer known from his preview of 2020. 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)) ## <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 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 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) timing issue so [Yusuke](#yusuke) changed it to compile the
file directly (this might have been fixed in the Makefile later on but it [clock.c](/2020/endoh3/clock.c) file directly (this might have been fixed in the
doesn't hurt to keep it in and this way it isn't a problem in any system). How Makefile later on but it doesn't hurt to keep it in and this way it isn't a
Cody remembers this minor detail more than three years ago is something that problem in any system). How Cody remembers this minor detail more than three
many people might wonder but he also once told us that if someone moves years ago is something that many people might wonder but he also once told us
something of his even a millimetre from where it was he knows it so he might be that if someone moves something of his even a millimetre from where it was he
called unusual (and he argues, with pride, eccentric :-) ) :-) 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)) ## <a name="2020_ferguson2"></a>[2020/ferguson2](/2020/ferguson1/prog.c) ([README.md](/2020/ferguson1/README.md))