add hack-a-round for language specified markdown code blocks
When language is specified in a markdown code block such as:
````
```c
printf("Hello, world!\n");
```
````
is used, the resulting HTML as produced by `pandoc(1)` combined
with our revised `ioccc.css` is not intent the code block well.
A temporary "_hack-a-round_" is to turn the "markdown code language
specifier" into an HTML comment. For example:
````
```<!---c-->
printf("Hello, world!\n");
```
````
This commits turns off existing markdown code language specifiers
for now, while preserving our ability to restore them in the future
when a better "_hack-a-round_" to the "markdown code language
specifier" problem is found.
The HTML impact if this "_hack-a-round_" is to produce HTML that
looks like this:
```
<pre class="<!---c-->"><code> .. </code></pre>
```
We might be able to create a complex set of classes for each markdown
code language (there won't be very many) in `ioccc.css`, or we might
find a more general CSS (or maybe `pandoc(1)`?) solution.
For now, this hack-a-round will have to do.
This commit is contained in:
1 parent
3919df50fb
commit
b66c79254a
700 files changed
+7052
-7056
No files matched your search
@@ -146,7 +146,7 @@ matters; I only have Intel CPUs and arm64 (MacBook Pro M1).</p>
|
||||
<p>I imagine that it works for 32-bit systems but I do not know for sure.</p>
|
||||
<h1 id="portability-macos">Portability: macOS</h1>
|
||||
<p>You should be able to get the compiler with:</p>
|
||||
<div class="sourceCode" id="cb1"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">sudo</span> xcode-select <span class="at">--install</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> sudo xcode-select --install</code></pre>
|
||||
<p>You don’t need Xcode itself and it appears that the command line tools (as above
|
||||
should install) already has ncurses so there shouldn’t be anything else that
|
||||
needs to be done. But I’m not actually sure of this - I’m seeing conflicting
|
||||
@@ -159,20 +159,20 @@ so that you don’t need sudo because … Well never mind.</p>
|
||||
you want to use the Makefile) to compile and link this entry. With Fedora more
|
||||
recent versions there’s the <code>dnf</code> package manager but I cannot help with any of
|
||||
the GUI installers since I don’t use them. Something like:</p>
|
||||
<div class="sourceCode" id="cb2"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">sudo</span> dnf install ncurses-devel ncurses make gcc</span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> sudo dnf install ncurses-devel ncurses make gcc</code></pre>
|
||||
<p>or</p>
|
||||
<div class="sourceCode" id="cb3"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a> <span class="co"># dnf install ncurses-devel ncurses make gcc</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> # dnf install ncurses-devel ncurses make gcc</code></pre>
|
||||
<h1 id="portability-centos">Portability: CentOS</h1>
|
||||
<p>Just like Fedora you will need <code>gcc</code>, <code>ncurses</code>, <code>ncurses-devel</code> (and if you
|
||||
want to use the Makefile <code>make</code>). CentOS uses <code>yum</code> and CentOS 8 uses <code>dnf</code>.
|
||||
So:</p>
|
||||
<div class="sourceCode" id="cb4"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">sudo</span> yum install ncurses-devel ncurses make gcc</span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> sudo yum install ncurses-devel ncurses make gcc</code></pre>
|
||||
<p>or</p>
|
||||
<div class="sourceCode" id="cb5"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a> <span class="co"># yum install ncurses-devel ncurses make gcc</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> # yum install ncurses-devel ncurses make gcc</code></pre>
|
||||
<p>or</p>
|
||||
<div class="sourceCode" id="cb6"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">sudo</span> dnf install ncurses-devel ncurses make gcc</span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> sudo dnf install ncurses-devel ncurses make gcc</code></pre>
|
||||
<p>or</p>
|
||||
<div class="sourceCode" id="cb7"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a> <span class="co"># dnf install ncurses-devel ncurses make gcc</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> # dnf install ncurses-devel ncurses make gcc</code></pre>
|
||||
<p>You can also use clang to compile (which is what gcc actually is under macOS).</p>
|
||||
<h1 id="compilation-notes">Compilation notes</h1>
|
||||
<p>As long as you have the dependencies above the only thing that comes to mind is
|
||||
|
||||
@@ -33,7 +33,7 @@ I imagine that it works for 32-bit systems but I do not know for sure.
|
||||
|
||||
You should be able to get the compiler with:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
sudo xcode-select --install
|
||||
```
|
||||
|
||||
@@ -53,13 +53,13 @@ you want to use the Makefile) to compile and link this entry. With Fedora more
|
||||
recent versions there's the `dnf` package manager but I cannot help with any of
|
||||
the GUI installers since I don't use them. Something like:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
sudo dnf install ncurses-devel ncurses make gcc
|
||||
```
|
||||
|
||||
or
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
# dnf install ncurses-devel ncurses make gcc
|
||||
```
|
||||
|
||||
@@ -69,25 +69,25 @@ Just like Fedora you will need `gcc`, `ncurses`, `ncurses-devel` (and if you
|
||||
want to use the Makefile `make`). CentOS uses `yum` and CentOS 8 uses `dnf`.
|
||||
So:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
sudo yum install ncurses-devel ncurses make gcc
|
||||
```
|
||||
|
||||
or
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
# yum install ncurses-devel ncurses make gcc
|
||||
```
|
||||
|
||||
or
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
sudo dnf install ncurses-devel ncurses make gcc
|
||||
```
|
||||
|
||||
or
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
# dnf install ncurses-devel ncurses make gcc
|
||||
```
|
||||
|
||||
|
||||
+33
-33
@@ -192,19 +192,19 @@ defaults if you don’t want to change the colour.</p>
|
||||
initialise a pair (make it 5 so as to not interfere with the script
|
||||
customisability) and then you use the bkgd() function with the colour pair.
|
||||
Something like this:</p>
|
||||
<div class="sourceCode" id="cb1"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a> init_pair<span class="op">(</span><span class="dv">5</span><span class="op">,</span> COLOR_BLACK<span class="op">,</span> COLOR_WHITE<span class="op">);</span></span>
|
||||
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a> bkgd<span class="op">(</span>COLOR_PAIR<span class="op">(</span><span class="dv">5</span><span class="op">));</span></span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> init_pair(5, COLOR_BLACK, COLOR_WHITE);
|
||||
bkgd(COLOR_PAIR(5));</code></pre>
|
||||
<p>I played with this after winning and I came across some problems with colours
|
||||
but that changes the background of the program anyway.</p>
|
||||
<p>The standard colour identifiers are:</p>
|
||||
<div class="sourceCode" id="cb2"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a> COLOR_BLACK</span>
|
||||
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a> COLOR_RED</span>
|
||||
<span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a> COLOR_GREEN</span>
|
||||
<span id="cb2-4"><a href="#cb2-4" aria-hidden="true" tabindex="-1"></a> COLOR_YELLOW</span>
|
||||
<span id="cb2-5"><a href="#cb2-5" aria-hidden="true" tabindex="-1"></a> COLOR_BLUE</span>
|
||||
<span id="cb2-6"><a href="#cb2-6" aria-hidden="true" tabindex="-1"></a> COLOR_MAGENTA</span>
|
||||
<span id="cb2-7"><a href="#cb2-7" aria-hidden="true" tabindex="-1"></a> COLOR_CYAN</span>
|
||||
<span id="cb2-8"><a href="#cb2-8" aria-hidden="true" tabindex="-1"></a> COLOR_WHITE</span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> COLOR_BLACK
|
||||
COLOR_RED
|
||||
COLOR_GREEN
|
||||
COLOR_YELLOW
|
||||
COLOR_BLUE
|
||||
COLOR_MAGENTA
|
||||
COLOR_CYAN
|
||||
COLOR_WHITE</code></pre>
|
||||
<p>See Linux Journal for more information article
|
||||
<a href="https://www.linuxjournal.com/content/programming-color-ncurses" class="uri">https://www.linuxjournal.com/content/programming-color-ncurses</a> for more
|
||||
details.</p>
|
||||
@@ -220,16 +220,16 @@ source code (<strong>include the single quotes!</strong>) respectively:</p>
|
||||
<p>Let’s say you don’t want to use arrow keys or you don’t have arrow keys. Instead
|
||||
you might want the keys <code>l</code>, <code>r</code>, <code>u</code> and <code>d</code> for the directions. Find the case
|
||||
statements:</p>
|
||||
<div class="sourceCode" id="cb4"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a> <span class="cf">case</span> KEY_LEFT<span class="op">:</span></span>
|
||||
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a> <span class="cf">case</span> KEY_RIGHT<span class="op">:</span></span>
|
||||
<span id="cb4-3"><a href="#cb4-3" aria-hidden="true" tabindex="-1"></a> <span class="cf">case</span> KEY_UP<span class="op">:</span></span>
|
||||
<span id="cb4-4"><a href="#cb4-4" aria-hidden="true" tabindex="-1"></a> <span class="cf">case</span> KEY_DOWN<span class="op">:</span></span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> case KEY_LEFT:
|
||||
case KEY_RIGHT:
|
||||
case KEY_UP:
|
||||
case KEY_DOWN:</code></pre>
|
||||
<p>Replace <code>KEY_LEFT</code> with:</p>
|
||||
<div class="sourceCode" id="cb5"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a> <span class="ch">'l'</span></span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> 'l'</code></pre>
|
||||
<p>and do the same thing for the other directions too. If you want more than one
|
||||
key e.g. the arrow keys and the letters just add another case statement e.g. for
|
||||
left it might be:</p>
|
||||
<div class="sourceCode" id="cb6"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a> <span class="cf">case</span> KEY_LEFT<span class="op">:</span> <span class="cf">case</span> <span class="ch">'l'</span><span class="op">:</span></span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> case KEY_LEFT: case 'l':</code></pre>
|
||||
<p>Yes the single quotes matter. You can do similar for the other input keys.
|
||||
Please note that modifier keys like ctrl aren’t detectable or at least I’m
|
||||
unaware of how to do so.</p>
|
||||
@@ -245,9 +245,9 @@ end of the game; I leave that as an exercise to the reader to implement two
|
||||
different sets. Please also be aware that if you don’t want any information you
|
||||
must set it to the below at the very least; defining it without a value is not
|
||||
enough (it amounts to the parameters to a printf call):</p>
|
||||
<div class="sourceCode" id="cb7"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a> <span class="pp">#define J </span><span class="st">" "</span><span class="pp"> </span><span class="op">);</span></span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> #define J " " );</code></pre>
|
||||
<p>If you don’t care about brief displays of ‘o’ at 0,0 you can just have:</p>
|
||||
<div class="sourceCode" id="cb8"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a> <span class="pp">#define J </span><span class="st">""</span><span class="op">);</span></span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> #define J "");</code></pre>
|
||||
<p>That’s the bare minimum. Notice also that it’s been a long while since I’ve
|
||||
tested this part but I think this is right.</p>
|
||||
<p>Anyway as I said the score line has basic statistics that’s relatively easy to
|
||||
@@ -262,7 +262,7 @@ bug. This however was something I didn’t quite like: I like having the
|
||||
coordinates of where the snake is plus the other things that are there (a number
|
||||
of which were added over time). Obviously this would take many bug sized bytes
|
||||
(bites) even once let alone twice! Thus I made it into a define:</p>
|
||||
<div class="sourceCode" id="cb9"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a> <span class="pp">#define J Z</span><span class="op">(</span><span class="pp">X</span><span class="op">:%</span><span class="pp">d</span><span class="op">/%</span><span class="pp">d Y</span><span class="op">:%</span><span class="pp">d</span><span class="op">/%</span><span class="pp">d S</span><span class="op">:%</span><span class="pp">zu</span><span class="op">/%</span><span class="pp">zu B</span><span class="op">:%</span><span class="pp">zu\n</span><span class="op">),</span><span class="pp"> Y</span><span class="op">,</span><span class="pp"> y</span><span class="op">[-</span><span class="dv">2</span><span class="op">],</span><span class="pp"> X</span><span class="op">,*</span><span class="pp">y</span><span class="op">,</span><span class="pp">A</span><span class="op">,</span><span class="pp">g</span><span class="op">,</span><span class="pp"> c</span><span class="op">);</span></span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> #define J Z(X:%d/%d Y:%d/%d S:%zu/%zu B:%zu\n), Y, y[-2], X,*y,A,g, c);</code></pre>
|
||||
<p>With the table below you can show a variety of other variables/statistics.</p>
|
||||
<p>There’s another reason for changing this line though: depending on the terminal
|
||||
width the line could cover the top wall; this can even happen only part of the
|
||||
@@ -280,7 +280,7 @@ so if this line wasn’t there it would require changes to make it work right.</
|
||||
<p>For an example this would only include the size of the snake and the number of
|
||||
bugs eaten (I think I have this correct; I’ve made many changes to the point of
|
||||
not wanting to mess with anything that’s unnecessary):</p>
|
||||
<div class="sourceCode" id="cb10"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a> <span class="pp">#define J Z</span><span class="op">(</span><span class="pp">SIZE</span><span class="op">:</span><span class="pp"> </span><span class="op">%</span><span class="pp">zu BUGS</span><span class="op">:</span><span class="pp"> </span><span class="op">%</span><span class="pp">zu\n</span><span class="op">),</span><span class="pp"> A</span><span class="op">,</span><span class="pp"> c</span><span class="op">);</span></span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> #define J Z(SIZE: %zu BUGS: %zu\n), A, c);</code></pre>
|
||||
<p>More generally the following expressions and data types (with format specifiers)
|
||||
come to mind as information that might be of interest.</p>
|
||||
<pre><code> DESCRIPTION EXPRESSION TYPE FORMAT SPECIFIER
|
||||
@@ -307,10 +307,10 @@ come to mind as information that might be of interest.</p>
|
||||
bug)</code></pre>
|
||||
<h2 id="make-it-so-the-snake-starts-at-a-random-location">Make it so the snake starts at a random location</h2>
|
||||
<p>Quite simply change:</p>
|
||||
<div class="sourceCode" id="cb12"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb12-1"><a href="#cb12-1" aria-hidden="true" tabindex="-1"></a> X <span class="op">=</span> H <span class="op">/</span> <span class="dv">2</span><span class="op">;</span> Y <span class="op">=</span> <span class="op">*</span>x <span class="op">/</span> <span class="dv">2</span><span class="op">;</span></span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> X = H / 2; Y = *x / 2;</code></pre>
|
||||
<p>To be something like:</p>
|
||||
<div class="sourceCode" id="cb13"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb13-1"><a href="#cb13-1" aria-hidden="true" tabindex="-1"></a> X <span class="op">=</span> R<span class="op">(</span><span class="dv">1</span><span class="op">,</span>H<span class="op">-</span><span class="dv">1</span><span class="op">);</span></span>
|
||||
<span id="cb13-2"><a href="#cb13-2" aria-hidden="true" tabindex="-1"></a> Y <span class="op">=</span> R<span class="op">(</span><span class="dv">2</span><span class="op">,*</span>x<span class="op">-</span><span class="dv">1</span><span class="op">);</span></span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> X = R(1,H-1);
|
||||
Y = R(2,*x-1);</code></pre>
|
||||
<p>Or whatever you might want it to be… (question to answer: will this work at
|
||||
all? You decide!)</p>
|
||||
<h1 id="additions">Additions (+)</h1>
|
||||
@@ -407,22 +407,22 @@ their ruddy phone instead of where they’re walking (even when crossing a busy
|
||||
street!).</p>
|
||||
<p>If you look at the walls code you will see a ternary operator for both <code>X</code> and <code>Y</code>
|
||||
coordinates. This of course is very different now but the idea remains the same:</p>
|
||||
<div class="sourceCode" id="cb14"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb14-1"><a href="#cb14-1" aria-hidden="true" tabindex="-1"></a> <span class="cf">if</span> <span class="op">(</span>p <span class="op">&&</span> <span class="op">!(*</span>O<span class="op">>=</span>O<span class="op">[</span><span class="dv">1</span><span class="op">]||</span>H<span class="op">>=</span>M<span class="op">(</span><span class="dv">1</span><span class="op">)))</span></span>
|
||||
<span id="cb14-2"><a href="#cb14-2" aria-hidden="true" tabindex="-1"></a> <span class="op">{</span></span>
|
||||
<span id="cb14-3"><a href="#cb14-3" aria-hidden="true" tabindex="-1"></a> <span class="cf">if</span> <span class="op">(</span>X<span class="op"><</span><span class="dv">1</span><span class="op">||</span>X<span class="op">>=</span>H<span class="op">)</span></span>
|
||||
<span id="cb14-4"><a href="#cb14-4" aria-hidden="true" tabindex="-1"></a> X <span class="op">=</span> X<span class="op"><</span><span class="dv">1</span><span class="op">?</span>H<span class="op">-</span><span class="dv">1</span><span class="op">:</span><span class="dv">1</span><span class="op">;</span></span>
|
||||
<span id="cb14-5"><a href="#cb14-5" aria-hidden="true" tabindex="-1"></a> <span class="cf">if</span> <span class="op">(</span>Y<span class="op"><</span><span class="dv">2</span><span class="op">||</span>Y<span class="op">>=*</span>O<span class="op">)</span></span>
|
||||
<span id="cb14-6"><a href="#cb14-6" aria-hidden="true" tabindex="-1"></a> Y <span class="op">=</span> Y<span class="op"><</span><span class="dv">2</span><span class="op">?*</span>O<span class="op">-</span><span class="dv">1</span><span class="op">:</span><span class="dv">2</span><span class="op">;</span></span>
|
||||
<span id="cb14-7"><a href="#cb14-7" aria-hidden="true" tabindex="-1"></a> <span class="op">}</span></span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> if (p && !(*O>=O[1]||H>=M(1)))
|
||||
{
|
||||
if (X<1||X>=H)
|
||||
X = X<1?H-1:1;
|
||||
if (Y<2||Y>=*O)
|
||||
Y = Y<2?*O-1:2;
|
||||
}</code></pre>
|
||||
<p>You can ignore the first if if you like; I’m not going to explain that part. The
|
||||
inner if statements however are testing if the new snake coordinates are beyond
|
||||
the walls (off screen). Depending on where the snake is it will set the
|
||||
coordinates to the correct new location.</p>
|
||||
<p>If however you wanted the walls to act as a barrier you could do something like
|
||||
this instead (omitting the inner if statements here):</p>
|
||||
<div class="sourceCode" id="cb15"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb15-1"><a href="#cb15-1" aria-hidden="true" tabindex="-1"></a> X<span class="op">=</span>X<span class="op"><</span><span class="dv">1</span><span class="op">?</span><span class="dv">1</span><span class="op">:*</span>H<span class="op">-</span><span class="dv">1</span><span class="op">;</span></span>
|
||||
<span id="cb15-2"><a href="#cb15-2" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb15-3"><a href="#cb15-3" aria-hidden="true" tabindex="-1"></a> Y<span class="op">=</span>Y<span class="op"><</span><span class="dv">2</span><span class="op">?</span><span class="dv">2</span><span class="op">:*</span>O<span class="op">-</span><span class="dv">1</span><span class="op">;</span></span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> X=X<1?1:*H-1;
|
||||
|
||||
Y=Y<2?2:*O-1;</code></pre>
|
||||
<p>Again though that’s just the idea; the code is dramatically different. The above
|
||||
incidentally is not even complete.</p>
|
||||
<p>You could also have it so depending on the WALLS value have it go through
|
||||
|
||||
+13
-13
@@ -78,7 +78,7 @@ initialise a pair (make it 5 so as to not interfere with the script
|
||||
customisability) and then you use the bkgd() function with the colour pair.
|
||||
Something like this:
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
init_pair(5, COLOR_BLACK, COLOR_WHITE);
|
||||
bkgd(COLOR_PAIR(5));
|
||||
```
|
||||
@@ -88,7 +88,7 @@ but that changes the background of the program anyway.
|
||||
|
||||
The standard colour identifiers are:
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
COLOR_BLACK
|
||||
COLOR_RED
|
||||
COLOR_GREEN
|
||||
@@ -124,7 +124,7 @@ Let's say you don't want to use arrow keys or you don't have arrow keys. Instead
|
||||
you might want the keys `l`, `r`, `u` and `d` for the directions. Find the case
|
||||
statements:
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
case KEY_LEFT:
|
||||
case KEY_RIGHT:
|
||||
case KEY_UP:
|
||||
@@ -133,7 +133,7 @@ statements:
|
||||
|
||||
Replace `KEY_LEFT` with:
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
'l'
|
||||
```
|
||||
|
||||
@@ -141,7 +141,7 @@ and do the same thing for the other directions too. If you want more than one
|
||||
key e.g. the arrow keys and the letters just add another case statement e.g. for
|
||||
left it might be:
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
case KEY_LEFT: case 'l':
|
||||
```
|
||||
|
||||
@@ -166,13 +166,13 @@ different sets. Please also be aware that if you don't want any information you
|
||||
must set it to the below at the very least; defining it without a value is not
|
||||
enough (it amounts to the parameters to a printf call):
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
#define J " " );
|
||||
```
|
||||
|
||||
If you don't care about brief displays of 'o' at 0,0 you can just have:
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
#define J "");
|
||||
```
|
||||
|
||||
@@ -194,7 +194,7 @@ coordinates of where the snake is plus the other things that are there (a number
|
||||
of which were added over time). Obviously this would take many bug sized bytes
|
||||
(bites) even once let alone twice! Thus I made it into a define:
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
#define J Z(X:%d/%d Y:%d/%d S:%zu/%zu B:%zu\n), Y, y[-2], X,*y,A,g, c);
|
||||
```
|
||||
|
||||
@@ -220,7 +220,7 @@ For an example this would only include the size of the snake and the number of
|
||||
bugs eaten (I think I have this correct; I've made many changes to the point of
|
||||
not wanting to mess with anything that's unnecessary):
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
#define J Z(SIZE: %zu BUGS: %zu\n), A, c);
|
||||
```
|
||||
|
||||
@@ -257,13 +257,13 @@ come to mind as information that might be of interest.
|
||||
|
||||
Quite simply change:
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
X = H / 2; Y = *x / 2;
|
||||
```
|
||||
|
||||
To be something like:
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
X = R(1,H-1);
|
||||
Y = R(2,*x-1);
|
||||
```
|
||||
@@ -395,7 +395,7 @@ street!).
|
||||
If you look at the walls code you will see a ternary operator for both `X` and `Y`
|
||||
coordinates. This of course is very different now but the idea remains the same:
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
if (p && !(*O>=O[1]||H>=M(1)))
|
||||
{
|
||||
if (X<1||X>=H)
|
||||
@@ -414,7 +414,7 @@ coordinates to the correct new location.
|
||||
If however you wanted the walls to act as a barrier you could do something like
|
||||
this instead (omitting the inner if statements here):
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
X=X<1?1:*H-1;
|
||||
|
||||
Y=Y<2?2:*O-1;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
## To build:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
make
|
||||
```
|
||||
|
||||
@@ -18,7 +18,7 @@ For more detailed information see [2020 ferguson1 bugs](../../bugs.html#2020_fer
|
||||
|
||||
## To use:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
WAIT=N WALLS=[01] EVADE=N SIZE=N MAXSIZE=N GROW=N SHEDS=N SHED=N CANNIBAL=[01] ./prog
|
||||
# start pressing some arrow keys
|
||||
```
|
||||
@@ -87,7 +87,7 @@ and non-zero).
|
||||
|
||||
## Try:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
make test
|
||||
|
||||
WAIT=75 WALLS=1 CANNIBAL=1 ./prog
|
||||
@@ -211,7 +211,7 @@ features.
|
||||
Because all IOCCC entries should have a man page I have included one (even
|
||||
though much of it is what's also above). To render try:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
man ./snake.1
|
||||
```
|
||||
|
||||
|
||||
+24
-24
@@ -141,7 +141,7 @@ like some of the other features this was not intentionally designed but is
|
||||
simply a fun consequence of the features I did implement.</p>
|
||||
<p>Let’s say you want to verify that the evade mode is at the right count. How
|
||||
can you verify it without modifying the code? Try:</p>
|
||||
<div class="sourceCode" id="cb1"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a> <span class="va">SIZE</span><span class="op">=</span>0 <span class="va">SHED</span><span class="op">=</span>1 <span class="va">SHEDS</span><span class="op">=</span>1 <span class="va">EVADE</span><span class="op">=</span>10 <span class="ex">./prog</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> SIZE=0 SHED=1 SHEDS=1 EVADE=10 ./prog</code></pre>
|
||||
<p>Since you start out at size 0 and you shed every movement then when you’re
|
||||
size 10 (as long as you don’t eat a bug of course!) the bug should evade.</p>
|
||||
<p>If you set it to <code>SIZE=10</code> there would be a difference of 10. Now every
|
||||
@@ -154,7 +154,7 @@ don’t at this time remember any I might have done.</p>
|
||||
<h1 id="the-snake-doesnt-seem-to-be-moving"><a name="stillsnake" href="#toc">The snake doesn’t seem to be moving</a></h1>
|
||||
<p>One way to show this is in full is to set the initial size and growth size to a
|
||||
high value; then try each one individually. For example:</p>
|
||||
<div class="sourceCode" id="cb2"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a> <span class="va">SIZE</span><span class="op">=</span>100 <span class="ex">./prog</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> SIZE=100 ./prog</code></pre>
|
||||
<p>In this case after you make the first move the snake will keep growing and
|
||||
so the snake tail stays in the same spot until after it’s the ‘full size’.
|
||||
When it has reached the full size then the entire body of the snake will
|
||||
@@ -201,24 +201,24 @@ way negative size will force a win.</p>
|
||||
<p>Here’s a fun output:</p>
|
||||
<pre><code> < <<<+</code></pre>
|
||||
<p>That’s from:</p>
|
||||
<div class="sourceCode" id="cb4"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a> <span class="va">SHED</span><span class="op">=</span>1 <span class="va">SHEDS</span><span class="op">=</span>-1 <span class="ex">./prog</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> SHED=1 SHEDS=-1 ./prog</code></pre>
|
||||
<p>And right after that you would see:</p>
|
||||
<pre><code> YOU WIN!
|
||||
X:72/156 Y:20/41 S:997/997 B:0</code></pre>
|
||||
<p>Try this though:</p>
|
||||
<div class="sourceCode" id="cb6"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a> <span class="va">SHEDS</span><span class="op">=</span>-1 <span class="va">SHED</span><span class="op">=</span>25 <span class="ex">./prog</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> SHEDS=-1 SHED=25 ./prog</code></pre>
|
||||
<p>And you’ll see that you start to be the normal size but then you leave your
|
||||
head several places until you end up getting to the max size (by way of it
|
||||
being unsigned). This isn’t a bug even if it might seem like one. In fact
|
||||
this is the basis of the grow/shrink mode of play that I talk about in the
|
||||
<a href="gameplay.html">gameplay.html</a> (<a href="gameplay.md">gameplay.md</a> on GitHub) file.</p>
|
||||
<p>Here’s another thing to be aware of. Let’s say you do:</p>
|
||||
<div class="sourceCode" id="cb7"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a> <span class="va">SIZE</span><span class="op">=</span>1 <span class="va">GROW</span><span class="op">=</span>-1 <span class="ex">./prog</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> SIZE=1 GROW=-1 ./prog</code></pre>
|
||||
<p>How many bugs will it take before you win? In fact it’s two: you would see the
|
||||
head twice: the second time once you ‘shrink’ down to size 0; it would then be
|
||||
that if you get another bug you will be at the ‘max size’:</p>
|
||||
<div class="sourceCode" id="cb8"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">YOU</span> WIN!</span>
|
||||
<span id="cb8-2"><a href="#cb8-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">X:81/156</span> Y:35/41 S:997/997 B:2</span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> YOU WIN!
|
||||
X:81/156 Y:35/41 S:997/997 B:2</code></pre>
|
||||
<h1 id="i-was-a-few-places-behind-my-tail-and-i-ran-into-it"><a name="bitetail" href="#toc">‘I was a few places behind my tail and I ran into it!’</a></h1>
|
||||
<p>I.e. what happens if you’re growing - for example after just eating a bug - and
|
||||
you’re racing towards your tail? If you’re behind it should be fine since you’re
|
||||
@@ -271,23 +271,23 @@ how it’s done in Snake and works well). The minimum terminal size I require in
|
||||
the game is 10 x 10. This includes the walls and score line.</p>
|
||||
<p>Now the default max snake size is 997 but when the terminal is too small it
|
||||
adjusts the max snake size. For 10 lines and 10 columns you would see:</p>
|
||||
<div class="sourceCode" id="cb12"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb12-1"><a href="#cb12-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> make test</span>
|
||||
<span id="cb12-2"><a href="#cb12-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">terminal</span> supports cursor movement</span>
|
||||
<span id="cb12-3"><a href="#cb12-3" aria-hidden="true" tabindex="-1"></a> <span class="ex">terminal</span> supports making cursor invisible</span>
|
||||
<span id="cb12-4"><a href="#cb12-4" aria-hidden="true" tabindex="-1"></a> <span class="ex">terminal</span> supports bold</span>
|
||||
<span id="cb12-5"><a href="#cb12-5" aria-hidden="true" tabindex="-1"></a> <span class="ex">terminal</span> supports colours</span>
|
||||
<span id="cb12-6"><a href="#cb12-6" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb12-7"><a href="#cb12-7" aria-hidden="true" tabindex="-1"></a> <span class="ex">terminal</span> rows 10 <span class="er">(</span><span class="ex">7</span> playable<span class="kw">)</span></span>
|
||||
<span id="cb12-8"><a href="#cb12-8" aria-hidden="true" tabindex="-1"></a> <span class="ex">terminal</span> cols 10 <span class="er">(</span><span class="ex">8</span> playable<span class="kw">)</span></span>
|
||||
<span id="cb12-9"><a href="#cb12-9" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb12-10"><a href="#cb12-10" aria-hidden="true" tabindex="-1"></a> <span class="ex">snake</span> size: 49 <span class="er">(</span><span class="ex">max</span> size: 49<span class="kw">)</span></span>
|
||||
<span id="cb12-11"><a href="#cb12-11" aria-hidden="true" tabindex="-1"></a> <span class="ex">bugs:</span> 9 <span class="er">(</span><span class="ex">max</span> size: 9<span class="kw">)</span></span>
|
||||
<span id="cb12-12"><a href="#cb12-12" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb12-13"><a href="#cb12-13" aria-hidden="true" tabindex="-1"></a> <span class="ex">at</span> least 28 columns recommended for snake size 49 <span class="er">(</span><span class="ex">is</span> 10<span class="kw">)</span></span>
|
||||
<span id="cb12-14"><a href="#cb12-14" aria-hidden="true" tabindex="-1"></a> <span class="ex">at</span> least 28 columns recommended for snake size 49 <span class="er">(</span><span class="ex">is</span> 10<span class="kw">)</span></span>
|
||||
<span id="cb12-15"><a href="#cb12-15" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb12-16"><a href="#cb12-16" aria-hidden="true" tabindex="-1"></a> <span class="ex">1</span> problem detected <span class="er">(</span><span class="ex">0</span> fatal<span class="kw">)</span><span class="bu">.</span></span>
|
||||
<span id="cb12-17"><a href="#cb12-17" aria-hidden="true" tabindex="-1"></a> <span class="ex">make:</span> <span class="pp">***</span> <span class="pp">[</span><span class="ss">test</span><span class="pp">]</span> Error 1</span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> $ make test
|
||||
terminal supports cursor movement
|
||||
terminal supports making cursor invisible
|
||||
terminal supports bold
|
||||
terminal supports colours
|
||||
|
||||
terminal rows 10 (7 playable)
|
||||
terminal cols 10 (8 playable)
|
||||
|
||||
snake size: 49 (max size: 49)
|
||||
bugs: 9 (max size: 9)
|
||||
|
||||
at least 28 columns recommended for snake size 49 (is 10)
|
||||
at least 28 columns recommended for snake size 49 (is 10)
|
||||
|
||||
1 problem detected (0 fatal).
|
||||
make: *** [test] Error 1</code></pre>
|
||||
<p>First: what’s the problem? It’s just a warning that for the snake size of 49 the
|
||||
recommended size of columns is 28. However this is just for the score text; with
|
||||
only 10 columns it will overflow and wrap to the next line(s). But if you observe
|
||||
|
||||
@@ -22,7 +22,7 @@ simply a fun consequence of the features I did implement.
|
||||
Let's say you want to verify that the evade mode is at the right count. How
|
||||
can you verify it without modifying the code? Try:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
SIZE=0 SHED=1 SHEDS=1 EVADE=10 ./prog
|
||||
```
|
||||
|
||||
@@ -44,7 +44,7 @@ don't at this time remember any I might have done.
|
||||
One way to show this is in full is to set the initial size and growth size to a
|
||||
high value; then try each one individually. For example:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
SIZE=100 ./prog
|
||||
```
|
||||
|
||||
@@ -113,7 +113,7 @@ Here's a fun output:
|
||||
|
||||
That's from:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
SHED=1 SHEDS=-1 ./prog
|
||||
```
|
||||
|
||||
@@ -126,7 +126,7 @@ And right after that you would see:
|
||||
|
||||
Try this though:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
SHEDS=-1 SHED=25 ./prog
|
||||
```
|
||||
|
||||
@@ -138,7 +138,7 @@ this is the basis of the grow/shrink mode of play that I talk about in the
|
||||
|
||||
Here's another thing to be aware of. Let's say you do:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
SIZE=1 GROW=-1 ./prog
|
||||
```
|
||||
|
||||
@@ -146,7 +146,7 @@ How many bugs will it take before you win? In fact it's two: you would see the
|
||||
head twice: the second time once you 'shrink' down to size 0; it would then be
|
||||
that if you get another bug you will be at the 'max size':
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
YOU WIN!
|
||||
X:81/156 Y:35/41 S:997/997 B:2
|
||||
```
|
||||
@@ -228,7 +228,7 @@ the game is 10 x 10. This includes the walls and score line.
|
||||
Now the default max snake size is 997 but when the terminal is too small it
|
||||
adjusts the max snake size. For 10 lines and 10 columns you would see:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
$ make test
|
||||
terminal supports cursor movement
|
||||
terminal supports making cursor invisible
|
||||
|
||||
@@ -274,7 +274,7 @@ most of them.</p>
|
||||
<h2 id="example-5-snake-moving-left-with-snake-inside-itsself">Example 5: snake moving left with snake inside itsself</h2>
|
||||
<p>Another example invocation where the snake head is in the snake and where the snake
|
||||
hadn’t yet moved (that is it was still growing):</p>
|
||||
<div class="sourceCode" id="cb6"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a> <span class="va">CANNIBAL</span><span class="op">=</span>1 <span class="va">SIZE</span><span class="op">=</span>1500 <span class="va">GROW</span><span class="op">=</span>2 <span class="va">MAXSIZE</span><span class="op">=</span>1600 <span class="ex">./prog</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> CANNIBAL=1 SIZE=1500 GROW=2 MAXSIZE=1600 ./prog</code></pre>
|
||||
<p>It looked like:</p>
|
||||
<pre><code> X:55/89 Y:11/25 S:1564/1600 B:32
|
||||
##########################################################################################
|
||||
|
||||
@@ -184,7 +184,7 @@ most of them.
|
||||
Another example invocation where the snake head is in the snake and where the snake
|
||||
hadn't yet moved (that is it was still growing):
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
CANNIBAL=1 SIZE=1500 GROW=2 MAXSIZE=1600 ./prog
|
||||
```
|
||||
|
||||
|
||||
@@ -123,7 +123,7 @@
|
||||
<!-- START: this line starts content for HTML phase 21 by: bin/pandoc-wrapper.sh via bin/md2html.sh -->
|
||||
|
||||
<p>The following are a few screen dumps of:</p>
|
||||
<div class="sourceCode" id="cb1"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a> <span class="va">SIZE</span><span class="op">=</span>100 <span class="va">SHEDS</span><span class="op">=</span>5 <span class="va">GROW</span><span class="op">=</span>-10 <span class="va">SHED</span><span class="op">=</span>50 <span class="va">MAXSIZE</span><span class="op">=</span>250 <span class="ex">./prog</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> SIZE=100 SHEDS=5 GROW=-10 SHED=50 MAXSIZE=250 ./prog</code></pre>
|
||||
<p>As you will see it took 17 bugs to get down to below 0. Notice how I had to get
|
||||
down to 0 more than once: because I moved enough times before I got the last
|
||||
bug that I grew by 5 in size. I then however moved a bit more and ate a bug
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
The following are a few screen dumps of:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
SIZE=100 SHEDS=5 GROW=-10 SHED=50 MAXSIZE=250 ./prog
|
||||
```
|
||||
|
||||
|
||||
@@ -451,9 +451,9 @@ 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
|
||||
up being > the max size though I suppose there might be some value that makes it
|
||||
less than again - I’m not going to try and figure that out however). Anyway:</p>
|
||||
<div class="sourceCode" id="cb14"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb14-1"><a href="#cb14-1" aria-hidden="true" tabindex="-1"></a> <span class="va">SIZE</span><span class="op">=</span>-1 <span class="ex">./prog</span></span>
|
||||
<span id="cb14-2"><a href="#cb14-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">YOU</span> WIN!</span>
|
||||
<span id="cb14-3"><a href="#cb14-3" aria-hidden="true" tabindex="-1"></a> <span class="ex">X:24/49</span> Y:8/16 S:658/658 B:0</span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> SIZE=-1 ./prog
|
||||
YOU WIN!
|
||||
X:24/49 Y:8/16 S:658/658 B:0</code></pre>
|
||||
<p>Observe that the size isn’t the default 997: because the screen size is too
|
||||
small for that value (see <a href="terminals.md">terminals.md</a>).</p>
|
||||
<p>The reason I chose 997 is that it leaves a bit of a challenge for some (maybe
|
||||
@@ -499,22 +499,22 @@ you have any form of epilepsy. Thank you.</strong></p>
|
||||
<p>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:</p>
|
||||
<div class="sourceCode" id="cb16"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb16-1"><a href="#cb16-1" aria-hidden="true" tabindex="-1"></a> <span class="va">WAIT</span><span class="op">=</span>-1 <span class="ex">./prog</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> WAIT=-1 ./prog</code></pre>
|
||||
<p>When you eat a bug the snake will grow and you can draw more. If you want to
|
||||
make it so you can go through yourself:</p>
|
||||
<div class="sourceCode" id="cb17"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb17-1"><a href="#cb17-1" aria-hidden="true" tabindex="-1"></a> <span class="va">WAIT</span><span class="op">=</span>-1 <span class="va">CANNIBAL</span><span class="op">=</span>1 <span class="ex">./prog</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> WAIT=-1 CANNIBAL=1 ./prog</code></pre>
|
||||
<p>If you don’t want to start out so small (i.e. you want to be able to draw more
|
||||
quickly) you can just set the size to a bigger number (and you could do the same
|
||||
with growth and moult/shed):</p>
|
||||
<div class="sourceCode" id="cb18"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb18-1"><a href="#cb18-1" aria-hidden="true" tabindex="-1"></a> <span class="va">SIZE</span><span class="op">=</span>50 <span class="va">CANNIBAL</span><span class="op">=</span>1 <span class="va">WAIT</span><span class="op">=</span>-1 <span class="ex">./prog</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> SIZE=50 CANNIBAL=1 WAIT=-1 ./prog</code></pre>
|
||||
<p>Do note that although you’re a bigger size you still grow one movement at a
|
||||
time.</p>
|
||||
<p>Okay but then if you get too many bugs the drawing will be over. If this proves
|
||||
to be a problem simply do:</p>
|
||||
<div class="sourceCode" id="cb19"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb19-1"><a href="#cb19-1" aria-hidden="true" tabindex="-1"></a> <span class="va">SIZE</span><span class="op">=</span>100 <span class="va">CANNIBAL</span><span class="op">=</span>1 <span class="va">WAIT</span><span class="op">=</span>-1 <span class="va">GROW</span><span class="op">=</span>0 <span class="ex">./prog</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> SIZE=100 CANNIBAL=1 WAIT=-1 GROW=0 ./prog</code></pre>
|
||||
<p>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</p>
|
||||
<div class="sourceCode" id="cb20"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb20-1"><a href="#cb20-1" aria-hidden="true" tabindex="-1"></a> <span class="va">MAXSIZE</span><span class="op">=</span>-1</span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> MAXSIZE=-1</code></pre>
|
||||
<p>Which I’ve done in the <a href="play.sh">play.sh</a> script.</p>
|
||||
<p>I discuss how this mode works in [spoilers.markdown][].</p>
|
||||
<p>Here’s an example run where I spelt ‘SNAKE’. As you can see it’s far from
|
||||
@@ -536,7 +536,7 @@ different colours and depending on the exact parameters you specify it could
|
||||
easily be in the trigger range for epilepsy but potentially stimulation overload
|
||||
too.</p>
|
||||
<p>If you’re still here you can create this effect like:</p>
|
||||
<div class="sourceCode" id="cb22"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb22-1"><a href="#cb22-1" aria-hidden="true" tabindex="-1"></a> <span class="va">WAIT</span><span class="op">=</span>0 <span class="va">WALLS</span><span class="op">=</span>1 <span class="va">CANNIBAL</span><span class="op">=</span>1 <span class="ex">./prog</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> WAIT=0 WALLS=1 CANNIBAL=1 ./prog</code></pre>
|
||||
<p>As long as the bug evades you’ll find that the snake is growing because it’s
|
||||
actually eating bugs; the computer is actually playing the game by itself! You
|
||||
can still move the snake though it won’t seem like you have much control over
|
||||
@@ -553,14 +553,14 @@ happen because the bug has to find a X and Y coordinate that’s not occupied an
|
||||
so with fewer available it has a harder time finding a place in that one line.</p>
|
||||
<h3 id="computer-player-variations"><a name="auto-variations" href="#toc">Computer player variations</a></h3>
|
||||
<p>Here’s how to make the bug move every time the snake moves:</p>
|
||||
<div class="sourceCode" id="cb23"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb23-1"><a href="#cb23-1" aria-hidden="true" tabindex="-1"></a> <span class="va">CANNIBAL</span><span class="op">=</span>1 <span class="va">WALLS</span><span class="op">=</span>1 <span class="va">WAIT</span><span class="op">=</span>0 <span class="va">EVADE</span><span class="op">=</span>1 <span class="ex">./prog</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> CANNIBAL=1 WALLS=1 WAIT=0 EVADE=1 ./prog</code></pre>
|
||||
<h4 id="help-the-computer-win-fairly-quickly">Help the computer win fairly quickly</h4>
|
||||
<p>If you want to see the game ‘win’ try something like:</p>
|
||||
<div class="sourceCode" id="cb24"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb24-1"><a href="#cb24-1" aria-hidden="true" tabindex="-1"></a> <span class="va">CANNIBAL</span><span class="op">=</span>1 <span class="va">WALLS</span><span class="op">=</span>1 <span class="va">WAIT</span><span class="op">=</span>0 <span class="va">EVADE</span><span class="op">=</span>1 <span class="va">MAXSIZE</span><span class="op">=</span>10 <span class="ex">./prog</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> CANNIBAL=1 WALLS=1 WAIT=0 EVADE=1 MAXSIZE=10 ./prog</code></pre>
|
||||
<h4 id="negative-growth-shrink-automatic-mode">Negative growth (Shrink) Automatic mode</h4>
|
||||
<p>Here’s a fun one I just thought of (a long time after these other modes were
|
||||
thought of):</p>
|
||||
<div class="sourceCode" id="cb25"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb25-1"><a href="#cb25-1" aria-hidden="true" tabindex="-1"></a> <span class="va">WAIT</span><span class="op">=</span>0 <span class="va">EVADE</span><span class="op">=</span>1 <span class="va">GROW</span><span class="op">=</span>-1 <span class="va">SIZE</span><span class="op">=</span>9 <span class="va">MAXSIZE</span><span class="op">=</span>10 <span class="va">CANNIBAL</span><span class="op">=</span>1 <span class="ex">./prog</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> WAIT=0 EVADE=1 GROW=-1 SIZE=9 MAXSIZE=10 CANNIBAL=1 ./prog</code></pre>
|
||||
<p>What you’ll see is that first the snake will get to the size of 9 - whether it
|
||||
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
|
||||
@@ -568,7 +568,7 @@ then the head again (i.e. 1 then 0 in size) and then win! This is also in the
|
||||
<a href="play.sh">play.sh</a> script.</p>
|
||||
<h4 id="adjusting-the-timespeed">Adjusting the time/speed</h4>
|
||||
<p>Of course you can also do something like:</p>
|
||||
<div class="sourceCode" id="cb26"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb26-1"><a href="#cb26-1" aria-hidden="true" tabindex="-1"></a> <span class="va">WAIT</span><span class="op">=</span>5 <span class="va">WALLS</span><span class="op">=</span>1 <span class="va">CANNIBAL</span><span class="op">=</span>1 <span class="ex">./prog</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> WAIT=5 WALLS=1 CANNIBAL=1 ./prog</code></pre>
|
||||
<p>Which although might not seem like it is significantly slower.</p>
|
||||
<h4 id="moving-the-snake-about-to-create-patterns">Moving the snake about to create patterns</h4>
|
||||
<p>If you press different direction keys in some pattern you will see a pattern
|
||||
@@ -578,7 +578,7 @@ suppose also how much the bug moves and the chance of being eaten also).</p>
|
||||
<p>Here’s an idea: how many moves is needed to make it possible to have some sort
|
||||
of success in catching bugs? Obviously the dimensions will affect this value.</p>
|
||||
<p>How long will it take for the snake to run into itself? For instance by doing:</p>
|
||||
<div class="sourceCode" id="cb27"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb27-1"><a href="#cb27-1" aria-hidden="true" tabindex="-1"></a> <span class="va">WAIT</span><span class="op">=</span>0 <span class="ex">./prog</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> WAIT=0 ./prog</code></pre>
|
||||
<p>On my 13” MacBook Pro (replaced later by a 16”) at the default settings going
|
||||
horizontally the snake ran into itself at:</p>
|
||||
<pre><code> OW!
|
||||
@@ -592,7 +592,7 @@ or growing to the full size directly. This is how it works:</p>
|
||||
<p>You have a negative shedding growth and a positive growth size: negative and
|
||||
positive winning. Depending on the parameters specified it might go one way over
|
||||
the other. Try:</p>
|
||||
<div class="sourceCode" id="cb29"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb29-1"><a href="#cb29-1" aria-hidden="true" tabindex="-1"></a> <span class="va">SIZE</span><span class="op">=</span>150 <span class="va">SHEDS</span><span class="op">=</span>-5 <span class="va">GROW</span><span class="op">=</span>10 <span class="va">SHED</span><span class="op">=</span>50 <span class="va">MAXSIZE</span><span class="op">=</span>250 <span class="ex">./prog</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> SIZE=150 SHEDS=-5 GROW=10 SHED=50 MAXSIZE=250 ./prog</code></pre>
|
||||
<p>What this does is set the size to 150 (to make it not go down so quickly) and
|
||||
then for each bug you eat it adds 5 to the size; for every 50 moves (that you
|
||||
don’t get the bug) you shrink by 5. You will find that at times you might only
|
||||
@@ -608,7 +608,7 @@ dumps with this idea.</p>
|
||||
<p>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 <a href="play.sh">play.sh</a>
|
||||
also has this mode:</p>
|
||||
<div class="sourceCode" id="cb30"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb30-1"><a href="#cb30-1" aria-hidden="true" tabindex="-1"></a> <span class="va">SIZE</span><span class="op">=</span>100 <span class="va">SHEDS</span><span class="op">=</span>5 <span class="va">GROW</span><span class="op">=</span>-10 <span class="va">SHED</span><span class="op">=</span>50 <span class="va">MAXSIZE</span><span class="op">=</span>250 <span class="ex">./prog</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> SIZE=100 SHEDS=5 GROW=-10 SHED=50 MAXSIZE=250 ./prog</code></pre>
|
||||
<p>Obviously there are many other variations. The <a href="play.sh">play.sh</a> 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).</p>
|
||||
@@ -622,7 +622,7 @@ typical range of seizures is 3 to 30 flashes per seconds (but can be higher) and
|
||||
that means that at <strong>EVADE=1</strong> every 231ms there will be a flash in addition to the
|
||||
snake moving too.</p>
|
||||
<p>Anyway this might sound absurd but it can be somewhat hypnotic by doing:</p>
|
||||
<div class="sourceCode" id="cb31"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb31-1"><a href="#cb31-1" aria-hidden="true" tabindex="-1"></a> <span class="va">EVADE</span><span class="op">=</span>1 <span class="va">CANNIBAL</span><span class="op">=</span>1 <span class="ex">./prog</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> EVADE=1 CANNIBAL=1 ./prog</code></pre>
|
||||
<p>And just moving the snake about not trying to catch any bugs - just let whatever
|
||||
happens happen.</p>
|
||||
<h2 id="gameplay-mode-stimulation-calming-mode"><a name="stim" href="#toc">Gameplay mode: Stimulation / Calming mode</a></h2>
|
||||
@@ -631,7 +631,7 @@ 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:</p>
|
||||
<div class="sourceCode" id="cb32"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb32-1"><a href="#cb32-1" aria-hidden="true" tabindex="-1"></a> <span class="va">GROW</span><span class="op">=</span>0 <span class="va">CANNIBAL</span><span class="op">=</span>1 <span class="ex">./prog</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> GROW=0 CANNIBAL=1 ./prog</code></pre>
|
||||
<h2 id="gameplay-mode-expansibility"><a name="expansibility" href="#toc">Gameplay mode: Expansibility</a></h2>
|
||||
<p>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.
|
||||
@@ -650,9 +650,9 @@ reason as well as I simply enjoy it and thinking up new modes.</p>
|
||||
this file discusses as well as allowing to easily change the colours.</p>
|
||||
<h2 id="colours-selection-snake-colours"><a name="colours" href="#toc">Colours selection: snake-colours</a></h2>
|
||||
<p>To do this use the <a href="snake-colours">snake-colours</a> script like so:</p>
|
||||
<div class="sourceCode" id="cb33"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb33-1"><a href="#cb33-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./snake-colours</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> ./snake-colours</code></pre>
|
||||
<p>If you want to pass in specific variables you can do that too e.g.:</p>
|
||||
<div class="sourceCode" id="cb34"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb34-1"><a href="#cb34-1" aria-hidden="true" tabindex="-1"></a> <span class="va">CANNIBAL</span><span class="op">=</span>1 <span class="ex">./snake-colours</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> CANNIBAL=1 ./snake-colours</code></pre>
|
||||
<p>The script will prompt you for the colour of the walls, snake head, body and the
|
||||
bug.</p>
|
||||
<h2 id="automate-the-above-gameplay-modes"><a name="preset" href="#toc">Automate the above gameplay modes</a></h2>
|
||||
@@ -664,9 +664,9 @@ snake-colours 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.</p>
|
||||
<p>To use you can do something like:</p>
|
||||
<div class="sourceCode" id="cb35"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb35-1"><a href="#cb35-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./play.sh</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> ./play.sh</code></pre>
|
||||
<p>Or to make it so walls are an obstacle:</p>
|
||||
<div class="sourceCode" id="cb36"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb36-1"><a href="#cb36-1" aria-hidden="true" tabindex="-1"></a> <span class="va">WALLS</span><span class="op">=</span>0 <span class="ex">./play.sh</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> WALLS=0 ./play.sh</code></pre>
|
||||
<h1 id="notes-about-some-of-the-game-variables">6. <a name="variables" href="#toc">Notes about some of the game variables</a></h1>
|
||||
<p>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.</p>
|
||||
|
||||
+20
-20
@@ -415,7 +415,7 @@ default) or setting the size to higher than the default (or < 0 which will end
|
||||
up being > the max size though I suppose there might be some value that makes it
|
||||
less than again - I'm not going to try and figure that out however). Anyway:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
SIZE=-1 ./prog
|
||||
YOU WIN!
|
||||
X:24/49 Y:8/16 S:658/658 B:0
|
||||
@@ -487,7 +487,7 @@ 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:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
WAIT=-1 ./prog
|
||||
```
|
||||
|
||||
@@ -495,7 +495,7 @@ does not move until you press a movement key. For example:
|
||||
When you eat a bug the snake will grow and you can draw more. If you want to
|
||||
make it so you can go through yourself:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
WAIT=-1 CANNIBAL=1 ./prog
|
||||
```
|
||||
|
||||
@@ -503,7 +503,7 @@ If you don't want to start out so small (i.e. you want to be able to draw more
|
||||
quickly) you can just set the size to a bigger number (and you could do the same
|
||||
with growth and moult/shed):
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
SIZE=50 CANNIBAL=1 WAIT=-1 ./prog
|
||||
```
|
||||
|
||||
@@ -513,14 +513,14 @@ time.
|
||||
Okay but then if you get too many bugs the drawing will be over. If this proves
|
||||
to be a problem simply do:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
SIZE=100 CANNIBAL=1 WAIT=-1 GROW=0 ./prog
|
||||
```
|
||||
|
||||
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
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
MAXSIZE=-1
|
||||
```
|
||||
|
||||
@@ -556,7 +556,7 @@ too.
|
||||
|
||||
If you're still here you can create this effect like:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
WAIT=0 WALLS=1 CANNIBAL=1 ./prog
|
||||
```
|
||||
|
||||
@@ -582,7 +582,7 @@ so with fewer available it has a harder time finding a place in that one line.
|
||||
|
||||
Here's how to make the bug move every time the snake moves:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
CANNIBAL=1 WALLS=1 WAIT=0 EVADE=1 ./prog
|
||||
```
|
||||
|
||||
@@ -591,7 +591,7 @@ Here's how to make the bug move every time the snake moves:
|
||||
|
||||
If you want to see the game 'win' try something like:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
CANNIBAL=1 WALLS=1 WAIT=0 EVADE=1 MAXSIZE=10 ./prog
|
||||
```
|
||||
|
||||
@@ -601,7 +601,7 @@ If you want to see the game 'win' try something like:
|
||||
Here's a fun one I just thought of (a long time after these other modes were
|
||||
thought of):
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
WAIT=0 EVADE=1 GROW=-1 SIZE=9 MAXSIZE=10 CANNIBAL=1 ./prog
|
||||
```
|
||||
|
||||
@@ -616,7 +616,7 @@ then the head again (i.e. 1 then 0 in size) and then win! This is also in the
|
||||
|
||||
Of course you can also do something like:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
WAIT=5 WALLS=1 CANNIBAL=1 ./prog
|
||||
```
|
||||
|
||||
@@ -635,7 +635,7 @@ of success in catching bugs? Obviously the dimensions will affect this value.
|
||||
|
||||
How long will it take for the snake to run into itself? For instance by doing:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
WAIT=0 ./prog
|
||||
```
|
||||
|
||||
@@ -660,7 +660,7 @@ You have a negative shedding growth and a positive growth size: negative and
|
||||
positive winning. Depending on the parameters specified it might go one way over
|
||||
the other. Try:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
SIZE=150 SHEDS=-5 GROW=10 SHED=50 MAXSIZE=250 ./prog
|
||||
```
|
||||
|
||||
@@ -683,7 +683,7 @@ 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][]
|
||||
also has this mode:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
SIZE=100 SHEDS=5 GROW=-10 SHED=50 MAXSIZE=250 ./prog
|
||||
```
|
||||
|
||||
@@ -705,7 +705,7 @@ snake moving too.
|
||||
|
||||
Anyway this might sound absurd but it can be somewhat hypnotic by doing:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
EVADE=1 CANNIBAL=1 ./prog
|
||||
```
|
||||
|
||||
@@ -721,7 +721,7 @@ 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:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
GROW=0 CANNIBAL=1 ./prog
|
||||
```
|
||||
|
||||
@@ -752,13 +752,13 @@ this file discusses as well as allowing to easily change the colours.
|
||||
|
||||
To do this use the [snake-colours][] script like so:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
./snake-colours
|
||||
```
|
||||
|
||||
If you want to pass in specific variables you can do that too e.g.:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
CANNIBAL=1 ./snake-colours
|
||||
```
|
||||
|
||||
@@ -777,13 +777,13 @@ you choose uses then the script will override what you pass in.
|
||||
|
||||
To use you can do something like:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
./play.sh
|
||||
```
|
||||
|
||||
Or to make it so walls are an obstacle:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
WALLS=0 ./play.sh
|
||||
```
|
||||
|
||||
|
||||
+23
-23
@@ -141,14 +141,14 @@ Location: <a href="../../location.html#US">US</a> - <em>United States of America
|
||||
<!-- START: this line starts content for HTML phase 21 by: bin/pandoc-wrapper.sh via bin/md2html.sh -->
|
||||
|
||||
<h2 id="to-build">To build:</h2>
|
||||
<div class="sourceCode" id="cb1"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">make</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> make</code></pre>
|
||||
<h3 id="bugs-and-misfeatures">Bugs and (Mis)features:</h3>
|
||||
<p>The current status of this entry is:</p>
|
||||
<pre><code> STATUS: INABIAF - please **DO NOT** fix</code></pre>
|
||||
<p>For more detailed information see <a href="../../bugs.html#2020_ferguson1">2020 ferguson1 bugs</a>.</p>
|
||||
<h2 id="to-use">To use:</h2>
|
||||
<div class="sourceCode" id="cb3"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a> <span class="va">WAIT</span><span class="op">=</span>N <span class="va">WALLS</span><span class="op">=</span><span class="pp">[</span><span class="ss">01</span><span class="pp">]</span> <span class="va">EVADE</span><span class="op">=</span>N <span class="va">SIZE</span><span class="op">=</span>N <span class="va">MAXSIZE</span><span class="op">=</span>N <span class="va">GROW</span><span class="op">=</span>N <span class="va">SHEDS</span><span class="op">=</span>N <span class="va">SHED</span><span class="op">=</span>N <span class="va">CANNIBAL</span><span class="op">=</span><span class="pp">[</span><span class="ss">01</span><span class="pp">]</span> <span class="ex">./prog</span></span>
|
||||
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a> <span class="co"># start pressing some arrow keys</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> WAIT=N WALLS=[01] EVADE=N SIZE=N MAXSIZE=N GROW=N SHEDS=N SHED=N CANNIBAL=[01] ./prog
|
||||
# start pressing some arrow keys</code></pre>
|
||||
<p>where <code>N</code> is a number and <code>[01]</code> is either <code>1</code> or <code>0</code> (or more correctly zero
|
||||
and non-zero).</p>
|
||||
<h3 id="variables">Variables:</h3>
|
||||
@@ -202,25 +202,25 @@ whether you can go through the Snake or not. Default is 0
|
||||
(cannot - die if you try).</p></li>
|
||||
</ul>
|
||||
<h2 id="try">Try:</h2>
|
||||
<div class="sourceCode" id="cb4"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">make</span> test</span>
|
||||
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb4-3"><a href="#cb4-3" aria-hidden="true" tabindex="-1"></a> <span class="va">WAIT</span><span class="op">=</span>75 <span class="va">WALLS</span><span class="op">=</span>1 <span class="va">CANNIBAL</span><span class="op">=</span>1 <span class="ex">./prog</span></span>
|
||||
<span id="cb4-4"><a href="#cb4-4" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb4-5"><a href="#cb4-5" aria-hidden="true" tabindex="-1"></a> <span class="ex">./prog</span></span>
|
||||
<span id="cb4-6"><a href="#cb4-6" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb4-7"><a href="#cb4-7" aria-hidden="true" tabindex="-1"></a> <span class="va">SIZE</span><span class="op">=</span>-1 <span class="ex">./prog</span></span>
|
||||
<span id="cb4-8"><a href="#cb4-8" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb4-9"><a href="#cb4-9" aria-hidden="true" tabindex="-1"></a> <span class="va">CANNIBAL</span><span class="op">=</span>1 <span class="va">WALLS</span><span class="op">=</span>1 <span class="va">WAIT</span><span class="op">=</span>50 <span class="va">EVADE</span><span class="op">=</span>200 <span class="ex">./prog</span></span>
|
||||
<span id="cb4-10"><a href="#cb4-10" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb4-11"><a href="#cb4-11" aria-hidden="true" tabindex="-1"></a> <span class="va">WAIT</span><span class="op">=</span>75 <span class="va">GROW</span><span class="op">=</span>-1 <span class="va">SIZE</span><span class="op">=</span>5 <span class="va">CANNIBAL</span><span class="op">=</span>1 <span class="ex">./prog</span></span>
|
||||
<span id="cb4-12"><a href="#cb4-12" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb4-13"><a href="#cb4-13" aria-hidden="true" tabindex="-1"></a> <span class="va">CANNIBAL</span><span class="op">=</span>1 <span class="va">WALLS</span><span class="op">=</span>1 <span class="va">WAIT</span><span class="op">=</span>0 <span class="va">EVADE</span><span class="op">=</span>1 <span class="va">MAXSIZE</span><span class="op">=</span>10 <span class="ex">./prog</span></span>
|
||||
<span id="cb4-14"><a href="#cb4-14" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb4-15"><a href="#cb4-15" aria-hidden="true" tabindex="-1"></a> <span class="ex">./play</span></span>
|
||||
<span id="cb4-16"><a href="#cb4-16" aria-hidden="true" tabindex="-1"></a> <span class="co"># allows you to configure colours and has various pre-configured gameplay modes</span></span>
|
||||
<span id="cb4-17"><a href="#cb4-17" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb4-18"><a href="#cb4-18" aria-hidden="true" tabindex="-1"></a> <span class="ex">./snake-colours</span></span>
|
||||
<span id="cb4-19"><a href="#cb4-19" aria-hidden="true" tabindex="-1"></a> <span class="co"># allows for configuring colours</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> make test
|
||||
|
||||
WAIT=75 WALLS=1 CANNIBAL=1 ./prog
|
||||
|
||||
./prog
|
||||
|
||||
SIZE=-1 ./prog
|
||||
|
||||
CANNIBAL=1 WALLS=1 WAIT=50 EVADE=200 ./prog
|
||||
|
||||
WAIT=75 GROW=-1 SIZE=5 CANNIBAL=1 ./prog
|
||||
|
||||
CANNIBAL=1 WALLS=1 WAIT=0 EVADE=1 MAXSIZE=10 ./prog
|
||||
|
||||
./play
|
||||
# allows you to configure colours and has various pre-configured gameplay modes
|
||||
|
||||
./snake-colours
|
||||
# allows for configuring colours</code></pre>
|
||||
<h2 id="judges-remarks">Judges’ remarks:</h2>
|
||||
<p>As the <a href="https://en.wikipedia.org/wiki/Gadsden_flag">Gadsden flag</a> warns, beware of the snake!
|
||||
This game has a number of configurable pitfalls including walls and snakes.</p>
|
||||
@@ -306,7 +306,7 @@ look like bugs but aren’t as well as documenting a built-in test unit for some
|
||||
features.</p>
|
||||
<p>Because all IOCCC entries should have a man page I have included one (even
|
||||
though much of it is what’s also above). To render try:</p>
|
||||
<div class="sourceCode" id="cb5"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">man</span> ./snake.1</span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> man ./snake.1</code></pre>
|
||||
<p>The <a href="COMPILING.html">COMPILING.html</a> file has a few portability
|
||||
notes and the <a href="HACKING.html">HACKING.html</a> file has some
|
||||
information on how one might modify things, things that could be implemented
|
||||
|
||||
@@ -762,9 +762,9 @@ returning <code>E()</code> I am returning 1 but if the end of main() is reached
|
||||
returned. In either case curses is ended.</p>
|
||||
<p>One of these optimisations saved four bytes simply by taking advantage of the
|
||||
value of a loop iterator after the loop. The loop is:</p>
|
||||
<div class="sourceCode" id="cb27"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb27-1"><a href="#cb27-1" aria-hidden="true" tabindex="-1"></a> <span class="cf">for</span> <span class="op">(</span>I <span class="op">=</span> <span class="dv">0</span><span class="op">;</span> A <span class="op">&&</span> I <span class="op"><</span> A <span class="op">-</span> <span class="dv">1</span><span class="op">;</span> <span class="op">++</span>I<span class="op">)</span></span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> for (I = 0; A && I < A - 1; ++I)</code></pre>
|
||||
<p>However after the loop I had this:</p>
|
||||
<div class="sourceCode" id="cb28"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb28-1"><a href="#cb28-1" aria-hidden="true" tabindex="-1"></a> A <span class="op">></span> <span class="dv">1</span> <span class="op">&&</span> q<span class="op">(</span>n<span class="op">[</span>A <span class="op">-</span> <span class="dv">1</span><span class="op">],</span>e<span class="op">[</span>A <span class="op">-</span> <span class="dv">1</span><span class="op">],</span> <span class="ch">'o'</span><span class="op">);</span></span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> A > 1 && q(n[A - 1],e[A - 1], 'o');</code></pre>
|
||||
<p>When I was considering moving that line to before the loop it occurred to me
|
||||
that as long as <code>A > 0</code> then <code>A - 1 == I</code> after the loop. I still had to check
|
||||
for <code>A > 1</code> but I could refer to just <code>I</code> instead of <code>A - 1</code>!</p>
|
||||
@@ -779,31 +779,31 @@ place at this point) I was looking at the code to see if I could figure out how
|
||||
to save even more bytes. Here are some that I found interesting ways to go about
|
||||
the problem.</p>
|
||||
<p>First, the function that turns on colours looked like:</p>
|
||||
<div class="sourceCode" id="cb29"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb29-1"><a href="#cb29-1" aria-hidden="true" tabindex="-1"></a> <span class="cf">if</span> <span class="op">(</span>h<span class="op">)</span> attron<span class="op">(</span>m<span class="op">(</span>PAIR<span class="op">(</span>L<span class="op">)));</span></span>
|
||||
<span id="cb29-2"><a href="#cb29-2" aria-hidden="true" tabindex="-1"></a> <span class="cf">else</span> attroff<span class="op">(</span>m<span class="op">(</span>PAIR<span class="op">(</span>L<span class="op">)));</span></span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> if (h) attron(m(PAIR(L)));
|
||||
else attroff(m(PAIR(L)));</code></pre>
|
||||
<p>But I thought is that else actually needed? If I were to switch the order so
|
||||
that the <code>attroff()</code> is called first then I could just do an <code>if (h)</code> -
|
||||
therefore getting rid of the <code>else</code>! But then I thought why not do what I’ve
|
||||
done elsewhere? I had:</p>
|
||||
<div class="sourceCode" id="cb30"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb30-1"><a href="#cb30-1" aria-hidden="true" tabindex="-1"></a> attroff<span class="op">(</span>m<span class="op">(</span>PAIR<span class="op">(</span>L<span class="op">)));</span></span>
|
||||
<span id="cb30-2"><a href="#cb30-2" aria-hidden="true" tabindex="-1"></a> <span class="cf">if</span> <span class="op">(</span>h<span class="op">)</span> attron<span class="op">(</span>m<span class="op">(</span>PAIR<span class="op">(</span>L<span class="op">)));</span></span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> attroff(m(PAIR(L)));
|
||||
if (h) attron(m(PAIR(L)));</code></pre>
|
||||
<p>But I then saved an extra byte by making it:</p>
|
||||
<div class="sourceCode" id="cb31"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb31-1"><a href="#cb31-1" aria-hidden="true" tabindex="-1"></a> attroff<span class="op">(</span>m<span class="op">(</span>PAIR<span class="op">(</span>L<span class="op">)));</span></span>
|
||||
<span id="cb31-2"><a href="#cb31-2" aria-hidden="true" tabindex="-1"></a> h <span class="op">&&</span> attron<span class="op">(</span>m<span class="op">(</span>PAIR<span class="op">(</span>L<span class="op">)));</span></span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> attroff(m(PAIR(L)));
|
||||
h && attron(m(PAIR(L)));</code></pre>
|
||||
<p>That saved two bytes.</p>
|
||||
<p>Second let’s look at the <code>B()</code> function: there were two things I thought of that
|
||||
would save some bytes (I no longer know how many but a few at least possibly six
|
||||
or even more). I had the following code:</p>
|
||||
<div class="sourceCode" id="cb32"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb32-1"><a href="#cb32-1" aria-hidden="true" tabindex="-1"></a> <span class="cf">if</span> <span class="op">(</span>V <span class="op">&&</span> U <span class="op">&&</span> o<span class="op">)</span> <span class="op">{</span> S<span class="op">(</span>N<span class="op">);</span> b<span class="op">(</span><span class="dv">1</span><span class="op">);</span> <span class="op">}</span></span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> if (V && U && o) { S(N); b(1); }</code></pre>
|
||||
<p>This made sure that only if the snake has caught a bug should it grow by the
|
||||
growth size and increase the bug count. But was checking for the <code>V</code> or <code>U</code>
|
||||
necessary? I gave it a look over and it occurred to me: the only time <code>B()</code> is
|
||||
called with <code>1</code> (thus <code>o</code> is 1 so the if is true) was if the bug actually is
|
||||
caught. That means I could remove the <code>V && U &&</code> part of the if! Thus it became
|
||||
instead:</p>
|
||||
<div class="sourceCode" id="cb33"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb33-1"><a href="#cb33-1" aria-hidden="true" tabindex="-1"></a> <span class="cf">if</span> <span class="op">(</span>o<span class="op">)</span> <span class="op">{</span> S<span class="op">(</span>N<span class="op">);</span> b<span class="op">(</span><span class="dv">1</span><span class="op">);</span> <span class="op">}</span></span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> if (o) { S(N); b(1); }</code></pre>
|
||||
<p>Then this</p>
|
||||
<div class="sourceCode" id="cb34"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb34-1"><a href="#cb34-1" aria-hidden="true" tabindex="-1"></a> <span class="op">!</span>o <span class="op">&&</span> V <span class="op">&&</span> U <span class="op">&&</span> q U<span class="op">,</span>V<span class="op">,</span><span class="ch">' '</span><span class="op">);</span></span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> !o && V && U && q U,V,' ');</code></pre>
|
||||
<p>…is to make sure to only clear the spot the bug is (or was) at if
|
||||
the bug was NOT eaten. Why not eaten? Because if it was eaten it means the
|
||||
snake’s head will be there!</p>
|
||||
@@ -818,7 +818,7 @@ unfortunately the snake has to be placed first since the bug cannot be placed
|
||||
where the snake already is. So if I had to make sure the game had started (the
|
||||
snake has moved at least once) what could I check? In fact that means the
|
||||
direction is not 0! So I could just replace it with:</p>
|
||||
<div class="sourceCode" id="cb35"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb35-1"><a href="#cb35-1" aria-hidden="true" tabindex="-1"></a> <span class="op">!</span>o <span class="op">&&</span> D <span class="op">&&</span> q <span class="op">*</span>U<span class="op">,*</span>V<span class="op">,</span><span class="ch">' '</span><span class="op">);</span></span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> !o && D && q *U,*V,' ');</code></pre>
|
||||
<p>That reduced the count further. But then I wondered if even that much is needed.
|
||||
The condition is that the bug has evaded which means the snake has moved already
|
||||
(so game started). What calls to this function happen before the game starts
|
||||
@@ -831,7 +831,7 @@ to check for is that <code>!o</code>: because after this call before the game ev
|
||||
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:</p>
|
||||
<div class="sourceCode" id="cb36"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb36-1"><a href="#cb36-1" aria-hidden="true" tabindex="-1"></a> <span class="op">!</span>o <span class="op">&&</span> q <span class="op">*</span>U<span class="op">,*</span>V<span class="op">,</span><span class="ch">' '</span><span class="op">);</span></span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> !o && q *U,*V,' ');</code></pre>
|
||||
<p>Technically it would be a <code>" "</code> (see <a href="HACKING.html">HACKING.html</a> or on GitHub
|
||||
<a href="HACKING.md">HACKING.md</a>) 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.
|
||||
|
||||
+10
-10
@@ -818,13 +818,13 @@ returned. In either case curses is ended.
|
||||
One of these optimisations saved four bytes simply by taking advantage of the
|
||||
value of a loop iterator after the loop. The loop is:
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
for (I = 0; A && I < A - 1; ++I)
|
||||
```
|
||||
|
||||
However after the loop I had this:
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
A > 1 && q(n[A - 1],e[A - 1], 'o');
|
||||
```
|
||||
|
||||
@@ -847,7 +847,7 @@ the problem.
|
||||
|
||||
First, the function that turns on colours looked like:
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
if (h) attron(m(PAIR(L)));
|
||||
else attroff(m(PAIR(L)));
|
||||
```
|
||||
@@ -857,14 +857,14 @@ that the `attroff()` is called first then I could just do an `if (h)` -
|
||||
therefore getting rid of the `else`! But then I thought why not do what I've
|
||||
done elsewhere? I had:
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
attroff(m(PAIR(L)));
|
||||
if (h) attron(m(PAIR(L)));
|
||||
```
|
||||
|
||||
But I then saved an extra byte by making it:
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
attroff(m(PAIR(L)));
|
||||
h && attron(m(PAIR(L)));
|
||||
```
|
||||
@@ -875,7 +875,7 @@ Second let's look at the `B()` function: there were two things I thought of that
|
||||
would save some bytes (I no longer know how many but a few at least possibly six
|
||||
or even more). I had the following code:
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
if (V && U && o) { S(N); b(1); }
|
||||
```
|
||||
|
||||
@@ -886,13 +886,13 @@ called with `1` (thus `o` is 1 so the if is true) was if the bug actually is
|
||||
caught. That means I could remove the `V && U &&` part of the if! Thus it became
|
||||
instead:
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
if (o) { S(N); b(1); }
|
||||
```
|
||||
|
||||
Then this
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
!o && V && U && q U,V,' ');
|
||||
```
|
||||
|
||||
@@ -913,7 +913,7 @@ where the snake already is. So if I had to make sure the game had started (the
|
||||
snake has moved at least once) what could I check? In fact that means the
|
||||
direction is not 0! So I could just replace it with:
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
!o && D && q *U,*V,' ');
|
||||
```
|
||||
|
||||
@@ -930,7 +930,7 @@ 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:
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
!o && q *U,*V,' ');
|
||||
```
|
||||
|
||||
|
||||
@@ -151,7 +151,7 @@ movement is required) I have provided a source file that can test your terminal
|
||||
for the capabilities I use in the entry.</p>
|
||||
<p>It also tries to determine the minimum number of columns to play without the
|
||||
status line overflowing - even with the dynamic length. Try:</p>
|
||||
<div class="sourceCode" id="cb1"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> make test</span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> $ make test</code></pre>
|
||||
<p>This compiles the program <a href="termcaps.c">termcaps.c</a> and runs it; you should see something like:</p>
|
||||
<pre><code> terminal supports cursor movement
|
||||
terminal supports making cursor invisible
|
||||
@@ -178,21 +178,21 @@ maximum (capped) snake size.</p>
|
||||
<p>If I pass in any of the variables <strong>GROW</strong>, <strong>MAXSIZE</strong>, <strong>SIZE</strong> and/or
|
||||
<strong>LINES</strong> or <strong>COLUMNS</strong> it bases its calculations on those variables. For
|
||||
example:</p>
|
||||
<div class="sourceCode" id="cb3"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">terminal</span> supports cursor movement</span>
|
||||
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">terminal</span> supports making cursor invisible</span>
|
||||
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a> <span class="ex">terminal</span> supports bold</span>
|
||||
<span id="cb3-4"><a href="#cb3-4" aria-hidden="true" tabindex="-1"></a> <span class="ex">terminal</span> supports colours</span>
|
||||
<span id="cb3-5"><a href="#cb3-5" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb3-6"><a href="#cb3-6" aria-hidden="true" tabindex="-1"></a> <span class="ex">terminal</span> rows 41 <span class="er">(</span><span class="ex">38</span> playable<span class="kw">)</span></span>
|
||||
<span id="cb3-7"><a href="#cb3-7" aria-hidden="true" tabindex="-1"></a> <span class="ex">terminal</span> cols 155 <span class="er">(</span><span class="ex">153</span> playable<span class="kw">)</span></span>
|
||||
<span id="cb3-8"><a href="#cb3-8" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb3-9"><a href="#cb3-9" aria-hidden="true" tabindex="-1"></a> <span class="ex">snake</span> size: 5776 <span class="er">(</span><span class="ex">max</span> size: 5776<span class="kw">)</span></span>
|
||||
<span id="cb3-10"><a href="#cb3-10" aria-hidden="true" tabindex="-1"></a> <span class="ex">bugs:</span> 5771 <span class="er">(</span><span class="ex">max</span> size: 5771<span class="kw">)</span></span>
|
||||
<span id="cb3-11"><a href="#cb3-11" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb3-12"><a href="#cb3-12" aria-hidden="true" tabindex="-1"></a> <span class="ex">at</span> least 37 columns <span class="er">(</span><span class="ex">currently</span> 155<span class="kw">)</span> <span class="ex">recommended</span> for snake size 5776</span>
|
||||
<span id="cb3-13"><a href="#cb3-13" aria-hidden="true" tabindex="-1"></a> <span class="ex">at</span> least 37 columns <span class="er">(</span><span class="ex">currently</span> 155<span class="kw">)</span> <span class="ex">recommended</span> for capped snake size 5776</span>
|
||||
<span id="cb3-14"><a href="#cb3-14" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb3-15"><a href="#cb3-15" aria-hidden="true" tabindex="-1"></a> <span class="ex">No</span> problems detected.</span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> terminal supports cursor movement
|
||||
terminal supports making cursor invisible
|
||||
terminal supports bold
|
||||
terminal supports colours
|
||||
|
||||
terminal rows 41 (38 playable)
|
||||
terminal cols 155 (153 playable)
|
||||
|
||||
snake size: 5776 (max size: 5776)
|
||||
bugs: 5771 (max size: 5771)
|
||||
|
||||
at least 37 columns (currently 155) recommended for snake size 5776
|
||||
at least 37 columns (currently 155) recommended for capped snake size 5776
|
||||
|
||||
No problems detected.</code></pre>
|
||||
<p>As you can see it tells you the max size (the ‘capsized’ snake) as well as the
|
||||
requested max size (if the requested size is bigger than the capped size then it
|
||||
will be set to that value instead) of the snake. The capped size is like in the
|
||||
@@ -224,12 +224,12 @@ resize the window with first. But what if you want exacts?</p>
|
||||
<p>To specify the lines/columns of curses program per instance use the <code>LINES</code> and
|
||||
<code>COLUMNS</code> environmental variables.</p>
|
||||
<p>For demonstration consider the following:</p>
|
||||
<div class="sourceCode" id="cb4"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> echo <span class="va">$LINES</span> <span class="va">$COLUMNS</span></span>
|
||||
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">42</span> 157</span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> $ echo $LINES $COLUMNS
|
||||
42 157</code></pre>
|
||||
<p>Note: I subtract 1 from the max y/x and the max coords in the game output
|
||||
include the walls and score line but these values are for the terminal itself.</p>
|
||||
<p>Say you want 55 columns:</p>
|
||||
<div class="sourceCode" id="cb5"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> COLUMNS=55 ./prog</span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> $ COLUMNS=55 ./prog</code></pre>
|
||||
<p>This will force curses to detect the max columns (X) of your terminal (for the
|
||||
game dimensions) - to be 55; it might look like this instead:</p>
|
||||
<pre><code> X:27/54 Y:20/41 S:5/997 B:0</code></pre>
|
||||
@@ -245,8 +245,8 @@ etc. For the game you might not see the final score.</p>
|
||||
<p>In my tests there is one thing that at least allows you to see the final score
|
||||
and that is by running <code>clear</code> before running the program. That’s what the
|
||||
prog.alt version does. You might run it as one of:</p>
|
||||
<div class="sourceCode" id="cb7"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a> <span class="va">LINES</span><span class="op">=</span>20 <span class="ex">./prog.alt</span></span>
|
||||
<span id="cb7-2"><a href="#cb7-2" aria-hidden="true" tabindex="-1"></a> <span class="va">LINES</span><span class="op">=</span>20 <span class="ex">./snake.alt</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> LINES=20 ./prog.alt
|
||||
LINES=20 ./snake.alt</code></pre>
|
||||
<p>Even if the final score is visible though the terminal may very well still be
|
||||
messed up. There are numerous things you might try but probably the easiest is
|
||||
to run the game again without modifying the dimensions (and then just quit) or
|
||||
@@ -259,7 +259,7 @@ even just the <code>reset</code> command.</p>
|
||||
(the line-feed character is normally control-J) to get the terminal
|
||||
to work, as carriage-return may no longer work in the abnormal state.</code></pre>
|
||||
<p>If you don’t have the reset utility you can try:</p>
|
||||
<div class="sourceCode" id="cb9"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a> <span class="bu">echo</span> <span class="at">-e</span> <span class="dt">\\</span>033c</span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> echo -e \\033c</code></pre>
|
||||
<p>Otherwise try <code>clear; stty sane</code> (that will turn on echo also) or if all else
|
||||
fails log out and back in.</p>
|
||||
<p>For more information on this subject generally see the <a href="https://www.tldp.org/HOWTO/Keyboard-and-Console-HOWTO.html">Linux keyboard and
|
||||
@@ -271,10 +271,10 @@ 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
|
||||
say they have a 13” monitor and they think it’d be funny to see how 997 lines
|
||||
would work; they might try something like:</p>
|
||||
<div class="sourceCode" id="cb10"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a> <span class="va">LINES</span><span class="op">=</span>997 <span class="ex">./prog</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> LINES=997 ./prog</code></pre>
|
||||
<p>What then? Well expect trouble; curses will not know any better and the max
|
||||
number of lines will be 997. If they were to do:</p>
|
||||
<div class="sourceCode" id="cb11"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true" tabindex="-1"></a> <span class="va">COLUMNS</span><span class="op">=</span>997 <span class="ex">./prog</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> COLUMNS=997 ./prog</code></pre>
|
||||
<p>Then they will see a different effect. Again the same reason: the player trying
|
||||
to be funny.</p>
|
||||
<p>The game will try and be funny in return and you can expect it to not function
|
||||
@@ -306,7 +306,7 @@ GitHub) file).</p>
|
||||
<p>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:</p>
|
||||
<div class="sourceCode" id="cb12"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb12-1"><a href="#cb12-1" aria-hidden="true" tabindex="-1"></a> <span class="va">TERM</span><span class="op">=</span>linux-m <span class="ex">./prog</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> TERM=linux-m ./prog</code></pre>
|
||||
<p>But I do not specifically check if the terminal has colours. Is there a curses
|
||||
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
|
||||
@@ -328,19 +328,19 @@ support in the source code itself.</p>
|
||||
<p>Based on the two as well as the fact that monochrome terminals (I’ve tried under
|
||||
both Linux and macOS) seem to work fine I believe I am fine here too. And to
|
||||
confirm this I wrote the following code with the output below:</p>
|
||||
<div class="sourceCode" id="cb15"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb15-1"><a href="#cb15-1" aria-hidden="true" tabindex="-1"></a> <span class="pp">#include </span><span class="im"><curses.h></span></span>
|
||||
<span id="cb15-2"><a href="#cb15-2" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb15-3"><a href="#cb15-3" aria-hidden="true" tabindex="-1"></a> <span class="dt">int</span> main<span class="op">()</span></span>
|
||||
<span id="cb15-4"><a href="#cb15-4" aria-hidden="true" tabindex="-1"></a> <span class="op">{</span></span>
|
||||
<span id="cb15-5"><a href="#cb15-5" aria-hidden="true" tabindex="-1"></a> initscr<span class="op">();</span></span>
|
||||
<span id="cb15-6"><a href="#cb15-6" aria-hidden="true" tabindex="-1"></a> start_color<span class="op">();</span></span>
|
||||
<span id="cb15-7"><a href="#cb15-7" aria-hidden="true" tabindex="-1"></a> printw<span class="op">(</span><span class="st">"COLORS: </span><span class="sc">%d\n</span><span class="st">COLOR_PAIRS: </span><span class="sc">%d\n</span><span class="st">"</span><span class="op">,</span> COLORS<span class="op">,</span> COLOR_PAIRS<span class="op">);</span></span>
|
||||
<span id="cb15-8"><a href="#cb15-8" aria-hidden="true" tabindex="-1"></a> getch<span class="op">();</span></span>
|
||||
<span id="cb15-9"><a href="#cb15-9" aria-hidden="true" tabindex="-1"></a> endwin<span class="op">();</span></span>
|
||||
<span id="cb15-10"><a href="#cb15-10" aria-hidden="true" tabindex="-1"></a> <span class="op">}</span></span></code></pre></div>
|
||||
<div class="sourceCode" id="cb16"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb16-1"><a href="#cb16-1" aria-hidden="true" tabindex="-1"></a> <span class="va">TERM</span><span class="op">=</span>linux-m <span class="ex">./colour_pairs</span></span>
|
||||
<span id="cb16-2"><a href="#cb16-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">COLORS:</span> 0</span>
|
||||
<span id="cb16-3"><a href="#cb16-3" aria-hidden="true" tabindex="-1"></a> <span class="ex">COLOR_PAIRS:</span> 0</span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> #include <curses.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
initscr();
|
||||
start_color();
|
||||
printw("COLORS: %d\nCOLOR_PAIRS: %d\n", COLORS, COLOR_PAIRS);
|
||||
getch();
|
||||
endwin();
|
||||
}</code></pre>
|
||||
<pre class="<!---sh-->"><code> TERM=linux-m ./colour_pairs
|
||||
COLORS: 0
|
||||
COLOR_PAIRS: 0</code></pre>
|
||||
<p>Without specifying the TERM I get:</p>
|
||||
<pre><code> COLORS: 256
|
||||
COLOR_PAIRS: 32767</code></pre>
|
||||
@@ -348,22 +348,22 @@ confirm this I wrote the following code with the output below:</p>
|
||||
possible colour pairs than I have used so that’s not a problem either. Perhaps
|
||||
even it would only be a runtime error if the colours are supported and the
|
||||
number is out of the range? To try and figure this out I did another test:</p>
|
||||
<div class="sourceCode" id="cb18"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb18-1"><a href="#cb18-1" aria-hidden="true" tabindex="-1"></a> <span class="dt">int</span> main<span class="op">()</span></span>
|
||||
<span id="cb18-2"><a href="#cb18-2" aria-hidden="true" tabindex="-1"></a> <span class="op">{</span></span>
|
||||
<span id="cb18-3"><a href="#cb18-3" aria-hidden="true" tabindex="-1"></a> initscr<span class="op">();</span></span>
|
||||
<span id="cb18-4"><a href="#cb18-4" aria-hidden="true" tabindex="-1"></a> start_color<span class="op">();</span></span>
|
||||
<span id="cb18-5"><a href="#cb18-5" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb18-6"><a href="#cb18-6" aria-hidden="true" tabindex="-1"></a> init_pair<span class="op">(</span>COLOR_PAIRS<span class="op">+</span><span class="dv">1</span><span class="op">,</span> COLOR_WHITE<span class="op">,</span> COLOR_GREEN<span class="op">);</span></span>
|
||||
<span id="cb18-7"><a href="#cb18-7" aria-hidden="true" tabindex="-1"></a> bkgd<span class="op">(</span>COLOR_PAIR<span class="op">(</span>COLOR_PAIRS<span class="op">+</span><span class="dv">1</span><span class="op">));</span></span>
|
||||
<span id="cb18-8"><a href="#cb18-8" aria-hidden="true" tabindex="-1"></a> init_pair<span class="op">(</span><span class="dv">1</span><span class="op">,</span> COLOR_WHITE<span class="op">,</span> COLOR_BLACK<span class="op">);</span></span>
|
||||
<span id="cb18-9"><a href="#cb18-9" aria-hidden="true" tabindex="-1"></a> attron<span class="op">(</span>COLOR_PAIR<span class="op">(</span><span class="dv">1</span><span class="op">));</span></span>
|
||||
<span id="cb18-10"><a href="#cb18-10" aria-hidden="true" tabindex="-1"></a> printw<span class="op">(</span><span class="st">"COLORS: </span><span class="sc">%d\n</span><span class="st">COLOR_PAIRS: </span><span class="sc">%d\n</span><span class="st">"</span><span class="op">,</span> COLORS<span class="op">,</span> COLOR_PAIRS<span class="op">);</span></span>
|
||||
<span id="cb18-11"><a href="#cb18-11" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb18-12"><a href="#cb18-12" aria-hidden="true" tabindex="-1"></a> getch<span class="op">();</span></span>
|
||||
<span id="cb18-13"><a href="#cb18-13" aria-hidden="true" tabindex="-1"></a> endwin<span class="op">();</span></span>
|
||||
<span id="cb18-14"><a href="#cb18-14" aria-hidden="true" tabindex="-1"></a> <span class="op">}</span></span></code></pre></div>
|
||||
<pre class="<!---c-->"><code> int main()
|
||||
{
|
||||
initscr();
|
||||
start_color();
|
||||
|
||||
init_pair(COLOR_PAIRS+1, COLOR_WHITE, COLOR_GREEN);
|
||||
bkgd(COLOR_PAIR(COLOR_PAIRS+1));
|
||||
init_pair(1, COLOR_WHITE, COLOR_BLACK);
|
||||
attron(COLOR_PAIR(1));
|
||||
printw("COLORS: %d\nCOLOR_PAIRS: %d\n", COLORS, COLOR_PAIRS);
|
||||
|
||||
getch();
|
||||
endwin();
|
||||
}</code></pre>
|
||||
<p>Running it like</p>
|
||||
<div class="sourceCode" id="cb19"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb19-1"><a href="#cb19-1" aria-hidden="true" tabindex="-1"></a> <span class="va">TERM</span><span class="op">=</span>linux-m <span class="ex">./colour_pairs</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> TERM=linux-m ./colour_pairs</code></pre>
|
||||
<p>I got the output as if colours weren’t used: 0 and 0. With coloured terminals
|
||||
however it was not visible. If I however comment out the call to <code>bkgd()</code> I get
|
||||
instead:</p>
|
||||
|
||||
+13
-13
@@ -30,7 +30,7 @@ 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:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
$ make test
|
||||
```
|
||||
|
||||
@@ -67,7 +67,7 @@ If I pass in any of the variables **GROW**, **MAXSIZE**, **SIZE** and/or
|
||||
**LINES** or **COLUMNS** it bases its calculations on those variables. For
|
||||
example:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
terminal supports cursor movement
|
||||
terminal supports making cursor invisible
|
||||
terminal supports bold
|
||||
@@ -129,7 +129,7 @@ To specify the lines/columns of curses program per instance use the `LINES` and
|
||||
|
||||
For demonstration consider the following:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
$ echo $LINES $COLUMNS
|
||||
42 157
|
||||
```
|
||||
@@ -139,7 +139,7 @@ include the walls and score line but these values are for the terminal itself.
|
||||
|
||||
Say you want 55 columns:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
$ COLUMNS=55 ./prog
|
||||
```
|
||||
|
||||
@@ -166,7 +166,7 @@ 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:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
LINES=20 ./prog.alt
|
||||
LINES=20 ./snake.alt
|
||||
```
|
||||
@@ -190,7 +190,7 @@ The Linux man page says:
|
||||
|
||||
If you don't have the reset utility you can try:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
echo -e \\033c
|
||||
```
|
||||
|
||||
@@ -209,14 +209,14 @@ along and thinks he/she will be clever and mess with the dimensions a bit. Let's
|
||||
say they have a 13" monitor and they think it'd be funny to see how 997 lines
|
||||
would work; they might try something like:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
LINES=997 ./prog
|
||||
```
|
||||
|
||||
What then? Well expect trouble; curses will not know any better and the max
|
||||
number of lines will be 997. If they were to do:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
COLUMNS=997 ./prog
|
||||
```
|
||||
|
||||
@@ -265,7 +265,7 @@ 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:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
TERM=linux-m ./prog
|
||||
```
|
||||
|
||||
@@ -301,7 +301,7 @@ Based on the two as well as the fact that monochrome terminals (I've tried under
|
||||
both Linux and macOS) seem to work fine I believe I am fine here too. And to
|
||||
confirm this I wrote the following code with the output below:
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
#include <curses.h>
|
||||
|
||||
int main()
|
||||
@@ -314,7 +314,7 @@ confirm this I wrote the following code with the output below:
|
||||
}
|
||||
```
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
TERM=linux-m ./colour_pairs
|
||||
COLORS: 0
|
||||
COLOR_PAIRS: 0
|
||||
@@ -332,7 +332,7 @@ possible colour pairs than I have used so that's not a problem either. Perhaps
|
||||
even it would only be a runtime error if the colours are supported and the
|
||||
number is out of the range? To try and figure this out I did another test:
|
||||
|
||||
```c
|
||||
```<!---c-->
|
||||
int main()
|
||||
{
|
||||
initscr();
|
||||
@@ -351,7 +351,7 @@ number is out of the range? To try and figure this out I did another test:
|
||||
|
||||
Running it like
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
TERM=linux-m ./colour_pairs
|
||||
```
|
||||
|
||||
|
||||
@@ -372,7 +372,7 @@ hit a key every time to move because it is blocking.</p></li>
|
||||
</ul>
|
||||
<h2 id="on-environmental-variables-more-generally-and-string-to-int-conversions"><a name="envvars" href="#toc">On environmental variables more generally and string to int conversions</a></h2>
|
||||
<p>What happens if you do:</p>
|
||||
<div class="sourceCode" id="cb12"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb12-1"><a href="#cb12-1" aria-hidden="true" tabindex="-1"></a> <span class="va">WALLS</span><span class="op">=</span> <span class="ex">./prog</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> WALLS= ./prog</code></pre>
|
||||
<p>Can you run into the wall since you didn’t specify a value and the default is 1?
|
||||
No. That’s not the way it works. By saying WALLS= you have told the system that
|
||||
there is that environmental variable. However the way the <code>strtoul()</code> functions
|
||||
@@ -381,12 +381,12 @@ it’s wasteful (iocccsize wise) and I have never felt that having invalid input
|
||||
for a number could have a better value than 0.</p>
|
||||
<p>If however you were to give valid input followed by invalid input the valid
|
||||
input would be parsed. For example:</p>
|
||||
<div class="sourceCode" id="cb13"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb13-1"><a href="#cb13-1" aria-hidden="true" tabindex="-1"></a> <span class="va">WALLS</span><span class="op">=</span>1test <span class="ex">./prog</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> WALLS=1test ./prog</code></pre>
|
||||
<p>would let you go through the walls. On the other hand</p>
|
||||
<div class="sourceCode" id="cb14"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb14-1"><a href="#cb14-1" aria-hidden="true" tabindex="-1"></a> <span class="va">WALLS</span><span class="op">=</span>test1 <span class="ex">./prog</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> WALLS=test1 ./prog</code></pre>
|
||||
<p>would not. Furthermore if you specify the same variable more than once it’s the
|
||||
last one that counts. For example:</p>
|
||||
<div class="sourceCode" id="cb15"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb15-1"><a href="#cb15-1" aria-hidden="true" tabindex="-1"></a> <span class="va">WALLS</span><span class="op">=</span>0 <span class="va">WALLS</span><span class="op">=</span>1 <span class="va">CANNIBAL</span><span class="op">=</span>1 <span class="va">CANNIBAL</span><span class="op">=</span>0 <span class="ex">./prog</span></span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> WALLS=0 WALLS=1 CANNIBAL=1 CANNIBAL=0 ./prog</code></pre>
|
||||
<p>would allow you to go through walls but you could not cannibalise.</p>
|
||||
<p>Also note that I specify base 0 which means that you can also have it in hex and
|
||||
octal. These are all the same:</p>
|
||||
@@ -421,17 +421,17 @@ will end (yes things that haven’t begun can be ended).</p>
|
||||
<p>If <code>calloc()</code> fails to obtain the needed memory you’ll see something like (here it
|
||||
was before I added proper - to make the perfect and obvious pun - capsizing
|
||||
so that by setting the size to -1 it went to the max unsigned value):</p>
|
||||
<div class="sourceCode" id="cb19"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb19-1"><a href="#cb19-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> MAXSIZE=-1 ./prog</span>
|
||||
<span id="cb19-2"><a href="#cb19-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">memory</span> error</span>
|
||||
<span id="cb19-3"><a href="#cb19-3" aria-hidden="true" tabindex="-1"></a> <span class="ex">X:0/157</span> Y:0/42 S:3/18446744073709551614 B:0</span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> $ MAXSIZE=-1 ./prog
|
||||
memory error
|
||||
X:0/157 Y:0/42 S:3/18446744073709551614 B:0</code></pre>
|
||||
<p>BTW: There are two arrays that have to be <strong>MAXSIZE</strong> (technically + 1).</p>
|
||||
<p>Is it possible that some value specified by the user could mess this up? I do
|
||||
not know but what I do know is that because it’s unsigned it can’t be negative;
|
||||
if the max size is 0 then the array size will be 1 but it won’t matter because
|
||||
the snake size will be >= that max anyway. But here’s a curious output:</p>
|
||||
<div class="sourceCode" id="cb20"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb20-1"><a href="#cb20-1" aria-hidden="true" tabindex="-1"></a> <span class="va">SIZE</span><span class="op">=</span>1 <span class="va">MAXSIZE</span><span class="op">=</span>0 <span class="ex">./prog</span></span>
|
||||
<span id="cb20-2"><a href="#cb20-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">YOU</span> WIN!</span>
|
||||
<span id="cb20-3"><a href="#cb20-3" aria-hidden="true" tabindex="-1"></a> <span class="ex">X:78/156</span> Y:20/41 S:0/0 B:0</span></code></pre></div>
|
||||
<pre class="<!---sh-->"><code> SIZE=1 MAXSIZE=0 ./prog
|
||||
YOU WIN!
|
||||
X:78/156 Y:20/41 S:0/0 B:0</code></pre>
|
||||
<p>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.</p>
|
||||
<!--
|
||||
|
||||
@@ -328,7 +328,7 @@ hit a key every time to move because it is blocking.
|
||||
|
||||
What happens if you do:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
WALLS= ./prog
|
||||
```
|
||||
|
||||
@@ -342,20 +342,20 @@ for a number could have a better value than 0.
|
||||
If however you were to give valid input followed by invalid input the valid
|
||||
input would be parsed. For example:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
WALLS=1test ./prog
|
||||
```
|
||||
|
||||
would let you go through the walls. On the other hand
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
WALLS=test1 ./prog
|
||||
```
|
||||
|
||||
would not. Furthermore if you specify the same variable more than once it's the
|
||||
last one that counts. For example:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
WALLS=0 WALLS=1 CANNIBAL=1 CANNIBAL=0 ./prog
|
||||
```
|
||||
|
||||
@@ -414,7 +414,7 @@ If `calloc()` fails to obtain the needed memory you'll see something like (here
|
||||
was before I added proper - to make the perfect and obvious pun - capsizing
|
||||
so that by setting the size to -1 it went to the max unsigned value):
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
$ MAXSIZE=-1 ./prog
|
||||
memory error
|
||||
X:0/157 Y:0/42 S:3/18446744073709551614 B:0
|
||||
@@ -428,7 +428,7 @@ not know but what I do know is that because it's unsigned it can't be negative;
|
||||
if the max size is 0 then the array size will be 1 but it won't matter because
|
||||
the snake size will be >= that max anyway. But here's a curious output:
|
||||
|
||||
```sh
|
||||
```<!---sh-->
|
||||
SIZE=1 MAXSIZE=0 ./prog
|
||||
YOU WIN!
|
||||
X:78/156 Y:20/41 S:0/0 B:0
|
||||
|
||||
Reference in new issue
Block a user