Previously, the name 's' was used for the index of a spot on the board,
as well as for the value of a combo, and for a few other purposes. Use
different names and mark the spot indexes using a custom type.
No binary change.
Fix variable names 'ia' and 'ib', which I forgot in the previous commit.
Move the documentation in the right places.
Split off another part of init_overlap, to make each function fit on a
single screen. Reducing the number of nested 'for' loops allows the
indentation to follow the NetBSD style.
No functional change.
By clearly associating each variable to either frame A or frame B,
suddenly the code becomes understandable. For the benefit of future
readers, explain the naming scheme.
No functional change.
The comments about the "top border" and "bottom border" had been wrong
all the time. Mention the corners in the comments, to remove the magic
from the various '+ 1' in the code.
No functional change.
No functional change, not even the TIE that is wrongly announced when
the very last spot on the board is yet to be filled by Black. Even
without this off-by-one error, it could be that filling the very last
spot completes a frame, so that code has been wrong all the time.
In practical terms, this situation only arises when the human player is
unconcentrated or the computer player has a bad strategy. The latter
may well be, as the computer moves in the (boring) endgame are not
directed towards winning -- they fill irrelevant spots before relevant
ones.
NetBSD 10 provides the mouse handling functions from <curses.h> but does
not actually implement the mouse handling. For the benefit of other
platforms, add mouse support; when linked with ncurses instead of
curses, it works.
Depending on the input device, mouse clicks are either reported as
"button 1 clicked" (mouse) or "button 1 pressed/released" (touchpad);
support both.
Be strict about the X coordinate when clicking. Since the coordinates
are integer numbers, getting the location between two spots is
ambiguous, as it could be just one pixel away or right in the middle of
the space between the spots.
The columns of the board are labeled from A to H and J to T, which makes
I5 or i5 an invalid coordinate. Previously, reading this invalid
coordinate from a file resulted in the string "<6" appearing in the move
log.
The 'i' was converted into the nonexistent column 20, and PT(20, 5) got
an out-of-bounds argument, resulting in spot 120. Converting this spot
back into coordinates resulted in PT(0, 6). The '<' comes from
'letters[0]'.
I also tried converting other macros, but s_occ would use more memory
and the return values for makemove are special values, besides the usual
coordinates in the form PT(x, y), so turning the special values into an
enum would be confusing.
No functional change.
At search depth 9, picking a move takes about a minute on modern
hardware, which is enough for casual game play. Even then, gomoku does
not always find the perfect move, so investing that much time seems
questionable. Limiting the search depth also puts an upper bound on the
memory usage, which is quite high with 150 MB.
In C99 mode, lint accepts when control gets to the end of main without
returning a value. It does not know anything about __dead though.
No binary change.
Modern compilers optimize linear integer arithmetic, so there is no
reason to use strange or misleading formulas.
Replace several magic numbers with proper formulas.
No binary change.
Not yet detected by lint, as lint is more permissive for type mismatches
if the value is a constant 0. Being permissive doesn't make sense in
this case. Now the calls to 'keypad' and 'leaveok' are consistent.
No binary change.
Most warnings were about implicit conversions from ptrdiff_t to int; add
explicit cast for them, as they are far from overflowing int.
The casts from one pointer type to 'struct combostr **' were indeed
suspicious. In these cases, a single region of memory is allocated to
store two objects of different type, without declaring a struct type for
their combination. The second object is an array of variable size.
No binary change.
Since overlap_info is only used in pickmove.c, move it there.
No functional change. In particular, in the middle of a game, gomoku
still tends to fall into analysis paralysis, thinking about the best
move for more than 3 minutes on modern hardware. Since the algorithm is
basically unchanged since the 1990s, it must have been a long waiting
time back then, probably an hour per move.
Of the 19 macros, only 3 were actually used. Replace their uses with
expressions based on the board size. It's a small step to making the
board size adjustable. There are still other places using hard-coded
numbers.
No binary change.
There are still parts of the code that use an indentation level of 4
instead of the usual 8. Fixing that right now would introduce more
unnatural line breaks, so defer that until later.
No binary change.
Pressing Tab or Shift+Tab now advances to the next letter that could be
substituted, it no longer stops at punctuation or digits. Since only
letters are scrambled, these are most interesting to be edited.
The '!= 0' is needed for an upcoming fix to lint's strict bool mode.
The additional text in the error messages is necessary because errx only
outputs the given string, with no details from errno. Since ferror does
not set errno, no such details are available, so just output a generic
message, which is still better than just "caesar: <stdout>".