Commit Graph

56 Commits

Author SHA1 Message Date
rillig 3dd0208726 gomoku: reduce usage of magic numbers in the code
No binary change.
2022-06-19 10:23:48 +00:00
rillig fe75e7f249 gomoku: refine the type of some functions and variables
Assisted by WARNS=6. At that level, there are several warnings about
type conversion between small integer types that would only clutter the
code, therefore stay at WARNS=5. Same for lint's -aa option.

No functional change.
2022-05-29 17:01:42 +00:00
rillig 1f981c0ac1 gomoku: when starting a new game, start in the middle of the board
Previously, when starting a new game, the user coordinate was kept at
the previously selected spot. Since playing in the center is common
sense, reset the coordinate.
2022-05-29 16:30:44 +00:00
rillig 6b2dc434d3 gomoku: add type player_color
No functional change.
2022-05-29 15:31:12 +00:00
rillig e3d95fb4b0 gomoku: provide a more gentle introduction to the code
No binary change.
2022-05-29 14:50:37 +00:00
rillig 7167cb1f23 gomoku: don't use 'i' as special-purpose variable name
No binary change.
2022-05-29 14:37:44 +00:00
rillig 5e10e7e916 gomoku: add data type for one of the 4 directions of a frame
No functional change.
2022-05-29 13:49:10 +00:00
rillig fca58dfea5 gomoku: turn spotstr.s_frame into a frame index
Most calculations are done on the frame index, not the pointer. This
avoids dealing with ptrdiff_t conversion to int.

Changing the type of s_frame changes the size of struct spotstr, it is
now 56 bytes on LP64 and 48 bytes on ILP32, neither of which is a power
of two. Remove the dummy padding since compilers no longer generate
division instructions for divisions by small integer constants, so that
optimization is no longer necessary.

No functional change.
2022-05-29 10:37:21 +00:00
rillig 355e963e40 gomoku: migrate spot_index from int to unsigned short
This matches the type of 'intersect'.

No functional change.
2022-05-29 00:38:26 +00:00
rillig 76069dc145 gomoku: use consistent variable names
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.
2022-05-29 00:12:11 +00:00
rillig cc51471792 gomoku: use custom magic value for end of file input
This allows the type for a spot index to be changed to an unsigned type.

No functional change.
2022-05-28 23:05:45 +00:00
rillig 14facc424c gomoku: split initialization of the board into smaller functions
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.
2022-05-28 17:51:27 +00:00
rillig 8fc3223a93 gomoku: highlight the winning frame 2022-05-28 08:32:55 +00:00
rillig a347aeb809 gomoku: group movelog and nmoves into a game struct
No functional change.
2022-05-28 08:19:18 +00:00
rillig 3a536c56b8 gomoku: extract update_overlap_different_direction
No functional change.
2022-05-28 06:25:35 +00:00
rillig 4a862cfde5 gomoku: reduce scope of local variables
No binary change.
2022-05-27 23:10:54 +00:00
rillig 42e4930deb gomoku: replace 1-based movenum with 0-based nmoves
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.
2022-05-27 19:59:56 +00:00
rillig fbd9c37871 gomoku: document a missed immediate win
No binary change.
2022-05-22 10:45:02 +00:00
rillig be456ab9a1 gomoku: right-align column header for move number 2022-05-21 17:19:10 +00:00
rillig 5b16bd53b8 gomoku: provide readable names for c.a and c.b
No binary change.
2022-05-21 16:39:14 +00:00
rillig 06d9af6489 gomoku: move comments closer to their corresponding entities
No binary change.
2022-05-21 15:21:40 +00:00
rillig 08019d5024 gomoku: inline macro MAXCOMBO
The name of the macro was not descriptive enough, the other constants in
bdinit also don't have names.

No binary change.
2022-05-21 15:11:24 +00:00
rillig 1425a8ae20 gomoku: convert input source constants to an enum
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.
2022-05-21 14:55:26 +00:00
rillig 2865e412a1 gomoku: warn before overwriting a saved game file 2022-05-21 12:29:34 +00:00
rillig 8e7debfab2 gomoku: make drawing the player's names simpler
No functional change.
2022-05-21 09:25:51 +00:00
rillig a79b5066a6 gomoku: fix spelling and grammar in comments 2022-05-20 19:30:17 +00:00
rillig 6d8c791c47 gomoku: remove unused function 'list_eq' 2022-05-19 23:12:40 +00:00
rillig 0144aec45b gomoku: de-obfuscate screen coordinate calculation
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.
2022-05-19 18:58:59 +00:00
rillig 509aea6249 gomoku: enable lint's strict bool mode
No functional change.
2022-05-16 21:48:45 +00:00
rillig 73770304b0 gomoku: allow combination of WARNS=6 and -DDEBUG 2022-05-16 21:02:18 +00:00
rillig 21be9673ff gomoku: prepare lint's strict bool mode
No binary change.
2022-05-16 20:57:01 +00:00
rillig af50285f47 gomoku: inline macros BSZ1, BSZ2, BSZ3, BSZ4
These macro names didn't convey any meaning, so replace them with their
replacement text, to have fewer identifiers to worry about.

No binary change.
2022-05-15 22:56:20 +00:00
rillig 20e9d475ef gomoku: remove write-only members from overlap_info
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.
2022-05-15 22:41:51 +00:00
rillig 3189ab5b3f gomoku: remove column macros
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.
2022-05-15 22:18:36 +00:00
rillig ee07f44521 gomoku: apply some style fixes towards KNF
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.
2022-05-15 22:00:11 +00:00
rillig 8e531acc76 gomoku: clean up unused code and lint warnings
No binary change.
2022-05-14 16:21:04 +00:00
dholland a94f7f4574 move extern decls to .h files 2014-03-22 18:58:57 +00:00
dholland b7b2c88aa1 Some improvements to the new UI. 2010-03-29 04:28:47 +00:00
dholland 4a11aa7558 Better user interface. From OpenBSD, written by Paul Janzen quite a
long time ago. A few minor adjustments by yours truly.
2010-03-29 03:51:55 +00:00
dholland bc0970cff2 sprinkle static 2009-08-12 06:19:17 +00:00
roy 7027866a09 Rename internal getline() function to get_line() so it does
conflict with the soon to be added getline(3) libc function.
2009-07-13 19:05:39 +00:00
dholland 99d95061d4 Remove global scratch string buffer. Don't zoom off the end while reading
user input, either.
2009-06-04 06:47:36 +00:00
dholland 60843edfc7 Remove remaining references to sprintf. 2009-06-04 06:41:50 +00:00
dholland b8bb3787da Make a couple of the logging/printing functions printf-alikes. This removes
most of the calls to sprintf.
2009-06-04 06:27:47 +00:00
dholland 04ecbfca8b attribute noreturn -> __dead 2009-06-04 05:52:30 +00:00
dholland 891dcf008d Increase spending on vowels. No object file diffs. 2009-06-04 05:43:29 +00:00
jsm cb5fd8342e Remove uses of __P. 2004-01-27 20:30:28 +00:00
jsm 514bad17d7 Include <sys/endian.h>. 2004-01-27 20:25:48 +00:00
agc e5aeb4ea46 Move UCB-licensed code from 4-clause to 3-clause licence.
Patches provided by Joel Baker in PR 22269, verified by myself.
2003-08-07 09:36:50 +00:00
jsm a1038d000e Fix uses of names of library functions for other purposes. 1999-09-13 17:18:56 +00:00