diff --git a/1994/shapiro/shapiro.html b/1994/shapiro/shapiro.html index 4e44f3a0e..5ed258a58 100644 --- a/1994/shapiro/shapiro.html +++ b/1994/shapiro/shapiro.html @@ -135,7 +135,7 @@

HINTS

-

For the first program (shapiro.c):

+

For the first program (shapiro.c):

This is a very simple program:

     1. #include <stdio.h>
      2. main()
diff --git a/1994/shapiro/shapiro.md b/1994/shapiro/shapiro.md
index f5c86fe14..f61299e81 100644
--- a/1994/shapiro/shapiro.md
+++ b/1994/shapiro/shapiro.md
@@ -1,6 +1,6 @@
 # HINTS
 
-For the first program ([shapiro.c](shapiro.c)):
+For the first program ([shapiro.c](%%REPO_URL%%/1994/shapiro/shapiro.c)):
 
 
 This is a very simple program:
diff --git a/1998/schweikh1/macos.html b/1998/schweikh1/macos.html
index 1fbc68d11..4a471af5c 100644
--- a/1998/schweikh1/macos.html
+++ b/1998/schweikh1/macos.html
@@ -155,7 +155,7 @@ command line tools installed which can be done like:

the entry, the alternate version has also removed this limitation despite gcc existing (though it’s clang) in macOS.

