Improve 2020/ferguson1/termcaps.c
This commit is contained in:
1 parent
16d305bddb
commit
a7e018d5e8
2 files changed
+58
-42
No files matched your search
+13
-11
@@ -1,11 +1,13 @@
|
|||||||
/* This will imperfectly:
|
/* ioccc/2020/ferguson1 - Snake terminal testing utility
|
||||||
|
*
|
||||||
(1) Test if terminal supports the features Snake uses.
|
* This will imperfectly:
|
||||||
(2) Report terminal (and playing) size(s).
|
*
|
||||||
(3) Estimates the minimum number of columns to play unhindered (based on the
|
* (0) Test if terminal supports the features Snake uses.
|
||||||
size, max size and growth rate).
|
* (1) Report terminal (and playing) size(s).
|
||||||
(4) Reports the max size of the Snake and the number of bugs required to
|
* (2) Estimates the minimum number of columns to play unhindered (based on the
|
||||||
reach that size (doesn't use shedding).
|
* size, max size and growth rate).
|
||||||
|
* (3) Reports the max size of the Snake and the number of bugs required to
|
||||||
|
* reach that size but doesn't use shedding.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <curses.h>
|
#include <curses.h>
|
||||||
@@ -84,7 +86,7 @@ int main(void)
|
|||||||
{
|
{
|
||||||
i[caps].sup = tigetstr(caps[i].caps);
|
i[caps].sup = tigetstr(caps[i].caps);
|
||||||
/* tigetstr() returns (char *)-1 if the capability name isn't
|
/* tigetstr() returns (char *)-1 if the capability name isn't
|
||||||
* recognised; check for this before suggesting it's supported: */
|
* recognised; check for this before suggesting it's (un)?supported: */
|
||||||
if (caps[i].sup == (char *)-1)
|
if (caps[i].sup == (char *)-1)
|
||||||
caps[i].sup = NULL;
|
caps[i].sup = NULL;
|
||||||
if (!caps[i].sup) ++k;
|
if (!caps[i].sup) ++k;
|
||||||
@@ -119,10 +121,10 @@ int main(void)
|
|||||||
|
|
||||||
rows = 14 + b(Y)*2 + a(y)*2 + a(x)*2 + b(N);
|
rows = 14 + b(Y)*2 + a(y)*2 + a(x)*2 + b(N);
|
||||||
if (x < (int)rows + 1) ++k;
|
if (x < (int)rows + 1) ++k;
|
||||||
printf("at least %zu columns recommended for snake size %-5zu (is %d)\n", rows+1,Y, x);
|
printf("at least %zu columns (currently %d) recommended for snake size %-5zu\n", rows+1,x, Y);
|
||||||
|
|
||||||
rows = 14 + b(K)*2 + a(y)*2 + a(x)*2 + b(c(K,X));
|
rows = 14 + b(K)*2 + a(y)*2 + a(x)*2 + b(c(K,X));
|
||||||
printf("at least %zu columns recommended for snake size %-5zu (is %d)\n\n", rows + 1, K, x);
|
printf("at least %zu columns (currently %d) recommended for capped snake size %-5zu\n\n", rows + 1,x, K);
|
||||||
|
|
||||||
|
|
||||||
if (!k)
|
if (!k)
|
||||||
|
|||||||
+45
-31
@@ -42,54 +42,68 @@ for the capabilities I use in the entry.
|
|||||||
It also tries to determine the minimum number of columns to play without the
|
It also tries to determine the minimum number of columns to play without the
|
||||||
status line overflowing - even with the dynamic length. Try:
|
status line overflowing - even with the dynamic length. Try:
|
||||||
|
|
||||||
$ make test
|
```sh
|
||||||
|
$ make test
|
||||||
|
```
|
||||||
|
|
||||||
This compiles the program and runs it; you should see something like:
|
This compiles the program [termcaps.c](termcaps.c) and runs it; you should see something like:
|
||||||
|
|
||||||
terminal supports cursor movement
|
|
||||||
terminal supports making cursor invisible
|
|
||||||
terminal supports bold
|
|
||||||
terminal supports colours
|
|
||||||
|
|
||||||
terminal rows 42 (39 playable)
|
```
|
||||||
terminal cols 157 (155 playable)
|
terminal supports cursor movement
|
||||||
|
terminal supports making cursor invisible
|
||||||
|
terminal supports bold
|
||||||
|
terminal supports colours
|
||||||
|
|
||||||
snake size: 997 (max size: 6006)
|
terminal rows 41 (38 playable)
|
||||||
bugs: 199 (max size: 1201)
|
terminal cols 155 (153 playable)
|
||||||
|
|
||||||
at least 34 columns recommended for snake size 997 (is 157)
|
snake size: 997 (max size: 5776)
|
||||||
at least 37 columns recommended for snake size 6006 (is 157)
|
bugs: 199 (max size: 1155)
|
||||||
|
|
||||||
No problems detected.
|
at least 34 columns (currently 155) recommended for snake size 997
|
||||||
|
at least 37 columns (currently 155) recommended for capped snake size 5776
|
||||||
|
|
||||||
If I pass in any of the variables **GROW**, **MAXSIZE**, **SIZE** and/or
|
No problems detected.
|
||||||
**LINES** or **COLUMNS** it bases its calculations on those variables. For
|
```
|
||||||
|
|
||||||
|
Terminal rows and cols are the current values (the number of columns shown later
|
||||||
|
as well). The snake size is the default size to win (based on the variables, see
|
||||||
|
below). The `max size: 5776` is the capped size (or 'capsize'). The 199 bugs is
|
||||||
|
approximately the `snake_size / growth_size` i.e. how many bugs it
|
||||||
|
will take to win the game. The max bugs in the `bugs` line is approximately
|
||||||
|
`max_snake_size / growth_size` i.e. how many bugs it'll take to win at the
|
||||||
|
maximum (capped) snake size.
|
||||||
|
|
||||||
|
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:
|
example:
|
||||||
|
|
||||||
$ MAXSIZE=-1 GROW=1 make test
|
```sh
|
||||||
terminal supports cursor movement
|
terminal supports cursor movement
|
||||||
terminal supports making cursor invisible
|
terminal supports making cursor invisible
|
||||||
terminal supports bold
|
terminal supports bold
|
||||||
terminal supports colours
|
terminal supports colours
|
||||||
|
|
||||||
terminal rows 42 (39 playable)
|
terminal rows 41 (38 playable)
|
||||||
terminal cols 157 (155 playable)
|
terminal cols 155 (153 playable)
|
||||||
|
|
||||||
snake size: 6006 (max size: 6006)
|
snake size: 5776 (max size: 5776)
|
||||||
bugs: 6001 (max size: 6001)
|
bugs: 5771 (max size: 5771)
|
||||||
|
|
||||||
at least 37 columns recommended for snake size 6006 (is 157)
|
at least 37 columns (currently 155) recommended for snake size 5776
|
||||||
at least 37 columns recommended for snake size 6006 (is 157)
|
at least 37 columns (currently 155) recommended for capped snake size 5776
|
||||||
|
|
||||||
No problems detected.
|
No problems detected.
|
||||||
|
```
|
||||||
|
|
||||||
|
As you can see it tells you the max size (the 'capsized' snake) as well as the
|
||||||
As you can see it tells you the max size (the 'capsized' snake) as well as
|
requested max size (if the requested size is bigger than the capped size then it
|
||||||
the requested max size (if the requested size is bigger than the capsize then it
|
|
||||||
will be set to that value instead) of the snake. The capped size is like in the
|
will be set to that value instead) of the snake. The capped size is like in the
|
||||||
Snake game itself but the suggested minimum number of columns is based on a
|
Snake game itself but the suggested minimum number of columns is based on a
|
||||||
number of variables.
|
number of variables.
|
||||||
|
|
||||||
|
|
||||||
If I were to do the above but set columns to less < 35 then there would be a
|
If I were to do the above but set columns to less < 35 then there would be a
|
||||||
problem. But why if the utility recommends at least 37? This is because the
|
problem. But why if the utility recommends at least 37? This is because the
|
||||||
max size of the snake also depends on the terminal size. This utility is not
|
max size of the snake also depends on the terminal size. This utility is not
|
||||||
@@ -108,7 +122,7 @@ this should give you an idea.
|
|||||||
|
|
||||||
If there are any problems it will say how many (fatal and otherwise). The fatal
|
If there are any problems it will say how many (fatal and otherwise). The fatal
|
||||||
problems are if curses fails to initialise or if movement of cursor cannot be
|
problems are if curses fails to initialise or if movement of cursor cannot be
|
||||||
done (both seem odd).
|
done (both seem unlikely to happen nowadays).
|
||||||
|
|
||||||
Both scripts run this utility and prompt if there are any problems;
|
Both scripts run this utility and prompt if there are any problems;
|
||||||
you can continue either way.
|
you can continue either way.
|
||||||
|
|||||||
Reference in new issue
Block a user