rillig
267ff9487f
gomoku: split local variable into separate variables
...
No binary change.
2022-05-27 19:30:56 +00:00
rillig
8473846f80
gomoku: add mouse support
...
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.
2022-05-22 13:38:08 +00:00
rillig
1b7e8737f3
gomoku: clean up coordinate calculations in get_coord
...
No functional change.
2022-05-22 12:42:54 +00:00
rillig
ce8273398b
gomoku: make coordinates in get_coord 1-based
...
The rest of the game has 1-based coordinates as well.
No functional change.
2022-05-22 12:30:05 +00:00
rillig
fbd9c37871
gomoku: document a missed immediate win
...
No binary change.
2022-05-22 10:45:02 +00:00
rillig
c997c7038b
gomoku: extract main_game_loop from main
...
No functional change.
2022-05-22 09:17:15 +00:00
rillig
ea1cda2971
gomoku: turn comments for testing mode into actual code
...
No functional change.
2022-05-22 08:58:31 +00:00
rillig
e38c0d0293
gomoku: extract read_color from main
...
No functional change.
2022-05-22 08:47:26 +00:00
rillig
5e7b08baaa
gomoku: extract declare_winner from main
2022-05-22 08:36:15 +00:00
rillig
3cf5ffad79
gomoku: extract ask_user_color from main
...
No functional change.
2022-05-22 08:31:12 +00:00
rillig
1b8a16f639
gomoku: extract read_move from main
...
No functional change.
2022-05-22 08:28:10 +00:00
rillig
ab62ad42a7
gomoku: extract set_input_sources from main
...
No functional change.
2022-05-22 08:22:43 +00:00
rillig
863c7020c3
gomoku: extract parse_args from main
...
No functional change.
2022-05-22 08:18:49 +00:00
rillig
c881ee6814
gomoku: extract save_game from main
...
No functional change.
2022-05-22 08:12:15 +00:00
rillig
91e5439d10
gomoku: fix error handling when reading moves from a file
...
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]'.
2022-05-21 19:02:14 +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
7e168a678f
gomoku: shorten code, error out on too many arguments
2022-05-21 14:23:10 +00:00
rillig
2865e412a1
gomoku: warn before overwriting a saved game file
2022-05-21 12:29:34 +00:00
rillig
5680343ed2
gomoku: do not accept overly long lines from the input
...
Typing beyond the screen and then pressing and holding backspace still
removes the prompt, just as before.
2022-05-21 12:16:53 +00:00
rillig
7d01361fb9
gomoku: fix deleting a character when reading a line
2022-05-21 12:08:06 +00:00
rillig
64454c622b
gomoku: prevent thinking for too long
...
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.
2022-05-21 10:01:49 +00:00
rillig
f5e2b7b5aa
gomoku: in debug mode, after pressing 'd', allow another debug command
...
While here, remove the sleeping, as there is no obvious reason for it.
2022-05-21 09:57:53 +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
2695c7a747
gomoku: use combined curses functions
...
To save some screen space in the source code and some bytes in the
generated binary.
No functional change.
2022-05-19 22:49:05 +00:00
rillig
05b0af0c8d
gomoku: use NULL instead of more verbose null pointer
...
No binary change.
2022-05-19 22:29:36 +00:00
rillig
1e96790954
gomoku: clean up coordinate for the currently selected spot
...
There is no need to make this coordinate dependent on the board size.
No binary change.
2022-05-19 22:24:54 +00:00
rillig
e80842a607
gomoku: clean up version control sections
...
Lint can handle these definitions, and the '#if 0' is redundant.
No functional change.
2022-05-19 22:19:18 +00:00
rillig
1acd9ee500
gomoku: remove unreachable code at the end of main
...
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.
2022-05-19 20:09:46 +00:00
rillig
e123f10c5a
gomoku: replace magic numbers with proper coordinate calculation
2022-05-19 19:52:56 +00:00
rillig
6599d74ac5
gomoku: properly center the player's names
2022-05-19 19:16:38 +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
6646a33d72
gomoku: fix error message for small screen
...
- gomoku: Screen too small (need 8018d)
+ gomoku: Screen too small (need 80x24)
2022-05-19 17:02:51 +00:00
rillig
47863a265f
gomoku: fix type mismatch in call to curses function
...
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.
2022-05-19 16:58:39 +00:00
rillig
8a25385c9e
gomoku: reduce scope of local variables
...
No binary change.
2022-05-18 22:35:13 +00:00
rillig
40aee379df
gomoku: reduce scope of 'for' loop variables
...
No binary change.
2022-05-18 22:30:19 +00:00
rillig
bd075df80d
gomoku: rename local variable
...
Not every array of "characters" is a string. In this case, it's rather
an array of bool.
No binary change.
2022-05-18 21:45:40 +00:00
rillig
d1157f9be9
gomoku: call setprogname, for portability
...
No functional change on NetBSD, but the games are distributed to other
platforms as well.
2022-05-18 19:29:00 +00:00
rillig
ee5b7371a9
gomoku: highlight the last played move
2022-05-16 22:03:16 +00:00
rillig
ea4f930572
gomoku: add usage
2022-05-16 21:53:41 +00:00
rillig
509aea6249
gomoku: enable lint's strict bool mode
...
No functional change.
2022-05-16 21:48:45 +00:00
rillig
03582a4d36
gomoku: fix remaining lint warnings in -DDEBUG mode
...
The generated code changes since the calculations are now performed with
int precision. No functional change since no overflow occurs.
2022-05-16 21:38:46 +00:00
rillig
46332bb5af
gomoku: fix most lint warnings in -DDEBUG mode
...
No binary change.
2022-05-16 21:35:39 +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
fb3a24af4a
gomoku: fix lint warnings
...
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.
2022-05-16 19:55:58 +00:00
rillig
9af749df4c
gomoku: condense code to decide which spot is better
...
The comments in the conditions only serve to align the expressions, to
allow humans to check that they correspond.
No functional change.
2022-05-16 19:20:25 +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
0a647d356c
gomoku: remove redundant parentheses around return values
...
No binary change.
2022-05-15 22:08:05 +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
rillig
1182a44c59
games: remove trailing whitespace in *.c and *.h
2021-05-02 12:50:43 +00:00
dholland
c136a62a8b
Fix the out-of-memory behavior so the message doesn't disappear under
...
endwin(). Related to PR 3126.
2016-06-12 02:15:26 +00:00
dholland
a94f7f4574
move extern decls to .h files
2014-03-22 18:58:57 +00:00
christos
193b880fad
fix unused variable warnings
2013-10-19 17:19:30 +00:00
dholland
0d0b06a380
Pass -Wstrict-overflow... mostly.
2012-10-13 20:57:35 +00:00
matt
29f82ac3aa
Fix conflicting variable definitions
2012-02-18 06:57:23 +00:00
christos
aba0d26e70
avoid non-literal format strings.
2011-08-16 11:10:54 +00:00
dholland
5cea3c1fc6
remove #ifdef SVR4
2010-03-29 05:16:08 +00:00
dholland
b7b2c88aa1
Some improvements to the new UI.
2010-03-29 04:28:47 +00:00
dholland
96bcb2af91
reorg for clarity and exposition.
2010-03-29 04:00:03 +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
3fa2c4cfe9
Spell "versus" right.
2010-03-29 02:48:17 +00:00
dholland
f6d2af84fc
Allow saved game filenames up to PATH_MAX. From OpenBSD.
2010-03-29 02:46:05 +00:00
dholland
fb89b74a21
fix quote markup, spotted in openbsd diffs
2010-03-29 02:34:50 +00:00
dholland
47514c94ae
Fix typo. From OpenBSD.
2010-03-29 02:32:45 +00:00
dholland
bb74336220
Don't exit(0) on failure. Use errx() instead of fprintf.
2010-03-29 02:21:04 +00:00
he
76d4444c78
When using -lcurses, you also need -lterminfo.
...
This fixes the build for sun2, and also builds with LDSTATIC=-static,
since archive libraries don't record inter-library dependencies.
2010-02-06 23:45:24 +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
a3c372524a
Rectify non-compiling code that appears when DEBUG is defined.
2009-06-04 07:01:16 +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
02e6a3b1d0
sprintf -> snprintf
2009-06-04 05:51:12 +00:00
dholland
891dcf008d
Increase spending on vowels. No object file diffs.
2009-06-04 05:43:29 +00:00
dholland
881e77fbe7
ANSIfy function declarations.x
2009-06-04 05:27:04 +00:00
drochner
432ec04420
if initscr() fails, exit with a message rather than crash in the
...
next curses call
2008-08-08 16:10:47 +00:00
lukem
2fe2731d3f
Remove the \n and tabs from the __COPYRIGHT() strings.
2008-07-20 00:52:39 +00:00
dholland
d759c4a5e3
build with WARNS=4
2008-01-28 07:01:01 +00:00
perry
8b0f9554ff
convert __attribute__s to applicable cdefs.h macros
2007-12-15 19:44:37 +00:00
mrg
bb1dac937d
avoid a pointer sign difference.
2006-05-11 00:17:07 +00:00
wiz
d9f5a9df01
Use standard AUTHORS section header. From YOMURA Masanori in private mail
...
Sort sections if necessary. Use more/better markup.
2005-09-15 02:09:41 +00:00
rillig
4f6457e756
Fixed wrong use of the <ctype.h> functions by adding an explicit conversion
...
to unsigned char. Approved by christos.
2005-04-19 20:14:29 +00:00
dsl
49f7d8a9b1
Add (unsigned char) cast to ctype functions
2004-11-05 21:30:31 +00:00
jsm
cb5fd8342e
Remove uses of __P.
2004-01-27 20:30:28 +00:00
jsm
0752e03df7
Include <limits.h> instead of <machine/limits.h>.
2004-01-27 20:26:20 +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
wiz
c91d8d6b9b
Lots of minor fixes resulting from reading these man pages in detail.
2002-09-26 18:31:58 +00:00
wiz
875690e96c
Ispell.
2002-09-26 16:29:25 +00:00
wiz
0d22e30cd0
New sentences begin on new lines.
...
Patch from Richard Elz, slightly improved by yours truly.
2002-09-26 16:12:39 +00:00