Now as far as how this works if you look at the code of -schweikh1.c, on line 55 you’ll see a funny command (this goes for +schweikh1.c, on line 55 you’ll see a funny command (this goes for the alternate version as well but a bit different).

Now the key is two magic numbers, one (two times) on a different line shortly below the string and the other a couple lines further below.

diff --git a/1998/schweikh1/macos.md b/1998/schweikh1/macos.md index e4826e83b..966316e79 100644 --- a/1998/schweikh1/macos.md +++ b/1998/schweikh1/macos.md @@ -28,7 +28,7 @@ the entry, the alternate version has also removed this limitation despite `gcc` existing (though it's `clang`) in macOS. Now as far as how this works if you look at the code of -[schweikh1.c](schweikh1.c), on line 55 you'll see a funny command (this goes for +[schweikh1.c](%%REPO_URL%%/1998/schweikh1/schweikh1.c), on line 55 you'll see a funny command (this goes for the alternate version as well but a bit different). Now the key is two magic numbers, one (two times) on a different line shortly below the diff --git a/2004/gavin/gavin.html b/2004/gavin/gavin.html index 329fafd45..3073c5edc 100644 --- a/2004/gavin/gavin.html +++ b/2004/gavin/gavin.html @@ -138,7 +138,7 @@
  1. First, build the kernel and filesystem (just make). In short, you need to build this on an x86 Linux machine. If you wish to try to compile on an OS -other than Linux you may need modify the Makefile to compile sh +other than Linux you may need modify the Makefile to compile sh using a cross-compiler that produces ELF binaries - i.e. a cross-compiler targeting x86 Linux. In short, you need to build this on an x86 Linux machine.

  2. Next, find a suitable machine to run the OS on. It should be perfectly safe, diff --git a/2004/gavin/gavin.md b/2004/gavin/gavin.md index 8c8427b01..f91c9ee1c 100644 --- a/2004/gavin/gavin.md +++ b/2004/gavin/gavin.md @@ -2,7 +2,7 @@ 1. First, build the kernel and filesystem (just `make`). In short, you need to build this on an x86 Linux machine. If you wish to try to compile on an OS -other than Linux you may need modify the [Makefile](Makefile) to compile `sh` +other than Linux you may need modify the [Makefile](%%REPO_URL%%/2004/gavin/Makefile) to compile `sh` using a cross-compiler that produces ELF binaries - i.e. a cross-compiler targeting x86 Linux. In short, you need to build this on an x86 Linux machine. diff --git a/2012/deckmyn/deckmyn.html b/2012/deckmyn/deckmyn.html index b371c6bf9..8433dad5d 100644 --- a/2012/deckmyn/deckmyn.html +++ b/2012/deckmyn/deckmyn.html @@ -142,7 +142,7 @@ the font description embedded in the source code. Notice that you don’t pass the file name, but the actual content as one long character string! If you want to define your personal music font, you can of course do so. The file layout must -be exactly the same as deckmyn.c though, only the locations of +be exactly the same as deckmyn.c though, only the locations of space (" ") may differ.

    The second argument is the actual music. Again it is one long string, not a file name. But it is possible to save your music in a file, of course.

    diff --git a/2012/deckmyn/deckmyn.md b/2012/deckmyn/deckmyn.md index e8374dea2..9f4d0c4c6 100644 --- a/2012/deckmyn/deckmyn.md +++ b/2012/deckmyn/deckmyn.md @@ -13,7 +13,7 @@ This minimalistic music notator expects two command line arguments. The first is the font description embedded in the source code. Notice that you don't pass the file name, but the actual content as one long character string! If you want to define your personal music font, you can of course do so. The file layout must -be exactly the same as [deckmyn.c](deckmyn.c) though, only the locations of +be exactly the same as [deckmyn.c](%%REPO_URL%%/2012/deckmyn/deckmyn.c) though, only the locations of space (`" "`) may differ. The second argument is the actual music. Again it is one long string, not a file diff --git a/2013/hou/doc/example.html b/2013/hou/doc/example.html index 709d5e954..fd27dda5b 100644 --- a/2013/hou/doc/example.html +++ b/2013/hou/doc/example.html @@ -261,7 +261,7 @@ indirect source.

    of up to 32 volumes, each with 64x64x64 cells. The volume 0 is the ‘top level’ volume where the camera goes. Each cell of a volume can be empty, filled with a material, or another volume. The roundish characters in -old_default.scene and the carpet on the floor in this +old_default.scene and the carpet on the floor in this file are examples where a cell is defined to another volume. Materials will be explained later.

    The volume shader for the i-th volume is named as the (i+1)-th capital letter. diff --git a/2013/hou/doc/example.md b/2013/hou/doc/example.md index ee62e4d47..e5f6ff270 100644 --- a/2013/hou/doc/example.md +++ b/2013/hou/doc/example.md @@ -179,7 +179,7 @@ indirect source. of up to 32 volumes, each with 64x64x64 cells. The volume 0 is the 'top level' volume where the camera goes. Each cell of a volume can be empty, filled with a material, or another volume. The roundish characters in -[old_default.scene](../old_default.scene) and the carpet on the floor in this +[old_default.scene](%%REPO_URL%%/2013/hou/old_default.scene) and the carpet on the floor in this file are examples where a cell is defined to another volume. Materials will be explained later. diff --git a/2014/endoh1/spoilers.html b/2014/endoh1/spoilers.html index b857a3ef7..8ad5e12b1 100644 --- a/2014/endoh1/spoilers.html +++ b/2014/endoh1/spoilers.html @@ -187,8 +187,8 @@ instruction set is carefully selected to minimize the sizes of both <ma

  3. The instructions have variable lengths, but many of them are represented as one -printable character. (See machine.rb and -assemble.rb in detail.) The mapping between instructions and +printable character. (See machine.rb and +assemble.rb in detail.) The mapping between instructions and characters is also carefully designed to minimize <VM code>, which makes the resulted program non-human-readable.

    How did I create the main code?

    @@ -196,8 +196,8 @@ resulted program non-human-readable.

    code in Ruby syntax and created a Ruby-to-VM compiler that involves alpha renaming and automatic register allocation only for this purpose.

      -
    • src.rb: the source code of QR code encoder written in Ruby syntax.
    • -
    • vm.c: the source code of the VM.
    • +
    • src.rb: the source code of QR code encoder written in Ruby syntax.
    • +
    • vm.c: the source code of the VM.

    The compiler tool chain is the following.

        src.rb              interp.c
    @@ -232,14 +232,14 @@ renaming and automatic register allocation only for this purpose.

    V prog.c
      -
    • parse.rb converts Ruby to AST.
    • -
    • serialize.rb converts AST to intermediate instruction sequence.
    • -
    • alpha.rb applies “alpha-renaming” to the instruction sequence.
    • -
    • register.rb applies “register allocation”.
    • -
    • assemble.rb converts the sequence to the final stack-machine instructions.
    • -
    • interp.c is an implementation of the VM.
    • -
    • link.rb generates main.c by linking the instructions and interpreter source.
    • -
    • gen-prog.c generates prog.c based on main.c.
    • +
    • parse.rb converts Ruby to AST.
    • +
    • serialize.rb converts AST to intermediate instruction sequence.
    • +
    • alpha.rb applies “alpha-renaming” to the instruction sequence.
    • +
    • register.rb applies “register allocation”.
    • +
    • assemble.rb converts the sequence to the final stack-machine instructions.
    • +
    • interp.c is an implementation of the VM.
    • +
    • link.rb generates main.c by linking the instructions and interpreter source.
    • +
    • gen-prog.c generates prog.c based on main.c.

    You can run the process by rake command. ruby-minisat gem is needed.

        $ gem install ruby-minisat
    @@ -254,7 +254,7 @@ renaming and automatic register allocation only for this purpose.

    found at https://play.google.com/store/apps/details?id=com.google.zxing.client.android but it appears to no longer exist.

    -

    You can use tool.rb to convert the output to a png file.

    +

    You can use tool.rb to convert the output to a png file.

        ./main Hello | ruby tool.rb > hello.png
     
         $ zbarimg -q hello.png
    diff --git a/2014/endoh1/spoilers.md b/2014/endoh1/spoilers.md
    index 164d34f7b..4fdc5d91f 100644
    --- a/2014/endoh1/spoilers.md
    +++ b/2014/endoh1/spoilers.md
    @@ -60,8 +60,8 @@ code>` and ``.
       * putchar, exit
     
     The instructions have variable lengths, but many of them are represented as one
    -printable character.  (See [machine.rb](machine.rb) and
    -[assemble.rb](assemble.rb) in detail.) The mapping between instructions and
    +printable character.  (See [machine.rb](%%REPO_URL%%/2014/endoh1/machine.rb) and
    +[assemble.rb](%%REPO_URL%%/2014/endoh1/assemble.rb) in detail.) The mapping between instructions and
     characters is also carefully designed to minimize ``, which makes the
     resulted program non-human-readable.
     
    @@ -72,8 +72,8 @@ It is too tedious to write the machine language directly.  So I wrote the source
     code in Ruby syntax and created a Ruby-to-VM compiler that involves alpha
     renaming and automatic register allocation only for this purpose.
     
    -* [src.rb](src.rb): the source code of QR code encoder written in Ruby syntax.
    -* [vm.c](vm.c): the source code of the VM.
    +* [src.rb](%%REPO_URL%%/2014/endoh1/src.rb): the source code of QR code encoder written in Ruby syntax.
    +* [vm.c](%%REPO_URL%%/2014/endoh1/vm.c): the source code of the VM.
     
     The compiler tool chain is the following.
     
    @@ -111,14 +111,14 @@ The compiler tool chain is the following.
     	      prog.c
     ```
     
    -* [parse.rb](parse.rb) converts Ruby to AST.
    -* [serialize.rb](serialize.rb) converts AST to intermediate instruction sequence.
    -* [alpha.rb](alpha.rb) applies "alpha-renaming" to the instruction sequence.
    -* [register.rb](register.rb) applies "register allocation".
    -* [assemble.rb](assemble.rb) converts the sequence to the final stack-machine instructions.
    -* [interp.c](interp.c) is an implementation of the VM.
    -* [link.rb](link.rb) generates `main.c` by linking the instructions and interpreter source.
    -* [gen-prog.c](gen-prog.c) generates [prog.c](prog.c) based on `main.c`.
    +* [parse.rb](%%REPO_URL%%/2014/endoh1/parse.rb) converts Ruby to AST.
    +* [serialize.rb](%%REPO_URL%%/2014/endoh1/serialize.rb) converts AST to intermediate instruction sequence.
    +* [alpha.rb](%%REPO_URL%%/2014/endoh1/alpha.rb) applies "alpha-renaming" to the instruction sequence.
    +* [register.rb](%%REPO_URL%%/2014/endoh1/register.rb) applies "register allocation".
    +* [assemble.rb](%%REPO_URL%%/2014/endoh1/assemble.rb) converts the sequence to the final stack-machine instructions.
    +* [interp.c](%%REPO_URL%%/2014/endoh1/interp.c) is an implementation of the VM.
    +* [link.rb](%%REPO_URL%%/2014/endoh1/link.rb) generates `main.c` by linking the instructions and interpreter source.
    +* [gen-prog.c](%%REPO_URL%%/2014/endoh1/gen-prog.c) generates [prog.c](%%REPO_URL%%/2014/endoh1/prog.c) based on `main.c`.
     
     You can run the process by `rake` command.  `ruby-minisat` gem is needed.
     
    @@ -143,7 +143,7 @@ but it appears to no longer exist.
     
     [1]: http://zbar.sourceforge.net/
     
    -You can use [tool.rb](tool.rb) to convert the output to a png file.
    +You can use [tool.rb](%%REPO_URL%%/2014/endoh1/tool.rb) to convert the output to a png file.
     
     ``` 
         ./main Hello | ruby tool.rb > hello.png
    diff --git a/2015/burton/road.to.obscurity.html b/2015/burton/road.to.obscurity.html
    index 37b3420b6..5cbfdc2b3 100644
    --- a/2015/burton/road.to.obscurity.html
    +++ b/2015/burton/road.to.obscurity.html
    @@ -254,17 +254,17 @@ Obscurity now increased!

    Around this time, the formatted code no longer fit with the 2053 limit (due to a lack of comprehension of the significance of the space-after-brace-and-semi rule, and a layout program that did not know how to do this). Frustrated, I -wrote another program to reformat this code into rule2.c, which was a +wrote another program to reformat this code into rule2.c, which was a single C token per line. This solved the formatting problem, but intriguingly introduced another. Now I was faced with the 4096 rule as well as the 2053 rule. But this was a challenge!

    I wrote a de-obfuscator, and worked on both the unobfuscated version and the master code. I worked on the template formatter to make this as automated as possible, and worked to achieve both a perfectly presented picture AND the -single-line exactly-at-4096 rule2.c.

    +single-line exactly-at-4096 rule2.c.

    Finally, “perfection”, with assignable memories! Where perfection is defined as a nicely formatted picture at less than 2053, and exactly 4096 -token-per-line rule2.c.

    +token-per-line rule2.c.

    Testing Testing Testing

    Cross platform, it works on Mac OSX, fails on Linux. It works if #include <stdlib.h>, but it dumps core without it (the only change!)?. 64-bits without proper declaration of ints in syscalls yields unpredictable results. 32-bit @@ -298,7 +298,7 @@ unobfuscated version; think: a complex chain of ternary expressions is a single statement). This involved careful examination of all the expressions within the logic, trying to find a different way of getting the same result, but typically within fewer bytes than before to allow for the added logic to fix the bugs.

    -

    The bugs were fixed, the code re-formatted, and rule2.c was again +

    The bugs were fixed, the code re-formatted, and rule2.c was again 4096 bytes.

    But wouldn’t it be nice for unary plus to work?

    Add unary plus, re-balance. Little things now take a fair bit of work. Adding @@ -327,7 +327,7 @@ relatively tight. But changing around the stable initialization code – by now the largest piece of logic – yielded the necessary bytes, and improved obscurity by double duty encoding of the operations initialization.

    The utility is now truly functional, and feature complete, and obscure. Without -src.doc.txt (basic documentation of the code structure), and some +src.doc.txt (basic documentation of the code structure), and some commented expanded logic stashed away, and the familiarity I have with the code having written and revised it repeatedly, I would not even want to attempt to decipher the logic. Many times in the debugging, I was thwarted by my own diff --git a/2015/burton/road.to.obscurity.md b/2015/burton/road.to.obscurity.md index 65026f49f..868e62184 100644 --- a/2015/burton/road.to.obscurity.md +++ b/2015/burton/road.to.obscurity.md @@ -146,7 +146,7 @@ But wouldn't it be nice to have assignable memories? Around this time, the formatted code no longer fit with the 2053 limit (due to a lack of comprehension of the significance of the space-after-brace-and-semi rule, and a layout program that did not know how to do this). Frustrated, I -wrote another program to reformat this code into [rule2.c](rule2.c), which was a +wrote another program to reformat this code into [rule2.c](%%REPO_URL%%/2015/burton/rule2.c), which was a single C token per line. This solved the formatting problem, but intriguingly introduced another. Now I was faced with the 4096 rule as well as the 2053 rule. But this was a challenge! @@ -154,11 +154,11 @@ rule. But this was a challenge! I wrote a de-obfuscator, and worked on both the unobfuscated version and the master code. I worked on the template formatter to make this as automated as possible, and worked to achieve both a perfectly presented picture AND the -single-line exactly-at-4096 [rule2.c](rule2.c). +single-line exactly-at-4096 [rule2.c](%%REPO_URL%%/2015/burton/rule2.c). Finally, "perfection", with assignable memories! Where perfection is defined as a nicely formatted picture at less than 2053, and exactly 4096 -token-per-line [rule2.c](rule2.c). +token-per-line [rule2.c](%%REPO_URL%%/2015/burton/rule2.c). ## Testing Testing Testing @@ -202,7 +202,7 @@ statement). This involved careful examination of all the expressions within the logic, trying to find a different way of getting the same result, but typically within fewer bytes than before to allow for the added logic to fix the bugs. -The bugs were fixed, the code re-formatted, and [rule2.c](rule2.c) was again +The bugs were fixed, the code re-formatted, and [rule2.c](%%REPO_URL%%/2015/burton/rule2.c) was again 4096 bytes. But wouldn't it be nice for unary plus to work? @@ -243,7 +243,7 @@ the largest piece of logic -- yielded the necessary bytes, and improved obscurity by double duty encoding of the operations initialization. The utility is now truly functional, and feature complete, and obscure. Without -[src.doc.txt](src.doc.txt) (basic documentation of the code structure), and some +[src.doc.txt](%%REPO_URL%%/2015/burton/src.doc.txt) (basic documentation of the code structure), and some commented expanded logic stashed away, and the familiarity I have with the code having written and revised it repeatedly, I would not even want to attempt to decipher the logic. Many times in the debugging, I was thwarted by my own diff --git a/2015/burton/spoilers.html b/2015/burton/spoilers.html index 88451b2e4..de2bc2614 100644 --- a/2015/burton/spoilers.html +++ b/2015/burton/spoilers.html @@ -138,7 +138,7 @@

    calc is a recursive-descent parser. It allocates from the stack deep enough that all expressions are exhausted before the recursion stack depth reaches the allocations. The memory map and source is documented in -src.doc.txt. Tokens are encoded using values 0-20, where 0 is an +src.doc.txt. Tokens are encoded using values 0-20, where 0 is an invalid token, 1 is minus, 2 is space, 3 is plus, etc. The necessary constants are derived at the start of the program, using the guarantee that globals are initialized to zero; so a correct NULL pointer is obtained from an uninitialized diff --git a/2015/burton/spoilers.md b/2015/burton/spoilers.md index 0bfc05b98..a1b9bdcdc 100644 --- a/2015/burton/spoilers.md +++ b/2015/burton/spoilers.md @@ -4,7 +4,7 @@ `calc` is a recursive-descent parser. It allocates from the stack deep enough that all expressions are exhausted before the recursion stack depth reaches the allocations. The memory map and source is documented in -[src.doc.txt](src.doc.txt). Tokens are encoded using values 0-20, where 0 is an +[src.doc.txt](%%REPO_URL%%/2015/burton/src.doc.txt). Tokens are encoded using values 0-20, where 0 is an invalid token, 1 is minus, 2 is space, 3 is plus, etc. The necessary constants are derived at the start of the program, using the guarantee that globals are initialized to zero; so a correct NULL pointer is obtained from an uninitialized diff --git a/2020/endoh2/spoiler/spoiler.html b/2020/endoh2/spoiler/spoiler.html index 5fe847a58..e604bde7a 100644 --- a/2020/endoh2/spoiler/spoiler.html +++ b/2020/endoh2/spoiler/spoiler.html @@ -139,14 +139,14 @@

    The source code of the font is glyphs.txt, which is a sequence of chunks that is a ASCII code (65-90) followed by points data: x,y,ctrl.

    If ctrl is 1, the point is used as control point for quadratic bezier curve.

    -

    code.c is the main logic for the program, which has some placeholders +

    code.c is the main logic for the program, which has some placeholders for font data and something.

    It decompresses the font data and renders a given text by projection. It exploits C99’s double complex type to represent 2D points, but carefully coded so that it does not require any math.h functions; you don’t have to pass -lm to cc.

    -

    tmpl.txt is a template for the program. gen.rb composes -the all items and generates prog.c.

    +

    tmpl.txt is a template for the program. gen.rb composes +the all items and generates prog.c.


    Jump to: top

    -

    Extreme cannibalism in 2020 IOCCC ‘Don’t tread on me’ Snake game

    +

    Extreme cannibalism in a Snake game

    +

    See the 2020 IOCCC ‘Don’t tread on me’ Snake game source code.

    To give an idea what cannibalism can look like (it’s I believe a unique feature to any other version of Snake), this file shows just how extreme cannibalism can get with a long snake. I made a few changes, described below, to make it easier diff --git a/2020/ferguson1/cannibalism.log.md b/2020/ferguson1/cannibalism.log.md index c143216a9..a35e32109 100644 --- a/2020/ferguson1/cannibalism.log.md +++ b/2020/ferguson1/cannibalism.log.md @@ -1,4 +1,6 @@ -# Extreme cannibalism in [2020 IOCCC 'Don't tread on me' Snake game](/2020/ferguson1/prog.c) +# Extreme cannibalism in a Snake game + +See the [2020 IOCCC 'Don't tread on me' Snake game source code](%%REPO_URL%%/2020/ferguson1/prog.c). To give an idea what cannibalism can look like (it's I believe a unique feature to any other version of Snake), this file shows just how extreme cannibalism can diff --git a/2020/ferguson1/chocolate-cake.html b/2020/ferguson1/chocolate-cake.html index fd4ce82f6..1c5116a8c 100644 --- a/2020/ferguson1/chocolate-cake.html +++ b/2020/ferguson1/chocolate-cake.html @@ -140,7 +140,7 @@ something of my mum’s speciality. It’s complicated and I should warn that no has seemed to get it down as well as she has but it’s well worth the effort if you love chocolate and have the time and patience.

    My late stepmum who only liked white ‘chocolate’ loved this cake! The picture -below is after it’s been iced. The image ioccc-cake.jpg was a +below is after it’s been iced. The image cake.jpg was a feeble attempt at drawing IOCCC into the cake before icing, a different time. The picture below was taken for my birthday (14 February) in 2022 as it’s the best one I have:

    @@ -161,9 +161,9 @@ there of course. Please make sure to mention me so I get a push notification as I don’t check it very often. Thanks and again enjoy!

    Measurements

    This was originally taken from an American magazine for women so the -measurements are in the US standards. A nice resource (that has much more than -just cooking) is http://www.onlineconversion.com/cooking.htm. This will -particularly matter for cups, teaspoons, tablespoons and ounces.

    +measurements are in the US standards. There is a +nice resource that has much more than +just cooking). This will particularly matter for cups, teaspoons, tablespoons and ounces.

    Baker’s chocolate

    Baker’s chocolate is a brand name and the product in question is unsweetened chocolate bars used for baking. According to a chocolates FAQ it might be diff --git a/2020/ferguson1/chocolate-cake.md b/2020/ferguson1/chocolate-cake.md index 755a450ca..a6fec51e4 100644 --- a/2020/ferguson1/chocolate-cake.md +++ b/2020/ferguson1/chocolate-cake.md @@ -6,7 +6,7 @@ has seemed to get it down as well as she has but it's well worth the effort if you love chocolate and have the time and patience. My late stepmum who only liked white 'chocolate' loved this cake! The picture -below is after it's been iced. The image [ioccc-cake.jpg](ioccc-cake.jpg) was a +below is after it's been iced. The image [cake.jpg](%%REPO_URL%%/2020/ferguson1/cake.jpg) was a feeble attempt at drawing `IOCCC` into the cake before icing, a different time. The picture below was taken for my birthday (14 February) in 2022 as it's the best one I have: @@ -35,9 +35,9 @@ I don't check it very often. Thanks and again enjoy! ## Measurements This was originally taken from an American magazine for women so the -measurements are in the US standards. A nice resource (that has much more than -just cooking) is . This will -particularly matter for cups, teaspoons, tablespoons and ounces. +measurements are in the US standards. There is a +[nice resource](http://www.onlineconversion.com/cooking.htm) that has much more than +just cooking). This will particularly matter for cups, teaspoons, tablespoons and ounces. ## Baker's chocolate @@ -197,7 +197,7 @@ bowl can sit in. thick BUT not too thick. **Make *SURE* ICING DOES *NOT* GET WET!** The idea is to **MAKE THE BOWL IT'S IN COLD *BUT TO NOT LET THE ICING GET WET!*** -[IOCCC and chocolate]: ioccc-and-chocolate.pdf +[IOCCC and chocolate]: %%REPO_URL%%/2020/ferguson1/cake.jpg [chocolates FAQ]: https://www.davidlebovitz.com/chocolate-faqs/ diff --git a/2020/ferguson1/gameplay.html b/2020/ferguson1/gameplay.html index bd59f606b..4f3736870 100644 --- a/2020/ferguson1/gameplay.html +++ b/2020/ferguson1/gameplay.html @@ -138,7 +138,7 @@ have included much more than just the input keys and a few printouts of the game. For normal play you probably don’t even need this file at all unless it be for the input keys.

    -

    + +

    Most people probably won’t have any issue at all but for those who have any -problems with the terminal see the terminals.html (terminals.md on -GitHub) file for more information on the terminal capabilities testing utility I +problems with the terminal see the terminals.html +file for more information on the terminal capabilities testing utility I include.

    -

    For troubleshooting other problems see troubleshooting.html -(troubleshooting.md on GitHub) and bugs.html (bugs.md on GitHub).

    -

    2. Input keys

    +

    For troubleshooting other problems see troubleshooting.html +and bugs.html.

    +
    +

    2. Input keys

    +
    • Left, right, up and down arrow keys: move that direction.
    • q (and Q): quit the game.
    • @@ -195,14 +200,16 @@ Note that no other keys will resume the game; however if you press a key that getch() picks up on and the game is not paused then it will be as if you pressed the current direction key (assuming you already moved the snake).
    -

    3. Gameplay

    +

    3. Gameplay

    Here I will show the initial screen as well as what a few things look like. If you don’t feel you need this but you want to configure colours jump to colour selection. You can also jump to gameplay modes or game variables.

    The bug colour by default is white; the snake head colour is red and the snake body colour is green. The walls are cyan.

    -

    Gameplay: The initial screen

    +

    When you load the game you will see a screen that looks something like the below. Note that the top line is the score/status line: the top wall is at line 1 and the left wall is column 0. Below I use the coordinates in the X/Y order @@ -242,7 +249,9 @@ size.

    it will always have an upper limit depending on the terminal size.

  4. The number of bugs eaten so far is 0.

  5. -

    Gameplay: Playing the game

    +
        X:39/49 Y:8/16 S:5/658 B:0
         ##################################################
         #                                                #
    @@ -300,7 +309,9 @@ Let’s do that:

    ##################################################

    Observe that the bug was eaten and a new bug spawned elsewhere. I went left three and then up one and could slither on to the bug.

    -

    Gameplay: Walls

    +

    By default walls are passable (WALLS=1). Let’s get to full size and go through the top wall:

        X:36/49 Y:15/16 S:10/658 B:1
    @@ -363,7 +374,9 @@ might look like (I set the starting size to 150 and had only just started):

    If I continue going up I will see:

    OUCH!
     X:20/49 Y:1/16 S:150/658 B:0
    -

    Gameplay: Cannibalism

    +

    By default cannibalism is disabled (CANNIBAL=0) so if you run into yourself it might look something like:

        X:45/49 Y:10/16 S:10/658 B:1
    @@ -448,16 +461,20 @@ will see that the arrow has moved over:

    left go right etc.) and then after some length (but before you get beyond the snake) turn (so that you go perpendicular) and then watch as the snake starts unwinding at one place and then suddenly unwinds another direction.

    -

    An example of extreme cannibalism is in the cannibalism.log.html -(cannibalism.log.md on GitHub) file. It explains information about the file +

    An example of extreme cannibalism is in the cannibalism.log.html +file. It explains information about the file including how to find the bug, head and tail of the snake, at least where it was documented. The first run has several dumps. The final example has the snake inside itself.

    -

    Gameplay: Shedding (stretching)

    +

    This feature will make you grow by the value of SHEDS for every SHED movements (the counter isn’t incremented when you eat a bug). Basically growing without eating a bug (stretching would be better name here).

    -

    Gameplay: Winning

    +

    If you ever get to the MAXSIZE the game is won. You can force a win by setting the max size to a smaller value than the size you specify (or the default) or setting the size to higher than the default (or < 0 which will end @@ -467,7 +484,7 @@ less than again - I’m not going to try and figure that out however). Anyway:

    Observe that the size isn’t the default 997: because the screen size is too -small for that value (see terminals.md).

    +small for that value (see [terminals.md][]).

    The reason I chose 997 is that it leaves a bit of a challenge for some (maybe most) people but it’s still winnable. Previously even I couldn’t have won unless maybe a much bigger screen, if both cheat modes were disabled. I probably could @@ -485,19 +502,25 @@ but then it occurred to me that there are prime numbers close to 1000 so why not choose one instead (that was less than 1000)? And so I did. Another fun fact: at the default starting size and growth size of 5 the number of bugs needed before the game is won is 199 - also a prime!

    -

    Gameplay: Quitting

    +

    If you wish to quit you can hit ‘q’ (case-insensitive). For example:

        X:24/49 Y:8/16 S:5/658 B:0
    -

    4. Gameplay modes

    -

    Here I list a number of different modes of play. In the bugs.html -(bugs.md on GitHub) file I even show how there’s a built-in test unit for some +

    +

    Here I list a number of different modes of play. In the bugs.html +file I even show how there’s a built-in test unit for some modes! There are certainly other modes that could be imagined: the modes below happened over time and some were simply an accidental discovery or something I thought of by a chance; others were thought out from the beginning but were improved over time.

    -

    The play.sh script sets up some of these automatically; I describe it after +

    The play.sh script sets up some of these automatically; I describe it after the modes below.

    -

    Photosensitive epilepsy/Stimulation overload trigger warnings

    +

    If you have photosensitive epilepsy please be careful especially with low values for both WAIT and EVADE. It appears that the number of hertz (flashes) per second triggering seizures is wide but depending on the variables it @@ -507,7 +530,9 @@ exercise caution. This could trigger seizures and it might also be too m stimulation for some people.

    Please be careful of these if these types of things have ever affected you or if you have any form of epilepsy. Thank you.

    -

    Gameplay mode: Drawing / Practice mode

    +

    If you want to draw the snake wherever you like on the screen you can do this by modifying the wait time (for input) to -1 (or any value < 0): then the snake does not move until you press a movement key. For example:

    @@ -527,7 +552,7 @@ to be a problem simply do:

    Or something like that (maybe make the size bigger but that’s up to you). You could also set the max size to be the highest possible by saying

        MAXSIZE=-1
    -

    Which I’ve done in the play.sh script.

    +

    Which I’ve done in the play.sh script.

    I discuss how this mode works in [spoilers.markdown][].

    Here’s an example run where I spelt ‘SNAKE’. As you can see it’s far from perfect: the snake after all does not leave gaps and the game does not support @@ -538,7 +563,9 @@ for. But you can consider this mode drawing or practice mode.

    oooo o oo ooooooo oooo ooooo o o ooo oo o ooo o oooo o oo ooo oooooooo>
    -

    Gameplay mode: Computer playing / Automatic mode (Photosensitive epilepsy/Stimulation overload trigger)

    +

    Photosensitive epilepsy/stimulation overload trigger warning: For those who have epilepsy or are susceptible to stimulation overload from flashing lights please do be careful with this mode. Depending on your @@ -563,7 +590,9 @@ by itself.

    seems to take longer for it to get a bug as it gets longer. I believe these happen because the bug has to find a X and Y coordinate that’s not occupied and so with fewer available it has a harder time finding a place in that one line.

    -

    Computer player variations

    +

    Here’s how to make the bug move every time the snake moves:

        CANNIBAL=1 WALLS=1 WAIT=0 EVADE=1 ./prog

    Help the computer win fairly quickly

    @@ -577,7 +606,7 @@ thought of):

    shows to be 10 characters depends on whether or not it gets a bug before it can get to that length - and then it’ll start shrinking until it’s just the head then the head again (i.e. 1 then 0 in size) and then win! This is also in the -play.sh script.

    +play.sh script.

    Adjusting the time/speed

    Of course you can also do something like:

        WAIT=5 WALLS=1 CANNIBAL=1 ./prog
    @@ -597,7 +626,9 @@ horizontally the snake ran into itself at:

    X:57/156 Y:20/41 S:155/997 B:30

    What if you set the size to a high value? The lowest? There are bound to be other games to play with this feature!

    -

    Gameplay mode: Grow-Shrink mode (Positive and Negative Winning)

    +

    In this mode you’re simultaneously growing and shrinking but because the max size is unsigned you can win both by shrinking to the point of losing your body or growing to the full size directly. This is how it works:

    @@ -615,16 +646,18 @@ actually tried it.

    The parameters above were chosen after playing with the mode a bit to find a value that wouldn’t take that much time but still would pose a challenge. One could reverse it so that one shrinks more than growing.

    -

    The crazy.log.html (crazy.log.md on GitHub) file has several screen +

    The crazy.log.html file has several screen dumps with this idea.

    You could also have it so that eating a bug makes you shrink and moving so many -moves you grow. I tried this and for me it was far more fun. The play.sh +moves you grow. I tried this and for me it was far more fun. The play.sh also has this mode:

        SIZE=100 SHEDS=5 GROW=-10 SHED=50 MAXSIZE=250 ./prog
    -

    Obviously there are many other variations. The play.sh script has some +

    Obviously there are many other variations. The play.sh script has some of them (the above is option 5; others are 4, 15 and 16 but only options 4 and 5 are called Grow / Shrink).

    -

    Hypnotic / Sleepy mode (Photosensitive epilepsy/Stimulation overload trigger)

    +

    Photosensitive epilepsy/stimulation overload trigger warning: For those who have epilepsy or are susceptible to stimulation overload from flashing lights and patterns please do be careful with this mode. Depending on your @@ -637,14 +670,18 @@ snake moving too.

        EVADE=1 CANNIBAL=1 ./prog

    And just moving the snake about not trying to catch any bugs - just let whatever happens happen.

    -

    Gameplay mode: Stimulation / Calming mode

    +

    If you just need something to stimulate your mind to keep you calm or simply you want to play a game without having to worry about winning or losing you can set the growth size to 0 and then just move the snake round and round eating bugs until you want to quit. You can enable cannibalism so that you don’t have to worry about even running into yourself and losing:

        GROW=0 CANNIBAL=1 ./prog
    -

    Gameplay mode: Expansibility

    +

    As I was writing this document and the game modes I have thought of other game modes (they were added) and I have come back to this document to add more modes. That’s the beauty of the variables I have implemented: together with the @@ -657,43 +694,55 @@ not be too hard either. And a game developer who does not play their games is a game developer who is detached from their player base and the wants and needs are therefore disregarded if even heard. I have played this game a lot for this reason as well as I simply enjoy it and thinking up new modes.

    -

    5. Scripts

    +

    5. Scripts

    The following scripts are provided to simplify and automate some of the things this file discusses as well as allowing to easily change the colours.

    -

    Colours selection: snake-colours

    -

    To do this use the snake-colours script like so:

    -
        ./snake-colours
    + +

    To do this use the snake-colours.sh script like so:

    +
        ./snake-colours.sh

    If you want to pass in specific variables you can do that too e.g.:

    -
        CANNIBAL=1 ./snake-colours
    +
        CANNIBAL=1 ./snake-colours.sh

    The script will prompt you for the colour of the walls, snake head, body and the bug.

    -

    Automate the above gameplay modes

    -

    The play.sh script has the gameplay modes described in this file and is menu +

    +

    The play.sh script has the gameplay modes described in this file and is menu based (there might be differences and some of the modes I include a variation). The script tests the terminal (allowing you to continue even if problems are detected), prompts you if you want to select colours (like those in -snake-colours above) and then gives you a list of game modes to play. You can +snake-colours.sh above) and then gives you a list of game modes to play. You can pass in the game variables but note that if you pass in a variable that the mode you choose uses then the script will override what you pass in.

    To use you can do something like:

        ./play.sh

    Or to make it so walls are an obstacle:

        WALLS=0 ./play.sh
    -

    6. Notes about some of the game variables

    +

    The game variables can be used for a variety of things including different gameplay modes (as shown above) but here are some general notes about a few of them.

    -

    WAIT: Snake speed

    +

    Besides the different game modes, if you find it too fast/slow you can change it to a value that’s better for you. Remember it’s a wait time so if you want the snake to move slower you have to increase the wait time!

    -

    EVADE: Bug evasion frequency

    +

    For every EVADE snake movements the bug will try and find a new place to occupy. It might be very close to it and I do not ensure it’s a new place at all.

    Each time the bug is placed the counter will be reset whether from eating the bug or not reaching it in time. Default 300 moves.

    This can help you get out of a trap but it can also sometimes make it harder.

    -

    SIZE / MAXSIZE: Initial / Max snake sizes

    +

    997 might be a bit high for many people. Or maybe you don’t have enough time. Or you’re not in the mood to lose. Or you want to get close to a size you were last time but quickly. It might be in conjunction with drawing mode.

    @@ -702,10 +751,14 @@ the snake will ‘populate’ in the snake arrays and the visible size: as I hav discussed here and there the snake doesn’t grow immediately so it takes time before the snake is visibly that many characters. In other words just because it says SIZE 29 doesn’t mean it will instantly be 29 characters on the screen.

    -

    GROW / SHEDS : Growth / Shedding sizes

    +

    Similar to the initial size. Notice that the above point on size applies here: it will take the number of movements before it is ‘its full size’.

    -

    7. Conclusion (and inspirational words for everyone)

    +

    I believe that this file has given more than enough information for anyone to get an idea of what is possible with my implementation of Snake. I realise also that most people won’t have read this far and that’s quite all right; I’m very diff --git a/2020/ferguson1/gameplay.md b/2020/ferguson1/gameplay.md index 0e89b4b9d..8d5b71c32 100644 --- a/2020/ferguson1/gameplay.md +++ b/2020/ferguson1/gameplay.md @@ -3,8 +3,7 @@ have included much more than just the input keys and a few printouts of the game. For normal play you probably don't even need this file at all unless it be for the input keys. - - +

    1. [Testing terminal environment/capabilities](#support) 2. [Input keys](#input) @@ -46,20 +45,25 @@ for the input keys. 7. [Conclusion (and inspirational words for everyone)](#conclusions) +
    -# 1. Testing terminal environment/capabilities + Most people probably won't have any issue at all but for those who have any -problems with the terminal see the [terminals.html][] ([terminals.md][] on -GitHub) file for more information on the terminal capabilities testing utility I +problems with the terminal see the [terminals.html][] +file for more information on the terminal capabilities testing utility I include. For troubleshooting other problems see [troubleshooting.html][] -([troubleshooting.md][] on GitHub) and [bugs.html][] ([bugs.md][] on GitHub). +and [bugs.html][]. -# 2. Input keys +
    +# 2. Input keys +
    - Left, right, up and down **arrow keys**: move that direction. - `q` (and `Q`): quit the game. @@ -68,7 +72,10 @@ For troubleshooting other problems see [troubleshooting.html][] that `getch()` picks up on and the game is not paused then it will be as if you pressed the current direction key (assuming you already moved the snake). -# 3. Gameplay + +
    +# 3. Gameplay +
    Here I will show the initial screen as well as what a few things look like. If you don't feel you need this but you want to configure colours jump to [colour @@ -79,7 +86,9 @@ The bug colour by default is white; the snake head colour is red and the snake body colour is green. The walls are cyan. -## Gameplay: The initial screen + When you load the game you will see a screen that looks something like the below. Note that the top line is the score/status line: the top wall is at line @@ -128,7 +137,9 @@ to the number in the diagram: - The number of bugs eaten so far is 0. -## Gameplay: Playing the game + ``` @@ -202,7 +213,9 @@ Observe that the bug was eaten and a new bug spawned elsewhere. I went left three and then up one and could slither on to the bug. -# Gameplay: Walls + By default walls are passable (**WALLS=1**). Let's get to full size and go through the top wall: @@ -286,8 +299,9 @@ X:20/49 Y:1/16 S:150/658 B:0 ``` - -# Gameplay: Cannibalism + By default cannibalism is disabled (**CANNIBAL=0**) so if you run into yourself it might look something like: @@ -395,19 +409,24 @@ snake) turn (so that you go perpendicular) and then watch as the snake starts unwinding at one place and then suddenly unwinds another direction. An example of extreme cannibalism is in the [cannibalism.log.html][] -([cannibalism.log.md][] on GitHub) file. It explains information about the file +file. It explains information about the file including how to find the bug, head and tail of the snake, at least where it was documented. The first run has several dumps. The final example has the snake inside itself. -# Gameplay: Shedding (stretching) + + This feature will make you grow by the value of **SHEDS** for every **SHED** movements (the counter isn't incremented when you eat a bug). Basically growing without eating a bug (stretching would be better name here). -# Gameplay: Winning + If you ever get to the **MAXSIZE** the game is won. You can force a win by setting the max size to a smaller value than the size you specify (or the @@ -445,7 +464,9 @@ the default starting size and growth size of 5 the number of bugs needed before the game is won is 199 - also a prime! -# Gameplay: Quitting + If you wish to quit you can hit 'q' (case-insensitive). For example: @@ -454,10 +475,12 @@ If you wish to quit you can hit 'q' (case-insensitive). For example: ``` -# 4. Gameplay modes + Here I list a number of different modes of play. In the [bugs.html][] -([bugs.md][] on GitHub) file I even show how there's a built-in test unit for some +file I even show how there's a built-in test unit for some modes! There are certainly other modes that could be imagined: the modes below happened over time and some were simply an accidental discovery or something I thought of by a chance; others were thought out from the beginning but were @@ -467,7 +490,9 @@ The [play.sh][] script sets up some of these automatically; I describe it after the modes below. -## Photosensitive epilepsy/Stimulation overload trigger warnings + If you have **photosensitive epilepsy please be careful** especially with low values for both **WAIT** and **EVADE**. It appears that the [number of hertz (flashes) @@ -481,7 +506,10 @@ stimulation for some people.** **Please be careful of these if these types of things have ever affected you or if you have any form of epilepsy. Thank you.** -## Gameplay mode: Drawing / Practice mode + + If you want to draw the snake wherever you like on the screen you can do this by modifying the wait time (for input) to -1 (or any value < 0): then the snake @@ -542,8 +570,9 @@ for. But you can consider this mode drawing or practice mode. ``` - -## Gameplay mode: Computer playing / Automatic mode (Photosensitive epilepsy/Stimulation overload trigger) + **Photosensitive epilepsy/stimulation overload trigger warning:** For those who have epilepsy or are susceptible to stimulation overload from @@ -578,7 +607,10 @@ seems to take longer for it to get a bug as it gets longer. I believe these happen because the bug has to find a X and Y coordinate that's not occupied and so with fewer available it has a harder time finding a place in that one line. -### Computer player variations + + Here's how to make the bug move every time the snake moves: @@ -650,7 +682,10 @@ horizontally the snake ran into itself at: What if you set the size to a high value? The lowest? There are bound to be other games to play with this feature! -## Gameplay mode: Grow-Shrink mode (Positive and Negative Winning) + + In this mode you're simultaneously growing and shrinking but because the max size is unsigned you can win both by shrinking to the point of losing your body @@ -676,7 +711,7 @@ The parameters above were chosen after playing with the mode a bit to find a value that wouldn't take that much time but still would pose a challenge. One could reverse it so that one shrinks more than growing. -The [crazy.log.html][] ([crazy.log.md][] on GitHub) file has several screen +The [crazy.log.html][] file has several screen dumps with this idea. You could also have it so that eating a bug makes you shrink and moving so many @@ -692,7 +727,9 @@ of them (the above is option 5; others are 4, 15 and 16 but only options 4 and 5 are called Grow / Shrink). -## Hypnotic / Sleepy mode (**Photosensitive epilepsy/Stimulation overload trigger**) + **Photosensitive epilepsy/stimulation overload trigger warning:** For those who have epilepsy or are susceptible to stimulation overload from @@ -713,7 +750,9 @@ And just moving the snake about not trying to catch any bugs - just let whatever happens happen. -## Gameplay mode: Stimulation / Calming mode + If you just need something to stimulate your mind to keep you calm or simply you want to play a game without having to worry about winning or losing you can set @@ -726,7 +765,9 @@ worry about even running into yourself and losing: ``` -## Gameplay mode: Expansibility + As I was writing this document and the game modes I have thought of other game modes (they were added) and I have come back to this document to add more modes. @@ -743,35 +784,43 @@ are therefore disregarded if even heard. I have played this game a lot for this reason as well as I simply enjoy it and thinking up new modes. -# 5. Scripts +
    +# 5. Scripts +
    The following scripts are provided to simplify and automate some of the things this file discusses as well as allowing to easily change the colours. -## Colours selection: snake-colours -To do this use the [snake-colours][] script like so: + + +To do this use the [snake-colours.sh][] script like so: ``` - ./snake-colours + ./snake-colours.sh ``` If you want to pass in specific variables you can do that too e.g.: ``` - CANNIBAL=1 ./snake-colours + CANNIBAL=1 ./snake-colours.sh ``` The script will prompt you for the colour of the walls, snake head, body and the bug. -## Automate the above gameplay modes + + The [play.sh][] script has the gameplay modes described in this file and is menu based (there might be differences and some of the modes I include a variation). The script tests the terminal (allowing you to continue even if problems are detected), prompts you if you want to select colours (like those in -snake-colours above) and then gives you a list of game modes to play. You can +snake-colours.sh above) and then gives you a list of game modes to play. You can pass in the game variables but note that if you pass in a variable that the mode you choose uses then the script will override what you pass in. @@ -788,19 +837,26 @@ Or to make it so walls are an obstacle: ``` -# 6. Notes about some of the game variables + The game variables can be used for a variety of things including different gameplay modes (as shown above) but here are some general notes about a few of them. -## WAIT: Snake speed + + Besides the different game modes, if you find it too fast/slow you can change it to a value that's better for you. Remember it's a wait time so if you want the snake to move slower you have to increase the wait time! -## EVADE: Bug evasion frequency + For every **EVADE** snake movements the bug will try and find a new place to occupy. It might be very close to it and I do not ensure it's a new place at @@ -812,7 +868,9 @@ bug or not reaching it in time. Default 300 moves. This can help you get out of a trap but it can also sometimes make it harder. -## SIZE / MAXSIZE: Initial / Max snake sizes + 997 might be a bit high for many people. Or maybe you don't have enough time. Or you're not in the mood to lose. Or you want to get close to a size you were last @@ -825,14 +883,17 @@ before the snake is visibly that many characters. In other words just because it says SIZE 29 doesn't mean it will instantly be 29 characters on the screen. -## GROW / SHEDS : Growth / Shedding sizes + Similar to the initial size. Notice that the above point on size applies here: it will take the number of movements before it is 'its full size'. - -# 7. Conclusion (and inspirational words for everyone) + I believe that this file has given more than enough information for anyone to get an idea of what is possible with my implementation of Snake. I realise also @@ -849,22 +910,16 @@ the imagination and creativity almost anything is possible.** This is something they believe in themselves!** I would have never thought this the case for me years ago but I know it's true now. **Believe in yourself. Always.** -[terminals.md]: terminals.md -[terminals.html]: terminals.html -[troubleshooting.md]: troubleshooting.md -[troubleshooting.html]: troubleshooting.html -[bugs.md]: bugs.md -[bugs.html]: bugs.html -[spoilers.md]: spoilers.md -[spoilers.html]: spoilers.html -[snake-colours]: snake-colours +[terminals.html]: %%REPO_URL%%/2020/ferguson1/terminals.html +[troubleshooting.html]: %%REPO_URL%%/2020/ferguson1/troubleshooting.html +[bugs.html]: %%REPO_URL%%/2020/ferguson1/bugs.html +[spoilers.html]: %%REPO_URL%%/2020/ferguson1/spoilers.html +[snake-colours.sh]: %%REPO_URL%%/2020/ferguson1/snake-colours.sh [number of hertz (flashes) per second triggering seizures]: https://www.epilepsysociety.org.uk/photosensitive-epilepsy#.Xjgpwi2ZOgQ -[termcaps.c]: termcaps.c -[cannibalism.log.md]: cannibalism.log.md -[cannibalism.log.html]: cannibalism.log.html -[crazy.log.md]: crazy.log.md -[crazy.log.html]: crazy.log.html -[play.sh]: play.sh +[termcaps.c]: %%REPO_URL%%/2020/ferguson1/termcaps.c +[cannibalism.log.html]: %%REPO_URL%%/2020/ferguson1/cannibalism.log.html +[crazy.log.html]: %%REPO_URL%%/2020/ferguson1/crazy.log.html +[play.sh]: %%REPO_URL%%/2020/ferguson1/play.sh
    diff --git a/2020/ferguson1/spoilers.html b/2020/ferguson1/spoilers.html index 591e4a791..411520d5d 100644 --- a/2020/ferguson1/spoilers.html +++ b/2020/ferguson1/spoilers.html @@ -135,7 +135,7 @@

    Introduction (SPOILER ALERT)

    -

    In the gameplay.html (gameplay.md on GitHub) file I have given enough +

    In the gameplay.html file I have given enough information to know how the game looks, how to move the snake, how to pause etc. In this file I am including (some) information on how the game actually works: the technical details as it were, obfuscation techniques and also some of the @@ -145,7 +145,7 @@ everything will be answered here.

    If you’re still interested in this file (i.e. you’re a judge or someone who wants to know more about it) read on. Yes I write a lot. But you probably already knew that so no harm there, hey?

    -

    + +

    The gameplay I have already described but this explains the way things are actually done in more detail.

    First I initialise curses; if this fails I print an error message (curses error) and return 1. Next the screen size is determined and I subtract 1 from @@ -220,7 +223,9 @@ location is updated and redrawn.

    There’s also the processing of any shedding at this point. If the snake eats a bug the snake will not shed; if it sheds the snake will not move in the same manner as if it simply moved. Growth/movement can in some ways be conflated.

    -

    How does the snake movement work?

    +

    The way the snake looks to move is that every time the snake moves the last position (the tail) is replaced with a space (' '). If the snake eats a bug then the snake will get bigger in the next N movements. Note that if the snake @@ -229,14 +234,18 @@ moving at the tail end; I have discussed this more than enough elsewhere.

    There are two arrays that store the last Y/X coordinates of the snake’s positions that are shifted forward as the snake moves about the field looking for bugs.

    -

    Drawing (manual) and computer playing (automatic) modes

    +

    How do these modes work? The timeout() function takes a signed int: if it’s < 0 it waits indefinitely; if it’s 0 it returns immediately even if there’s no input waiting (if input is there then it’s used instead); and if it’s > 0 it waits that many milliseconds. Thus a negative value allows for complete control over the snake’s movement (speed and otherwise), a value of 0 means the snake will move as long as it’s not paused etc. and otherwise it waits up to that many milliseconds (which is how the 0 value comes into play).

    -

    Collision detection

    +

    This was an interesting thing to work out. Because the snake could occupy more than one row and more than one column at a time the two arrays approach seemed good to me.

    @@ -247,7 +256,9 @@ or the bug.

    The bug does its best to avoid landing where the snake is but given that snakes are very flexible and cunning who can tell what might happen? As I noted these bugs are not bugs! :)

    -

    Cannibal collision detection

    +

    How does cannibalism change collision detection? The fact that each time the snake function is called there is a space printed at the tail end was a problem to resolve: what happened is if the snake went through itself then at some point @@ -271,7 +282,9 @@ mode exists for a different kind of play means it should look unnatural: for it

    The second is you can look at it as if two more snakes are having fun with each other. This can also appear to defy physics!

    Choose your poison. Or rather your venom.

    -

    Collision detection when resizing the window of the game

    +

    What happens if the window is resized during the game? If the size is increased then the border can (and will) stay the same; but if the window is shrunk then what? It would be very difficult if not impossible to redraw the snake: where @@ -285,7 +298,7 @@ remain the same. This GREATLY simplified things.

    There was another problem at some point where the snake would quickly grow if it was increased in size but I believe that’s resolved. Anyway what kind of field in real life increases in size like that so suddenly? :)

    -

    Obfuscation

    +

    Obfuscation

    • I make use of the C token pasting operator. Although this is well known it’s probably less known and either way it’s not as simple as just having the code @@ -454,11 +467,11 @@ refer to a x is possibly confusing even without the negative offset

      Of course I don’t have to use negative offsets at all! I could use positive offsets for every time I use negative offsets. But where’s the fun in that? :)

      BTW: Some of these are not in the table of expressions in the -HACKING.html (HACKING.md on GitHub) file. Also there might be some +HACKING.html file. Also there might be some code in there that is no longer correct (it was before I started obfuscation) though it might be able to give an idea. Spoilers abound in -that file (in addition to this file) but the HACKING.html (HACKING.md -on GitHub) file states things that are no longer true: a way of obfuscation +that file (in addition to this file) but the HACKING.html +file states things that are no longer true: a way of obfuscation itself! Instead of misleading comments it’s misleading statements in the file that explains what some of the things are for!

    • Misleading variable names for coordinates. In other words the Y coordinate is @@ -746,7 +759,9 @@ goal; I think I did it but maybe I missed one here and/or there):

      the file based on the 120 columns total. I believe I have succeeded in that though again maybe I have an off by one or two here and/or there.

      Most of the primes above were intentional.

      -

      Skinning the snake (i.e. decreasing the iocccsize)

      +

      This happened in a number of ways and I have already documented some in other parts. Now there are a number of reasons to do this: amongst them to make it possible to obfuscate (plus a more unique layout) but also to add more features.

      @@ -784,7 +799,9 @@ for A > 1 but I could refer to just I instead of calloc() failed I called abort() and before that if initialising ncurses failed I also called abort() and did not report any errors in either event but I do now).

      -

      A few more interesting size optimisations

      +

      As I was getting to the end of obfuscation (wrt size available - and it was getting pretty obfuscated too - the majority of the techniques were already in place at this point) I was looking at the code to see if I could figure out how @@ -844,8 +861,8 @@ the score line is updated: so the empty space will be overwritten anyway. And if the score line is made an empty string it doesn’t matter because it’ll appear as all spaces anyway. Thus I could save another three bytes by changing it to:

          !o  && q *U,*V,' ');
      -

      Technically it would be a " " (see HACKING.html or on GitHub -HACKING.md) else for N (not referring to the variable though it might very +

      Technically it would be a " " (see HACKING.html +else for N (not referring to the variable though it might very well matter here too) movements (i.e. due to sizes) you will at times (e.g. after eating a bug) see the snake body char at 0,0. I’m not bothered about that though because the score line is meant to display something, it squeezes a few diff --git a/2020/ferguson1/spoilers.md b/2020/ferguson1/spoilers.md index fcb434b36..b18cee80a 100644 --- a/2020/ferguson1/spoilers.md +++ b/2020/ferguson1/spoilers.md @@ -1,6 +1,6 @@ # Introduction (SPOILER ALERT) -In the [gameplay.html][] ([gameplay.md][] on GitHub) file I have given enough +In the [gameplay.html][] file I have given enough information to know how the game looks, how to move the snake, how to pause etc. In this file I am including (some) information on how the game actually works: the technical details as it were, obfuscation techniques and also some of the @@ -12,8 +12,7 @@ If you're still interested in this file (i.e. you're a judge or someone who wants to know more about it) read on. Yes I write a lot. But you probably already knew that so no harm there, hey? - - +

      - [How does it work?](#works) - [How does the snake movement work?](#movement) - [Drawing (manual) and computer playing (automatic) modes](#manual-automatic) @@ -23,9 +22,12 @@ already knew that so no harm there, hey? - [Obfuscation](#obfuscation) - [Skinning the snake (i.e. decreasing the iocccsize)](#skinning) - [A few more interesting size optimisations](#size) +
      -# How does it work? + The gameplay I have already described but this explains the way things are actually done in more detail. @@ -105,7 +107,9 @@ bug the snake will not shed; if it sheds the snake will not move in the same manner as if it simply moved. Growth/movement can in some ways be conflated. -# How does the snake movement work? + The way the snake looks to move is that every time the snake moves the last position (the tail) is replaced with a space (`' '`). If the snake eats a bug @@ -118,7 +122,9 @@ positions that are shifted forward as the snake moves about the field looking for bugs. -# Drawing (manual) and computer playing (automatic) modes + How do these modes work? The `timeout()` function takes a signed int: if it's `< 0` it waits indefinitely; if it's `0` it returns immediately even if there's no @@ -129,7 +135,9 @@ will move as long as it's not paused etc. and otherwise it waits up to that many milliseconds (which is how the `0` value comes into play). -# Collision detection + This was an interesting thing to work out. Because the snake could occupy more than one row and more than one column at a time the two arrays approach seemed @@ -145,7 +153,9 @@ are very flexible and cunning who can tell what might happen? As I noted _these bugs are not bugs! :)_ -## Cannibal collision detection + How does cannibalism change collision detection? The fact that each time the snake function is called there is a space printed at the tail end was a problem @@ -177,7 +187,9 @@ other. This can also appear to defy physics! Choose your poison. Or rather your venom. -## Collision detection when resizing the window of the game + What happens if the window is resized during the game? If the size is increased then the border can (and will) stay the same; but if the window is shrunk then @@ -196,7 +208,9 @@ was increased in size but I believe that's resolved. Anyway what kind of field in real life increases in size like that so suddenly? :) -# Obfuscation + - I make use of the C token pasting operator. Although this is well known it's probably less known and either way it's not as simple as just having the code @@ -427,11 +441,11 @@ dimensions. Now in the first call in `main()` I have the code and tests followin offsets for every time I use negative offsets. But where's the fun in that? :) BTW: Some of these are not in the table of expressions in the - [HACKING.html][] ([HACKING.md][] on GitHub) file. Also there might be some + [HACKING.html][] file. Also there might be some code in there that is no longer correct (it was before I started obfuscation) though it might be able to give an idea. Spoilers abound in - that file (in addition to this file) but the [HACKING.html][] ([HACKING.md][] - on GitHub) file states things that are no longer true: a way of obfuscation + that file (in addition to this file) but the [HACKING.html][] + file states things that are no longer true: a way of obfuscation itself! Instead of misleading comments it's misleading statements in the file that explains what some of the things are for! @@ -783,7 +797,10 @@ though again maybe I have an off by one or two here and/or there. Most of the primes above were intentional. -# Skinning the snake (i.e. decreasing the iocccsize) + + This happened in a number of ways and I have already documented some in other parts. Now there are a number of reasons to do this: amongst them to make it @@ -837,7 +854,10 @@ add additional features and also to add proper error reporting (when `calloc()` failed I called `abort()` and before that if initialising ncurses failed I also called `abort()` and did not report any errors in either event but I do now). -# A few more interesting size optimisations + + As I was getting to the end of obfuscation (wrt size available - and it was getting pretty obfuscated too - the majority of the techniques were already in @@ -934,18 +954,16 @@ all spaces anyway. Thus I could save another three bytes by changing it to: !o && q *U,*V,' '); ``` -Technically it would be a `" "` (see [HACKING.html][] or on GitHub -[HACKING.md][]) else for N (not referring to the variable though it might very +Technically it would be a `" "` (see [HACKING.html][] +else for N (not referring to the variable though it might very well matter here too) movements (i.e. due to sizes) you will at times (e.g. after eating a bug) see the snake body char at 0,0. I'm not bothered about that though because the score line is meant to display something, it squeezes a few more bytes and having a space is hardly an imposition on usage (and for that matter having a 'o' at 0,0 isn't either). -[gameplay.md]: gameplay.md -[gameplay.html]: gameplay.html -[HACKING.md]: HACKING.md -[HACKING.html]: HACKING.html +[gameplay.html]: %%REPO_URL%%/2020/ferguson1/gameplay.html +[HACKING.html]: %%REPO_URL%%/2020/ferguson1/HACKING.html
      diff --git a/2020/ferguson1/terminals.html b/2020/ferguson1/terminals.html index e2303db55..a6c3a576d 100644 --- a/2020/ferguson1/terminals.html +++ b/2020/ferguson1/terminals.html @@ -138,7 +138,7 @@

      Terminals are very easy to mess up and for that reason they deserve their own file. I discuss terminal capabilities, dimensions (setting and how to restore sanity if it causes any problems) as well as colours (limitations etc.).

      -

      +
    -

    Capabilities support testing program

    + +

    Although it should be playable without the features I use (except that cursor movement is required) I have provided a source file that can test your terminal for the capabilities I use in the entry.

    It also tries to determine the minimum number of columns to play without the status line overflowing - even with the dynamic length. Try:

        $ make test
    -

    This compiles the program termcaps.c and runs it; you should see something like:

    +

    This compiles the program termcaps.c and runs it; you should see something like:

        terminal supports cursor movement
         terminal supports making cursor invisible
         terminal supports bold
    @@ -228,11 +231,15 @@ problems are if curses fails to initialise or if movement of cursor cannot be
     done (both seem unlikely to happen nowadays).

    Both scripts run this utility and prompt if there are any problems; you can continue either way.

    -

    Setting the game dimensions

    +

    There are a number of ways to do this and only one will keep the terminal sane all the time but that’s by running it under a terminal emulator that you can resize the window with first. But what if you want exacts?

    -

    The LINES and COLUMNS environmental variables

    +

    To specify the lines/columns of curses program per instance use the LINES and COLUMNS environmental variables.

    For demonstration consider the following:

    @@ -247,13 +254,17 @@ game dimensions) - to be 55; it might look like this instead:

        X:27/54 Y:20/41 S:5/997 B:0

    But problems can arise with messing with dimensions: in my tests this held only to lines.

    -

    Terminal insanity

    +

    Terminal sanity can be compromised and it can cause all sorts of output problems; it might not appear right away but it will show its ugly head eventually if you use it. For example pager output might be screwy, echo might be turned off, output of commands might overwrite the input of those commands, etc. For the game you might not see the final score.

    -

    Restoring the terminal

    +

    In my tests there is one thing that at least allows you to see the final score and that is by running clear before running the program. That’s what the prog.alt version does. You might run it as one of:

    @@ -277,7 +288,9 @@ fails log out and back in.

    For more information on this subject generally see the Linux keyboard and console HOWTO (specifically Linux keyboard and console HOWTO section 4). Yes this works under macOS (at least it did for me).

    -

    Terminal size abuse

    +

    So players 1, 2 and 3 are content with not meddling with the terminal sizes outside what’s actually possible with their screen. But then player 4 comes along and thinks he/she will be clever and mess with the dimensions a bit. Let’s @@ -291,30 +304,37 @@ number of lines will be 997. If they were to do:

    to be funny.

    The game will try and be funny in return and you can expect it to not function properly. Because that’s what funny means in this context.

    -

    Terminal limitations

    +

    It’d be nice if curses could detect hitting more than one arrow key at the same time so that diagonal directions would be possible but unfortunately it’s not (cat -v confirms this). Even if I were to define four extra keys what -would they be? And what about the head character? The HACKING.html -(HACKING on GitHub) file has information on this.

    +would they be? And what about the head character? The HACKING.html +file has information on this.

    I also limit the terminal size to 10 lines/columns but most likely it would require the cheat modes to win and in any event allowing certain low values causes problems e.g. LINES=6 COLUMNS=6 and LINES=3 COLUMNS=3 caused some nasty issues.

    -

    Terminal colours

    +

    N.B.: If all you’re after is wanting to change the colours see the script -snake-colours.sh instead. The rest of this file was mostly notes for the +snake-colours.sh instead. The rest of this file was mostly notes for the judges; here I discuss the background, foreground as well as limitations (in particular runtime limitations).

    -

    Curses background

    +

    The documentation I have seen says that the background will always be black and from a quick test this holds even with a terminal that has a white background. There is a way to force the background to remain white though that’s by way of monochrome (so no colours); I discuss that and another related terminal specific in the troubleshooting guide (there’s another way but it would take me over the -iocccsize; I talk about it in the HACKING.html (HACKING on -GitHub) file).

    -

    Monochrome terminals

    +iocccsize; I talk about it in the HACKING.html.

    +

    According to my tests for monochrome terminals the screen has the white and black background; if terminal is configured to be black background white foreground that is the order it is too. You can try that like:

    @@ -324,7 +344,9 @@ implementation that has a problem here? Below I explain what to comment out should you need colours to be disabled but I personally have not run into any problems even with monochrome terminals. Later I say what to do to remove colour support in the source code itself.

    -

    Colour limitations

    +

    According to X/Open Curses, Issue 7 (pg. 57):

        With init_pair() and pair_content(), the value of pair must be in a range
         from 0 to and including COLOR_PAIRS-1. (There may be an
    @@ -385,7 +407,9 @@ instead:

    won’t work for a colour-capable terminal but it doesn’t matter for monochrome terminals one way or another. And since I don’t go beyond the ranges (as I cited earlier) there shouldn’t be any problem here.

    -

    Disabling colour

    +

    Nevertheless if it is a problem and you don’t want to use a monochrome terminal (or can’t):

    First comment out the code that has start_color(); and then add return; to the diff --git a/2020/ferguson1/terminals.md b/2020/ferguson1/terminals.md index ead50024b..6143e1799 100644 --- a/2020/ferguson1/terminals.md +++ b/2020/ferguson1/terminals.md @@ -5,8 +5,7 @@ file. I discuss terminal capabilities, dimensions (setting and how to restore sanity if it causes any problems) as well as colours (limitations etc.). - - +

    - [Capabilities support testing program](#termcaps) - [Setting the game dimensions](#dimensions) * [The LINES and COLUMNS environmental variables](#linescolumns) @@ -19,9 +18,12 @@ sanity if it causes any problems) as well as colours (limitations etc.). * [Monochrome terminals](#monochrome) * [Colour limitations](#colourlimitations) * [Disabling colour](#disablecolour) +
    -# Capabilities support testing program + Although it should be playable without the features I use (except that cursor movement is required) I have provided a source file that can test your terminal @@ -34,7 +36,7 @@ status line overflowing - even with the dynamic length. Try: $ make test ``` -This compiles the program [termcaps.c](termcaps.c) and runs it; you should see something like: +This compiles the program [termcaps.c](%%REPO_URL%%/2020/ferguson1/termcaps.c) and runs it; you should see something like: ``` @@ -115,14 +117,19 @@ done (both seem unlikely to happen nowadays). Both scripts run this utility and prompt if there are any problems; you can continue either way. -# Setting the game dimensions + + There are a number of ways to do this and only one will keep the terminal sane all the time but that's by running it under a terminal emulator that you can resize the window with first. But what if you want exacts? -## The LINES and COLUMNS environmental variables + To specify the lines/columns of curses program per instance use the `LINES` and `COLUMNS` environmental variables. @@ -151,7 +158,10 @@ game dimensions) - to be 55; it might look like this instead: But problems can arise with messing with dimensions: in my tests this held only to lines. -## Terminal insanity + + Terminal sanity can be compromised and it can cause all sorts of output problems; it might not appear right away but it will show its ugly head @@ -160,7 +170,9 @@ be turned off, output of commands might overwrite the input of those commands, etc. For the game you might not see the final score. -### Restoring the terminal + In my tests there is one thing that at least allows you to see the final score and that is by running `clear` before running the program. That's what the @@ -201,7 +213,10 @@ For more information on this subject generally see the [Linux keyboard and console HOWTO][] (specifically [Linux keyboard and console HOWTO section 4][]). Yes this works under macOS (at least it did for me). -### Terminal size abuse + + So players 1, 2 and 3 are content with not meddling with the terminal sizes outside what's actually possible with their screen. But then player 4 comes @@ -227,13 +242,15 @@ The game will try and be funny in return and you can expect it to not function properly. Because that's what funny means in this context. -# Terminal limitations + It'd be nice if curses could detect hitting more than one arrow key at the same time so that diagonal directions would be possible but unfortunately it's not (`cat -v` confirms this). Even if I were to define four extra keys what would they be? And what about the head character? The [HACKING.html][] -([HACKING](HACKING.md) on GitHub) file has information on this. +file has information on this. I also limit the terminal size to 10 lines/columns but most likely it would require the cheat modes to win and in any event allowing certain low values @@ -241,25 +258,31 @@ causes problems e.g. **LINES=6 COLUMNS=6** and **LINES=3 COLUMNS=3** caused some nasty issues. -# Terminal colours + N.B.: If all you're after is wanting to change the colours see the script [snake-colours.sh][] instead. The rest of this file was mostly notes for the judges; here I discuss the background, foreground as well as limitations (in particular runtime limitations). -## Curses background + + The documentation I have seen says that the background will always be black and from a quick test this holds even with a terminal that has a white background. There is a way to force the background to remain white though that's by way of monochrome (so no colours); I discuss that and another related terminal specific in the troubleshooting guide (there's another way but it would take me over the -iocccsize; I talk about it in the [HACKING.html][] ([HACKING](HACKING.md) on -GitHub) file). +iocccsize; I talk about it in the [HACKING.html][]. -## Monochrome terminals + According to my tests for monochrome terminals the screen has the white and black background; if terminal is configured to be black background white @@ -275,7 +298,10 @@ should you need colours to be disabled but I personally have not run into any problems even with monochrome terminals. Later I say what to do to remove colour support in the source code itself. -## Colour limitations + + According to X/Open Curses, Issue 7 (pg. 57): @@ -369,7 +395,10 @@ won't work for a colour-capable terminal but it doesn't matter for monochrome terminals one way or another. And since I don't go beyond the ranges (as I cited earlier) there shouldn't be any problem here. -## Disabling colour + + Nevertheless if it is a problem and you don't want to use a monochrome terminal (or can't): @@ -381,11 +410,10 @@ you can also comment out the `init_pair()` calls. Perhaps you only need to add the `return;` to `C()`. My guess is that's the case but I do not know for certain. -[HACKING.md]: HACKING.md -[HACKING.html]: HACKING.html +[HACKING.html]: %%REPO_URL%%/2020/ferguson1/HACKING.html [Linux keyboard and console HOWTO]: https://www.tldp.org/HOWTO/Keyboard-and-Console-HOWTO.html [Linux keyboard and console HOWTO section 4]: https://www.tldp.org/HOWTO/Keyboard-and-Console-HOWTO-4.html -[snake-colours.sh]: snake-colours.sh +[snake-colours.sh]: %%REPO_URL%%/2020/ferguson1/snake-colours.sh
    diff --git a/2020/ferguson1/troubleshooting.html b/2020/ferguson1/troubleshooting.html index dc3a02d3b..fd4002ddc 100644 --- a/2020/ferguson1/troubleshooting.html +++ b/2020/ferguson1/troubleshooting.html @@ -157,7 +157,7 @@ it as structured as possible/easiest to find.

    The top wall isn’t (all/some of the time) visible!

    Because the score line is dynamic in length depending on the terminal size it can happen that the score/status wraps to the next line(s). This can be fixed by -modifying the status line (see HACKING.html or on GitHub HACKING.md) but +modifying the status line (see HACKING.html but you shouldn’t need it to be very wide.

    • RESOLUTION #0: Use a bigger screen (it doesn’t take that many columns)

      @@ -166,12 +166,12 @@ needed. This won’t work right if you change the score line!

      Note that this utility is not perfect; I describe this elsewhere. Either way a small screen will make it harder to play esp without the cheat modes enabled (but they can still be fun with large screens).

    • -
    • RESOLUTION #1: Open the prog.c and change the line

      +
    • RESOLUTION #1: Open the prog.c and change the line

            #define J Z(X:%d/%d Y:%d/%d S:%zu/%zu B:%zu\n),Y,y[-2],X, *y, A, g, c );

      To be something like:

            #define J Z(B:%zu\n), c);

      Recompile and try again. That will then show only the number of bugs eaten. -See the HACKING.html (HACKING.md on GitHub) file for other data you +See the HACKING.html file for other data you can include (though there are some discrepancies here and there as you’ll see).

    @@ -194,8 +194,8 @@ when it does move you’ll see it doesn’t move for long.

    Sometimes also it might appear that the movement is delayed but there are numerous causes for this some of which are a busy computer but ultimately it’ll catch up; just give it the time it needs.

    -
  6. BOTTOM LINE: If you want more information then see the bugs.html -(bugs.md on GitHub) file.

  7. +
  8. BOTTOM LINE: If you want more information then see the bugs.html +file.

  9. I can’t see the snake head (or other part of the snake)!

    Possibly this could happen with too long a score line which I already discussed. @@ -239,7 +239,7 @@ desperate copy and paste the entire file into a document and search for the bug char (if it’s an editor like vi/vim you will have to be sure to escape the char since * is a regexp metacharacter). This has happened to me numerous times.

  10. RESOLUTION #3: If the colour contrast is not good for your eyes use the -snake-colours script to select a different colour scheme.

  11. +snake-colours.sh script to select a different colour scheme.

    The game froze!

    This should not be possible either but without certain safety checks in place I @@ -353,9 +353,9 @@ at least) it’s at /usr/share/terminfo/6c/linux-m (for macOS Ventu background white and the foreground black. This will of course mean you have no colour but unfortunately changing the background colour of curses would eat too many bytes in the entry (I cite the functions in the -HACKING.html (HACKING.md on GitHub) file).

    +HACKING.html.

    I discuss colours and terminals in much more detail in -terminals.html (terminals.md on GitHub).

    +terminals.html.

    The text is hard to see (not bright enough)!

      @@ -419,7 +419,7 @@ example:

      is invalid input because octal only has digits 0 - 7: the resulting size will be 0.

      I discuss the signed/unsigned issue to do with curses and sizes in C being -unsigned in bugs.html (bugs.md on GitHub) but probably there isn’t +unsigned in bugs.html but probably there isn’t anything more to say here.

      Errors and error reporting

      If curses fails to initialise you should get an error that says ‘curses error’ diff --git a/2020/ferguson1/troubleshooting.md b/2020/ferguson1/troubleshooting.md index ba9eba39c..1bad406f7 100644 --- a/2020/ferguson1/troubleshooting.md +++ b/2020/ferguson1/troubleshooting.md @@ -26,7 +26,7 @@ it as structured as possible/easiest to find. Because the score line is dynamic in length depending on the terminal size it can happen that the score/status wraps to the next line(s). This can be fixed by -modifying the status line (see [HACKING.html][] or on GitHub [HACKING.md][]) but +modifying the status line (see [HACKING.html][] but you shouldn't need it to be very wide. * RESOLUTION #0: Use a bigger screen (it doesn't take that many columns) @@ -48,7 +48,7 @@ you shouldn't need it to be very wide. #define J Z(B:%zu\n), c); Recompile and try again. That will then show only the number of bugs eaten. - See the [HACKING.html][] ([HACKING.md][] on GitHub) file for other data you + See the [HACKING.html][] file for other data you can include (though there are some discrepancies here and there as you'll see). @@ -81,7 +81,7 @@ e.g. when the snake is growing. it'll catch up; just give it the time it needs. * BOTTOM LINE: If you want more information then see the [bugs.html][] -([bugs.md][] on GitHub) file. +file. ## I can't see the snake head (or other part of the snake)! @@ -136,7 +136,7 @@ char (if it's an editor like vi/vim you will have to be sure to escape the char since `*` is a regexp metacharacter). This has happened to me numerous times. * RESOLUTION #3: If the colour contrast is not good for your eyes use the -[snake-colours][] script to select a different colour scheme. +[snake-colours.sh][] script to select a different colour scheme. ## The game froze! @@ -288,10 +288,10 @@ so that's probably why; in CentOS I did have to install it specially. background white and the foreground black. This will of course mean you have no colour but unfortunately changing the background colour of curses would eat too many bytes in the entry (I cite the functions in the - [HACKING.html][] ([HACKING.md][] on GitHub) file). + [HACKING.html][]. I discuss colours and terminals in much more detail in - [terminals.html][] ([terminals.md][] on GitHub). + [terminals.html][]. ## The text is hard to see (not bright enough)! @@ -395,7 +395,7 @@ is invalid input because octal only has digits 0 - 7: the resulting size will be I discuss the signed/unsigned issue to do with curses and sizes in C being -unsigned in [bugs.html][] ([bugs.md][] on GitHub) but probably there isn't +unsigned in [bugs.html][] but probably there isn't anything more to say here. ## Errors and error reporting @@ -438,14 +438,11 @@ Why does it show snake size as 0 when I specified 1? It's because the max size is 0 and I limit the size to be no bigger than the max size. -[HACKING.md]: HACKING.md -[HACKING.html]: HACKING.html -[prog.c]: prog.c -[bugs.md]: bugs.md -[bugs.html]: bugs.html -[terminals.md]: terminals.md -[terminals.html]: terminals.html -[snake-colours]: snake-colours +[HACKING.html]: %%REPO_URL%%/2020/ferguson1/HACKING.html +[prog.c]: %%REPO_URL%%/2020/ferguson1/prog.c +[bugs.html]: %%REPO_URL%%/2020/ferguson1/bugs.html +[terminals.html]: %%REPO_URL%%/2020/ferguson1/terminals.html +[snake-colours.sh]: %%REPO_URL%%/2020/ferguson1/snake-colours.sh [Snakey]: https://www.hp-lexicon.org/character/gaunt-family/morfin-gaunt/ diff --git a/2020/ferguson2/recode.html b/2020/ferguson2/recode.html index 7573c7094..a2b78c7cb 100644 --- a/2020/ferguson2/recode.html +++ b/2020/ferguson2/recode.html @@ -139,7 +139,7 @@ explore my Enigma machine simulator. I really encourage you to do this but of course you don’t have to if you don’t wish to.

      -

      +
      -

      What is recode and why is it recommended?

      -

      To demonstrate how to and why you should use the recode program with -the Enigma machine simulator I have included some examples here as +

      + +

      To demonstrate how to and why you should use the recode.c program with +the Enigma machine simulator I have included some examples here as well as brief (‘brief?!’ I am sure many would think but it’s brief for me) commentary.

      It would not be possible to do all that the recode program does in my entry @@ -181,7 +184,7 @@ with the Roman numeral, showing their actual orders etc.), the reflectors (labelling them with B, C and showing the actual strings) etc.

      In this file I will show an example of each feature and then get to the wonderful ‘challenge’ for everyone.

      -

      Options

      +

      Options

          ./recode -h
           usage: ./recode [options]
           -v                  display selected settings
      @@ -234,8 +237,10 @@ Again note that this does not validate input! Although it detects out of range
       for the arrays it doesn’t detect duplicates. This is because it wasn’t meant to
       be any given file or anything else other than the direct output of a previous
       run (thus validated). I’m not even guaranteeing that I got the array tests valid
      -in recode.c -R option!

      -

      Protecting against the same I/O file

      +in recode.c -R option!

      +

      Because some file systems are case-insensitive I have implemented a case-insensitive strcmp(); if the input file name is the same as the output file name I won’t write to it. From a quick test this is important particularly if @@ -245,17 +250,23 @@ This might be overprotective but I believe it better to prevent user error where possible. Of course if neither file exists it might be argued that it’s not necessary to worry since you can’t read from a file that doesn’t exist. But then what about if one exists but the other does not?

      -

      File options parser limitation

      +

      Due to the way the parsing of options is done (no spaces between option char and argument) shell expansion will not work right so for example doing:

          $ ./recode -R~/config

      will not read the file ‘config’ in the home directory. I show another way to achieve this later.

      This limitation also applies to the -f and -o options!

      -

      -R option validation?

      +

      Again the -R option does not validate input. For validation you have to run the program interactively.

      -

      Piping commands to recode

      +

      If stdin is not a tty (!isatty(0)) and neither randomised mode nor reading in from a file is specified then you might just see something like:

          $ echo testing test tests | ./recode
      @@ -272,7 +283,9 @@ from a file is specified then you might just see something like:

      In other words just the defaults. This was to simplify the problems with prompting again for input if it’s invalid (though as you’ll see it does a good job at this anyway).

      -

      Piping recode to the Enigma simulator

      +

      If you’re using recode to recode the input so you don’t have to type in the input manually (if you randomise or read in from previously saved file no input need be done at all) then make sure to redirect stderr to /dev/null. If you @@ -285,7 +298,9 @@ redirected to /dev/null it prints this out; at this point however i input. Why or how it shows the first prompt instead of later on I do not know. Anyway at this point the simulator is already expecting input to en/decipher. That’s why after I sent EOF it printed out the remaining strings to stderr.

      -

      Manually test the recode program with the Enigma program

      +
          $ cat input
           IOCCC
       
      @@ -347,7 +362,9 @@ the same output:

      Also if you flip the order of the letters in the pair e.g. the AB as BA instead:

          $ echo 1AA2AA3AA2BA..CDEFGHIJKLMNOPQRIOCCC|./prog - 2>/dev/null
           HQNVO
      -

      Only write config file

      +
          $ ./recode -v -oconfig -finput >/dev/null
           Rotors:
           (1)   I: EKMFLGDQVZNTOWYHXUSPAIBRCJ
      @@ -425,7 +442,9 @@ first one will print a newline with the echo but that won’t matter):

      the buffer remains NULL and so I don’t print it but still do print the settings file. (Actually even if getdelim() fails you’re supposed to free the buffer so I set another variable to indicate if it should be printed.)

      -

      Reusing a configuration

      +
          $ echo -n|./recode -r -oconfig
           4UH5II1RJ1SPIFEJLYGZWRTBHVCAMN$
       
      @@ -450,7 +469,9 @@ set another variable to indicate if it should be printed.)

          $ ./recode -finput.txt -Rconfig | ./prog - 2>/dev/null > output2
           $ diff output output2
           $
      -

      Write config file, read data file and pass to Enigma simulator

      +
          $ ./recode -finput.txt -oconfig | ./prog - 2>/dev/null > output
           Rotors:
           (1)   I: EKMFLGDQVZNTOWYHXUSPAIBRCJ
      @@ -501,7 +522,9 @@ does is the output:

      This is a sentence. This is another sentence.
      -

      Piping directly to the Enigma code once (with randomised settings, saved)

      +

      This is like the above only randomised:

          $ ./recode -r -oconfig|./prog - 2>/dev/null
           IOCCC
      @@ -519,17 +542,23 @@ okay:

      actual pasting to demonstrate:

          $ echo IOCCC | ./recode -R$(cat config) | ./prog - 2>/dev/null | ./recode -R2BM4GJ3HK1LNCBXWRMGKSYIAZUTPVJ | ./prog - 2>/dev/null
           IOCCC
      -

      Usage conclusion

      +

      That should give you an idea of how to use the recode program. I leave it as an exercise to the reader to implement additional features but here are some ideas of what could be done and how this entry might be used (including that delicious challenge).

      -

      Example additions

      +
        -
      • Add code (to prog.c) that tries to determine possible decipherments based on +
      • Add code (to prog.c) that tries to determine possible decipherments based on a given crib (or set of cribs).
      -

      Example uses

      +
      • Take an actual key sheet and message for that day and try and decipher the message (might help if you know German!). I haven’t actually done this for @@ -545,7 +574,9 @@ watching dry paint stay dry on a wall but why not poke fun at politicians anyway?

      • Best idea: try the below experiment!

      -

      A fun way to explore my Enigma machine, with a surprise

      +

      As I was making the above silly list something occurred to me. My other entry this year includes a recipe for a wonderful double-layered chocolate fudge diff --git a/2020/ferguson2/recode.md b/2020/ferguson2/recode.md index 7d57e87f3..ba93b15b1 100644 --- a/2020/ferguson2/recode.md +++ b/2020/ferguson2/recode.md @@ -6,8 +6,7 @@ explore my [Enigma machine](https://www.cryptomuseum.com/crypto/enigma/index.htm have to if you don't wish to. - - +

      - [What is recode and why is it recommended?](#recode) - [Options](#options) * [Protecting against the same I/O file](#samefile) @@ -24,12 +23,15 @@ have to if you don't wish to. - [Example additions](#additions) - [Example uses](#exampleuses) - [A fun way to explore my Enigma machine, with a surprise](#fun) +
      -# What is recode and why is it recommended? + -To demonstrate how to and why you should use the [recode](recode.c) program with -the [Enigma machine simulator](prog.c) I have included some examples here as +To demonstrate how to and why you should use the [recode.c](%%REPO_URL%%/2020/ferguson1/recode.c) program with +the [Enigma machine simulator](%%REPO_URL%%/2020/ferguson1/prog.c) I have included some examples here as well as brief ('brief?!' I am sure many would think but it's brief for me) commentary. @@ -53,7 +55,10 @@ with the Roman numeral, showing their actual orders etc.), the reflectors In this file I will show an example of each feature and then get to the wonderful 'challenge' for everyone. -# Options + +
      +# Options +
      ``` ./recode -h @@ -123,10 +128,12 @@ Again note that this does not validate input! Although it detects out of range for the arrays it doesn't detect duplicates. This is because it wasn't meant to be any given file or anything else other than the direct output of a previous run (thus validated). I'm not even guaranteeing that I got the array tests valid -in [recode.c](recode.c) `-R` option! +in [recode.c](%%REPO_URL%%/2020/ferguson1/recode.c) `-R` option! -## Protecting against the same I/O file + Because some file systems are case-insensitive I have implemented a case-insensitive `strcmp()`; if the input file name is the same as the output file @@ -138,7 +145,10 @@ possible. Of course if neither file exists it might be argued that it's not necessary to worry since you can't read from a file that doesn't exist. But then what about if one exists but the other does not? -## File options parser limitation + + Due to the way the parsing of options is done (no spaces between option char and argument) shell expansion will not work right so for example doing: @@ -153,12 +163,17 @@ achieve this later. This limitation also applies to the `-f` and `-o` options! -## -R option validation? + Again the `-R` option does not validate input. For validation you have to run the program interactively. -# Piping commands to recode + + If stdin is not a tty (`!isatty(0)`) and neither randomised mode nor reading in from a file is specified then you might just see something like: @@ -182,7 +197,9 @@ prompting again for input if it's invalid (though as you'll see it does a good job at this anyway). -# Piping recode to the Enigma simulator + If you're using recode to recode the input so you don't have to type in the input manually (if you randomise or read in from previously saved file no input @@ -202,8 +219,9 @@ Anyway at this point the simulator is already expecting input to en/decipher. That's why after I sent EOF it printed out the remaining strings to stderr. - -# Manually test the recode program with the Enigma program + ``` $ cat input @@ -285,7 +303,9 @@ Also if you flip the order of the letters in the pair e.g. the AB as BA instead: HQNVO ``` -# Only write config file + ``` $ ./recode -v -oconfig -finput >/dev/null @@ -378,7 +398,9 @@ the buffer remains `NULL` and so I don't print it but still do print the setting file. (Actually even if `getdelim()` fails you're supposed to free the buffer so I set another variable to indicate if it should be printed.) -# Reusing a configuration + ``` $ echo -n|./recode -r -oconfig @@ -412,7 +434,9 @@ Alternatively you can just use the `-R` and `-f` options: ``` -# Write config file, read data file and pass to Enigma simulator + ``` $ ./recode -finput.txt -oconfig | ./prog - 2>/dev/null > output @@ -473,7 +497,9 @@ does is the output: ``` -# Piping directly to the Enigma code once (with randomised settings, saved) + This is like the above only randomised: @@ -510,19 +536,27 @@ actual pasting to demonstrate: ``` -# Usage conclusion + That should give you an idea of how to use the `recode` program. I leave it as an exercise to the reader to implement additional features but here are some ideas of what could be done and how this entry might be used (including that delicious challenge). -# Example additions -* Add code (to [prog.c](prog.c)) that tries to determine possible decipherments based on + + +* Add code (to [prog.c](%%REPO_URL%%/2020/ferguson1/prog.c)) that tries to determine possible decipherments based on a given crib (or set of cribs). -# Example uses + + * Take an actual key sheet and message for that day and try and decipher the message (might help if you know German!). I haven't actually done this for @@ -541,7 +575,9 @@ anyway? * Best idea: try the below experiment! -# A fun way to explore my Enigma machine, with a surprise + As I was making the above silly list something occurred to me. My [other entry](https://www.ioccc.org/2020/ferguson1/index.html) this year includes a