fix Makefile and README.md for 2001/kev

This commit is contained in:
Landon Curt Noll committed 2023-03-21 15:55:44 -07:00
1 parent 2036c8afc8
commit 62450844d1
2 files changed
+430 -340

No files matched your search

+262 -169
View File
@@ -1,18 +1,9 @@
#!/usr/bin/env make #!/usr/bin/env make
# #
# IOCCC 2001 entry Makefile # IOCCC 2001 winning entry - kev
################################################################################ ################################################################################
# #
# An Historical Makefile NOTE:
#
# The orig.Makefile, if it exits, is the original Makefile before this IOCCC
# year directory was reworked so that entries are in separate directories.
# This also applies to any orig.ansi.mk and orig.common.mk files.
#
# Several Makefiles were modified / formed in 2022, and as such it may have
# elements that are not historically compatible with way entries were built.
#
# Regarding individual entries: # Regarding individual entries:
# #
# IOCCC winning entry code may not work on your system. Even with standards, # IOCCC winning entry code may not work on your system. Even with standards,
@@ -45,192 +36,294 @@
# See: http://creativecommons.org/licenses/by-sa/3.0/ # See: http://creativecommons.org/licenses/by-sa/3.0/
SHELL= /bin/sh #############################
CAT= cat # shell used by this Makefile
RM= rm #############################
SED= sed
TRUE= true
#CINCLUDE= -I ${HOMEBREW_PREFIX}/include/SDL2
# optimization
# #
# Most compiles will safely use -O2. Some can use only -O. SHELL= bash
# A few compilers have broken optimizers and thus you may
# not want anything. #######################
# common tool locations
#######################
#
include ../../var.mk
# Set X11_LIBDIR to the directory where the X11 library resides
#
#X11_LIBDIR= /usr/X11R6/lib
#X11_LIBDIR= /usr/X11/lib
X11_LIBDIR= /opt/X11/lib
# Set X11_INCLUDEDIR to the directory where the X11 include files reside
#
#X11_INCDIR= /usr/X11R6/include
#X11_INCDIR= /usr/X11/include
X11_INCDIR= /opt/X11/include
# Common C compiler warnings to silence
#
#CSILENCE=
CSILENCE= -Wno-empty-body -Wno-error -Wno-implicit-function-declaration \
-Wno-incompatible-pointer-types -Wno-non-literal-null-conversion \
-Wno-parentheses -Wno-pointer-bool-conversion -Wno-unsequenced
# Common C compiler warning flags
#
#CWARN= ${CSILENCE}
#CWARN= -Wall ${CSILENCE}
#CWARN= -Wall -Wextra ${CSILENCE}
CWARN= -Wall -Wextra -pedantic ${CSILENCE}
# Compiler standard
#
#CSTD=
#CSTD= -ansi
CSTD= -std=gnu99
# Compiler bit architecture
#
# Some entries require 32-bitness:
# ARCH= -m32
#
# Some entries require 64-bitness:
# ARCH= -m64
#
# By default we assume nothing:
#
ARCH=
# Defines that are needed to compile
#
#CDEFINE=
CDEFINE= -DPORT=5455 -DSPEED=50 -Dl_="socket(il.sin_family=AF_INET,SOCK_STREAM,0)"
# Include files that are needed to compile
#
CINCLUDE=
#CINCLUDE= -include stdlib.h
#CINCLUDE= -include stdio.h
#CINCLUDE= -include stdlib.h -include stdio.h
#CINCLUDE= -I ${X11_INCDIR} -I ${X11_INCDIR}/X11
#CINCLUDE= `${SDL2_CONFIG} --cflags`
# Optimization
#
# Most compiles will safely use -O2. Some can use only -O1 or -O.
# A few compilers have broken optimizers or this entry make break
# under those buggy optimizers and thus you may not want anything.
# Reasonable compilers will allow for -O3.
# #
#OPT= #OPT=
#OPT= -O #OPT= -O
OPT= -O2 #OPT= -O1
#OPT= -O2
OPT= -O3
# flags for ANSI compiles # Default flags for ANSI C compilation
# #
# NOTE: Some ANSI compilers make use of -Xa to turn on ANSI mode, CFLAGS= ${CSTD} ${CWARN} ${ARCH} ${CDEFINE} ${CINCLUDE} ${OPT}
# others such as gcc may want -ansi, others (Compaq Tru64 Unix)
# want -std1, and others may want nothing at all.
# Adjust the CFLAGS line as needed.
#
# NOTE: Some compilers cannot optimize, or optimize some entries
# incorrectly. You might want to turn on -O to see if your
# compiler can handle them.
#
#
#CFLAGS= -Xa ${OPT}
#CFLAGS= -std1 $(OPT)
CFLAGS= -ansi ${OPT}
# NOTE: On some systems, the library path does not include the location # Libraries needed to build
# of the X11 libraries. You might need to use a -L/path/to/X11/lib/dir
# in order to compile with these libs.
# #
X11CCFLAGS= -I/usr/X11R6/include -I/usr/X11R6/include/X11 -I/usr/include/X11 #LIBS=
#X11CCFLAGS= LIBS= -lncurses
X11LDFLAGS= -L/usr/X11R6/lib -Wl,-R/usr/X11R6/lib #LIBS= -L ${X11_LIBDIR} -lX11
#X11LDFLAGS= #LIBS= `${SDL2_CONFIG} --libs`
# ANSI compiler # C compiler to use
#
# Set CC to the name of your ANSI compiler.
#
# Some entries seem to need gcc. If you have gcc, set
# both CC and MAY_NEED_GCC to gcc.
#
# If you do not have gcc, set CC to the name of your ANSI compiler, and
# set MAY_NEED_GCC to either ${CC} (and hope for the best) or to just :
# to disable such programs.
# #
CC= cc CC= cc
MAY_NEED_GCC= gcc #CC=clang
#CC=gcc
# winners that compile under ANSI C # Compiler add-ons or replacements for clang only
# #
WINNERS= anonymous bellard bellard.otccex cheong coupard \ ifeq ($(CC),clang)
ctk dgbeards herrmann1 herrmann2 jason kev ollinger rosten \
schweikh westley williams
ALT_NAMES= westley.orig
DATA_FILES= anonymous_files bellard_files herrmann1_files herrmann2_files
all: ${WINNERS}
# Most likely to amaze
# #
anonymous: anonymous.c CSILENCE+= -Wno-float-conversion -Wno-implicit-int-conversion -Wno-missing-prototypes \
magic='${MAY_NEED_GCC} -O1'; \ -Wno-missing-variable-declarations -Wno-poison-system-directories \
X='-DA(X)=#X'; \ -Wno-shorten-64-to-32 -Wno-sign-conversion
warning='-pedantic -Dprocessor'; \
$$magic $$warning -Dmagic= $$X "-DX=A($$magic \"$$X\")" \
-o anonymous anonymous.c
anonymous_files: anonymous.ten.c
# Best abuse of the rules
# #
bellard: bellard.c CWARN+= -Weverything
${CC} -rdynamic ${CFLAGS} bellard.c -o bellard -ldl
bellard_files: bellard.otccex.c
# Best short program
# #
cheong: cheong.c endif
${CC} ${CFLAGS} cheong.c -o cheong
# Most obfuscated sound # Specific add-ons or replacements for gcc only
# #
coupard: coupard.c ifeq ($(CC),gcc)
${CC} ${CFLAGS} -o coupard coupard.c
# Worst Driver
# #
ctk: ctk.c #CSILENCE+=
${CC} ${CFLAGS} -o ctk ctk.c
# Worst AI
# #
dgbeards: dgbeards.c #CWARN+=
${CC} ${CFLAGS} -DE=break -DF=char -DK=case -DP=int -DR=return \
-DI=0xFFFF dgbeards.c -o dgbeards
# Best abuse of the C preprocessor
# #
herrmann1: herrmann1.c herrmann1.sh endif
@echo "NOTE: $@ must be built/run using the script $@.sh"
${SHELL} ./herrmann1.sh
herrmann1_files: herrmann1.gcd herrmann1.sh herrmann1.times2
# Most eye-crossing ##############################
# Special flags for this entry
##############################
# #
# This entry requires the GCC -include feature. ENTRY= kev
PROG= ${ENTRY}
# #
herrmann2: herrmann2.c OBJ= ${PROG}.o
${MAY_NEED_GCC} ${CFLAGS} herrmann2.c -o herrmann2 \ DATA=
-include /usr/include/stdlib.h -include /usr/include/stdio.h \ TARGET= ${PROG}
-include /usr/include/time.h -include /usr/include/unistd.h
herrmann2_files: herrmann2.cup herrmann2.ioccc
# Best Of Show
# #
jason: jason.c ALT_OBJ=
${CC} ${CFLAGS} -o jason jason.c ALT_TARGET=
# Best Curses Game
#################
# build the entry
#################
# #
kev: kev.c all: data ${TARGET}
${CC} ${CFLAGS} -DPORT=5455 -DSPEED=50 -o kev kev.c \
-lcurses -ltermcap \
-Dl_="socket(il.sin_family=AF_INET,SOCK_STREAM,0)"
# Best primal ASCII graphics
#
ollinger: ollinger.c
${CC} ${CFLAGS} ollinger.c -o ollinger
# Best abuse of the user
#
rosten: rosten.c
${CC} ${CFLAGS} rosten.c ${X11CCFLAGS} ${X11LDFLAGS} -pedantic -lX11 \
-o rosten
# Best one-liner
#
schweikh: schweikh.c
${CC} ${CFLAGS} schweikh.c -o schweikh
# Best position-independant code
#
westley: westley.c
${CC} ${CFLAGS} westley.c -o westley
westley.orig: westley.orig.c
${CC} ${CFLAGS} westley.orig.c -o westley.orig
# Best position-independant code
#
williams: williams.c
${CC} williams.c ${X11CCFLAGS} ${X11LDFLAGS} -lX11 -o williams
everything: ${WINNERS} ${ALT_NAMES} ${DATA_FILES}
love:
@echo 'not war?'
haste:
${MAKE} waste
waste:
@echo 'waste'
clean:
${RM} -f *.o a.out core ${WINNERS}
clobber: clean
${RM} -f ${WINNERS}
${RM} -f ${ALT_NAMES}
nuke: clobber
@${TRUE} @${TRUE}
install: all .PHONY: all alt data everything clean clobber install \
${CAT} ${WINNERS} ${ALT_NAMES} > /dev/null love haste waste maker easter_egg sandwich \
supernova deep_magic magic charon pluto
${PROG}: ${PROG}.c
${CC} ${CFLAGS} $< -o $@ ${LIBS}
# alternative executable
#
alt: data ${ALT_TARGET}
@${TRUE}
# data files
#
data: ${DATA}
@${TRUE}
# both all and alt
#
everything: all alt
###############
# utility rules
###############
#
clean:
${RM} -f ${OBJ} ${ALT_OBJ}
@-if [ -f indent.c ]; then \
echo ${RM} -f indent.c; \
${RM} -f indent.c; \
fi
clobber: clean
${RM} -f ${TARGET} ${ALT_TARGET}
@-if [ -e sandwich ]; then \
${RM} -f sandwich; \
echo 'ate sandwich'; \
fi
install:
@echo "Dr. Spock says that is not logical!"
@${TRUE}
# you may be able to misunderstand the source by reading indent.c
#
indent.c: ${PROG}.c
@if which "${GINDENT}" >/dev/null 2>&1; then \
echo ${RM} -f $@; \
${RM} -f $@; \
echo "${GINDENT} < $< > $@"; \
${GINDENT} < $< > $@; \
elif which "${INDENT}" >/dev/null 2>&1; then \
echo ${RM} -f $@; \
${RM} -f $@; \
echo "${INDENT} < $< > $@"; \
${INDENT} < $< > $@; \
else \
echo "no intent tool found, ident $< yourself, sorry"; \
echo "exit 1"; \
exit 1; \
fi
##################
# 133t hacker rulz
##################
#
love:
@echo 'not war?'
@${TRUE}
haste:
$(MAKE) waste
@${TRUE}
waste:
@echo 'haste'
@${TRUE}
maker:
@echo 'Participate in a maker faire'
@${TRUE}
easter_egg:
@echo "you expected to often misunderstand this $${RANDOM} magic"
@echo "chongo '<was here>' /\\oo/\\"
@echo "Eggy"
sandwich: easter_egg
@if [ `id -u` -eq 0 ]; then \
echo 'Okay.'; \
echo "$${RANDOM}`date +%s`$${RANDOM}" > $@; \
else \
echo 'What? Make it yourself.'; \
exit 1; \
fi
# Understand the history of the Homebrew Computer Club
# as well as the West Coast Computer Faire and
# you might be confused different. :-)
#
supernova: sandwich
@-if [ -r .code_anal ]; then \
${RM} -f .code_anal_v6; \
else \
echo "planet deniers, like some members of the IAU, are so cute when they try to defend their logic"; \
fi
@echo "A $@ helps ${MAKE} the elements that help form planets"
@${TRUE}
deep_magic: supernova
@-if [ -r .code_anal ]; then \
ccode_analysis --deep_magic 7889066cdbdf09b0408021754586e895be641cc9be29e7eafd3ca65359541f17 \
--FNV1a_hash_512_bit -v2 "${PROG}" "${PROG}.c"; \
else \
echo "Wrong! Do it again!"; \
sleep 2; \
echo "Wrong! Do it again!"; \
sleep 2; \
echo "Wrong! Do it again!"; \
fi
@${TRUE}
magic: deep_magic
@-if [ -r .code_anal ]; then \
ccode_analysis --level 20003 --mode 5717175 --FNV1a_hash_512_bit -v2 "${PROG}" "${PROG}.c"; \
else \
echo "If you don't eat yer meat, you can't have any pudding!"; \
echo "How can you have any pudding if you don't eat yer meat?!"; \
fi
@${TRUE}
# The IOCCC resident astronomer states
#
charon: magic
@echo "$@ is a dwarf planet"
@echo "dwarf is a type of planet"
@echo "therefore IAU, $@ is a planet"
pluto: charon
${MAKE} charon
@echo "$@ is a dwarf planet"
@echo "dwarf is a type of planet"
@echo "therefore, $@ is a planet"
@echo "having lots of planets is good feature because supernovae can help ${MAKE} a lot of them"
+168 -171
View File
@@ -1,4 +1,4 @@
Best Curses Game: # Best Curses Game:
Kevin Pulo Kevin Pulo
School of Information Technologies School of Information Technologies
@@ -8,188 +8,185 @@ Best Curses Game:
http://www.kev.pulo.com.au/ http://www.kev.pulo.com.au/
# To build:
Judge's Remarks: ```sh
make
```
To build: ### To run:
make kev ```sh
./kev
```
Try: ### Try:
./kev ```sh
./kev localhost
```
and then in another window, ## Judges' comments:
./kev localhost Continuing with this year's "retro game" theme, this is another old game;
arguably, one of the oldest. Requires a functioning network, and curses.
Continuing with this year's "retro game" theme, this is another old game; The graphics aren't the impressive part; the graphics and network are.
arguably, one of the oldest. Requires a functioning network, and curses. How many games come out at $50 and still require you to wait for a patch
to come out before you can play multiplayer? This one works out of the
box.
The graphics aren't the impressive part; the graphics and network are. ## Author's comments:
How many games come out at $50 and still require you to wait for a patch
to come out before you can play multiplayer? This one works out of the NETWORK P*NG!
box. [=================]
Kevin Pulo
kev@pulo.com.au
Selected Author's Comments: ### REQUIREMENTS
NETWORK P*NG! * TCP sockets
[=================] * curses
* usleep
Kevin Pulo ### DESCRIPTION
kev@pulo.com.au
This program is a two-player networked version of the eighties
arcade classic, "pong". It uses standard TCP sockets to
REQUIREMENTS communicate over the net, and ncurses for display. It supports
------------ variable terminal sizes (though both players must have the same
terminal size) and game speeds. Each player has a paddle to hit
* TCP sockets the ball, and you get points for getting the ball past your
* curses opponent's paddle. It's pretty fun! :)
* usleep
### RUNNING
DESCRIPTION Run the server first without any command line arguments, ie.
-----------
```sh
This program is a two-player networked version of the eighties ./kev
arcade classic, "pong". It uses standard TCP sockets to ```
communicate over the net, and ncurses for display. It supports
variable terminal sizes (though both players must have the same Then run the client with a single command line argument which is
terminal size) and game speeds. Each player has a paddle to hit the name of the machine running the server, eg.
the ball, and you get points for getting the ball past your
opponent's paddle. It's pretty fun! :) ```sh
./kev localhost
```
RUNNING
------- Make sure that the terminals on both ends are the same size.
Also, the TCP port number specified in the build file mustn't be
Run the server first without any command line arguments, ie. blocked by a firewall.
./kev Here's a good quick example to see it in action on your own
machine, assuming you have Xwindows:
Then run the client with a single command line argument which is
the name of the machine running the server, eg. ```sh
xterm -geometry 80x40 -fg green -bg black -fn 9x15bold -e ./kev &
./kev localhost xterm -geometry 80x40 -fg green -bg black -fn 9x15bold -e ./kev localhost&
```
Make sure that the terminals on both ends are the same size.
Also, the TCP port number specified in the build file mustn't be ### PLAYING
blocked by a firewall.
Your paddle is the one at the bottom of the screen, your opponent
Here's a good quick example to see it in action on your own is at the top. To move your paddle left, hold down ',' (ie. '<'
machine, assuming you have Xwindows: but don't press shift). To move your paddle right, hold down '.'.
To quit, either player may press 'q'.
xterm -geometry 80x40 -fg green -bg black -fn 9x15bold -e ./kev &
xterm -geometry 80x40 -fg green -bg black -fn 9x15bold -e ./kev localhost& The current score is shown on the left side of the halfway line.
Your score is the lower number, your opponents score is the upper
number. Your score is the number of times your opponent has
PLAYING missed the ball.
-------
You can control the speed of the ball by the motion of your paddle
Your paddle is the one at the bottom of the screen, your opponent when the ball hits it. If your paddle is still, then the ball
is at the top. To move your paddle left, hold down ',' (ie. '<' just bounces normally off it. If your paddle is moving in the
but don't press shift). To move your paddle right, hold down '.'. same direction as the ball, then the ball's speed in that
To quit, either player may press 'q'. direction will increase. If your paddle is moving in the opposite
direction to the ball, then the ball's speed in that direction
The current score is shown on the left side of the halfway line. will decrease (or if the ball is going slowly enough, it'll turn
Your score is the lower number, your opponents score is the upper around).
number. Your score is the number of times your opponent has
missed the ball. You might want to increase your keyboard repeat rate before
playing. On the Linux console try "kbdrate -r 24.0 -d 250"
You can control the speed of the ball by the motion of your paddle (kbdrate might be "hidden" from normal users in /sbin, and you
when the ball hits it. If your paddle is still, then the ball might need to be root anyway), in Xwindows try "xset r rate 250
just bounces normally off it. If your paddle is moving in the 24" (find out your current rate first with "xset q", so that you
same direction as the ball, then the ball's speed in that can reset it later).
direction will increase. If your paddle is moving in the opposite
direction to the ball, then the ball's speed in that direction Look below in the Building section for info on how to speed up or
will decrease (or if the ball is going slowly enough, it'll turn slow down the game (useful if your increase or decrease the
around). terminal size).
You might want to increase your keyboard repeat rate before ### BUILDING
playing. On the Linux console try "kbdrate -r 24.0 -d 250"
(kbdrate might be "hidden" from normal users in /sbin, and you Just run the Makefile as above. The "SPEED" variable in the Makefile
might need to be root anyway), in Xwindows try "xset r rate 250 controls the speed of the game (defaults to 50). This speed is
24" (find out your current rate first with "xset q", so that you the delay between frames in milliseconds. Thus a value of 0 will
can reset it later). make the game go as fast as your network can handle, and values
less than 50 are useful for larger terminals or more exciting
Look below in the Building section for info on how to speed up or games. The program needs bandwidth equal to 1/s bytes per second
slow down the game (useful if your increase or decrease the (where "s" is the speed value). Any latency on the network will
terminal size). be added to s - so you should probably subtract any latency from
the value of s you want to have. Given that loopback and fast
Ethernet LANs are both much less than 1ms of latency, you should
BUILDING only need to worry about this if you plan on playing over a slower
-------- link like a cable modem, DSL, or (God-forbid) dialup.
Just run the Makefile as above. The "SPEED" variable in the Makefile The TCP port to use for network communications is specified by the
controls the speed of the game (defaults to 50). This speed is "PORT" variable in the Makefile. If the default of 5455 is
the delay between frames in milliseconds. Thus a value of 0 will blocked for whatever reason, you can change it to something else.
make the game go as fast as your network can handle, and values Of course if you use a port < 1024, you'll need to be root.
less than 50 are useful for larger terminals or more exciting
games. The program needs bandwidth equal to 1/s bytes per second ### OBFUSCATION
(where "s" is the speed value). Any latency on the network will
be added to s - so you should probably subtract any latency from The program's broad structure is fairly straightforward, but
the value of s you want to have. Given that loopback and fast individual tasks are rarely done in a straightforward manner. ;)
Ethernet LANs are both much less than 1ms of latency, you should
only need to worry about this if you plan on playing over a slower Identifier names have mostly been chosen to resemble paddles and
link like a cable modem, DSL, or (God-forbid) dialup. balls, and to generally decrease readability.
The TCP port to use for network communications is specified by the The source has been cleverly formatted to resemble one of the
"PORT" variable in the Makefile. If the default of 5455 is paddles from the game, rotated 90 degrees. ;) (The "source
blocked for whatever reason, you can change it to something else. paddle" has approximately the same aspect ratio as the game at 80
Of course if you use a port < 1024, you'll need to be root. columns wide, which is 1:10.)
Finally, the number of "non-whitespace characters" (as defined by
OBFUSCATION the rules) in the file is exactly 2048, which I think is rather
----------- unexpectedly cool. :)
The program's broad structure is fairly straightforward, but ### BUGS
individual tasks are rarely done in a straightforward manner. ;)
There are 3 warnings when I compile with gcc 2.95.3 (-Wall -ansi
Identifier names have mostly been chosen to resemble paddles and -pedantic) on my Linux system, but all are completely harmless.
balls, and to generally decrease readability.
I don't like the curses and/or termcaps/terminfos on IRIX and
The source has been cleverly formatted to resemble one of the Solaris (the only two non-Linux systems I have access to).
paddles from the game, rotated 90 degrees. ;) (The "source Despite calling timeout(0), notimeout(win, TRUE), nodelay(win,
paddle" has approximately the same aspect ratio as the game at 80 TRUE) and/or keypad(win, FALSE), it still seems to force a delay
columns wide, which is 1:10.) into calls to getch() - I'm guessing at a termcap/terminfo level.
At any rate, I can't seem to force no delay. This is a shame,
Finally, the number of "non-whitespace characters" (as defined by because it basically plays havoc with the input code, particularly
the rules) in the file is exactly 2048, which I think is rather the read-ahead canceller. It still works, but not nearly as well
unexpectedly cool. :) (keypresses are dodgey and holding down keys doesn't always work),
and so I _much_ prefer and recommend Linux libncurses.
BUGS Sometimes when 'q' is pressed in one, the other will crash out
---- with "Broken pipe".
There are 3 warnings when I compile with gcc 2.95.3 (-Wall -ansi If the specified port can't be bound or connected to, the program
-pedantic) on my Linux system, but all are completely harmless. segfaults.
I don't like the curses and/or termcaps/terminfos on IRIX and If your terminal is too wide (we're talking gigantic here - over
Solaris (the only two non-Linux systems I have access to). 500 characters wide) then the program can segfault. It's also
Despite calling timeout(0), notimeout(win, TRUE), nodelay(win, possible to crash the program a player scores over a billion
TRUE) and/or keypad(win, FALSE), it still seems to force a delay points (1e9). Maybe you can consider that the goal... ;)
into calls to getch() - I'm guessing at a termcap/terminfo level.
At any rate, I can't seem to force no delay. This is a shame, If you run the client and server on different architectures, both
because it basically plays havoc with the input code, particularly architectures need to have the same character systems (ie. don't
the read-ahead canceller. It still works, but not nearly as well try mixing ASCII and EBCDIC). It is independent of endianness
(keypresses are dodgey and holding down keys doesn't always work), though.
and so I _much_ prefer and recommend Linux libncurses.
Sometimes when 'q' is pressed in one, the other will crash out
with "Broken pipe".
If the specified port can't be bound or connected to, the program
segfaults.
If your terminal is too wide (we're talking gigantic here - over
500 characters wide) then the program can segfault. It's also
possible to crash the program a player scores over a billion
points (1e9). Maybe you can consider that the goal... ;)
If you run the client and server on different architectures, both
architectures need to have the same character systems (ie. don't
try mixing ASCII and EBCDIC). It is independent of endianness
though.