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
+425 -335

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"
+163 -166
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,31 +8,35 @@ 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
box.
Selected Author's Comments:
NETWORK P*NG! NETWORK P*NG!
[=================] [=================]
@@ -41,155 +45,148 @@ Selected Author's Comments:
kev@pulo.com.au kev@pulo.com.au
REQUIREMENTS ### REQUIREMENTS
------------
* TCP sockets * TCP sockets
* curses * curses
* usleep * usleep
### DESCRIPTION
DESCRIPTION
----------- This program is a two-player networked version of the eighties
arcade classic, "pong". It uses standard TCP sockets to
This program is a two-player networked version of the eighties communicate over the net, and ncurses for display. It supports
arcade classic, "pong". It uses standard TCP sockets to variable terminal sizes (though both players must have the same
communicate over the net, and ncurses for display. It supports terminal size) and game speeds. Each player has a paddle to hit
variable terminal sizes (though both players must have the same the ball, and you get points for getting the ball past your
terminal size) and game speeds. Each player has a paddle to hit opponent's paddle. It's pretty fun! :)
the ball, and you get points for getting the ball past your
opponent's paddle. It's pretty fun! :) ### RUNNING
Run the server first without any command line arguments, ie.
RUNNING
------- ```sh
./kev
Run the server first without any command line arguments, ie. ```
./kev Then run the client with a single command line argument which is
the name of the machine running the server, eg.
Then run the client with a single command line argument which is
the name of the machine running the server, eg. ```sh
./kev localhost
./kev localhost ```
Make sure that the terminals on both ends are the same size. 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 Also, the TCP port number specified in the build file mustn't be
blocked by a firewall. blocked by a firewall.
Here's a good quick example to see it in action on your own Here's a good quick example to see it in action on your own
machine, assuming you have Xwindows: machine, assuming you have Xwindows:
xterm -geometry 80x40 -fg green -bg black -fn 9x15bold -e ./kev & ```sh
xterm -geometry 80x40 -fg green -bg black -fn 9x15bold -e ./kev localhost& xterm -geometry 80x40 -fg green -bg black -fn 9x15bold -e ./kev &
xterm -geometry 80x40 -fg green -bg black -fn 9x15bold -e ./kev localhost&
```
PLAYING
------- ### PLAYING
Your paddle is the one at the bottom of the screen, your opponent Your paddle is the one at the bottom of the screen, your opponent
is at the top. To move your paddle left, hold down ',' (ie. '<' is at the top. To move your paddle left, hold down ',' (ie. '<'
but don't press shift). To move your paddle right, hold down '.'. but don't press shift). To move your paddle right, hold down '.'.
To quit, either player may press 'q'. To quit, either player may press 'q'.
The current score is shown on the left side of the halfway line. 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 Your score is the lower number, your opponents score is the upper
number. Your score is the number of times your opponent has number. Your score is the number of times your opponent has
missed the ball. missed the ball.
You can control the speed of the ball by the motion of your paddle You can control the speed of the ball by the motion of your paddle
when the ball hits it. If your paddle is still, then the ball when the ball hits it. If your paddle is still, then the ball
just bounces normally off it. If your paddle is moving in the just bounces normally off it. If your paddle is moving in the
same direction as the ball, then the ball's speed in that same direction as the ball, then the ball's speed in that
direction will increase. If your paddle is moving in the opposite direction will increase. If your paddle is moving in the opposite
direction to the ball, then the ball's speed in that direction direction to the ball, then the ball's speed in that direction
will decrease (or if the ball is going slowly enough, it'll turn will decrease (or if the ball is going slowly enough, it'll turn
around). around).
You might want to increase your keyboard repeat rate before You might want to increase your keyboard repeat rate before
playing. On the Linux console try "kbdrate -r 24.0 -d 250" playing. On the Linux console try "kbdrate -r 24.0 -d 250"
(kbdrate might be "hidden" from normal users in /sbin, and you (kbdrate might be "hidden" from normal users in /sbin, and you
might need to be root anyway), in Xwindows try "xset r rate 250 might need to be root anyway), in Xwindows try "xset r rate 250
24" (find out your current rate first with "xset q", so that you 24" (find out your current rate first with "xset q", so that you
can reset it later). can reset it later).
Look below in the Building section for info on how to speed up or Look below in the Building section for info on how to speed up or
slow down the game (useful if your increase or decrease the slow down the game (useful if your increase or decrease the
terminal size). terminal size).
### BUILDING
BUILDING
-------- Just run the Makefile as above. The "SPEED" variable in the Makefile
controls the speed of the game (defaults to 50). This speed is
Just run the Makefile as above. The "SPEED" variable in the Makefile the delay between frames in milliseconds. Thus a value of 0 will
controls the speed of the game (defaults to 50). This speed is make the game go as fast as your network can handle, and values
the delay between frames in milliseconds. Thus a value of 0 will less than 50 are useful for larger terminals or more exciting
make the game go as fast as your network can handle, and values games. The program needs bandwidth equal to 1/s bytes per second
less than 50 are useful for larger terminals or more exciting (where "s" is the speed value). Any latency on the network will
games. The program needs bandwidth equal to 1/s bytes per second be added to s - so you should probably subtract any latency from
(where "s" is the speed value). Any latency on the network will the value of s you want to have. Given that loopback and fast
be added to s - so you should probably subtract any latency from Ethernet LANs are both much less than 1ms of latency, you should
the value of s you want to have. Given that loopback and fast only need to worry about this if you plan on playing over a slower
Ethernet LANs are both much less than 1ms of latency, you should link like a cable modem, DSL, or (God-forbid) dialup.
only need to worry about this if you plan on playing over a slower
link like a cable modem, DSL, or (God-forbid) dialup. The TCP port to use for network communications is specified by the
"PORT" variable in the Makefile. If the default of 5455 is
The TCP port to use for network communications is specified by the blocked for whatever reason, you can change it to something else.
"PORT" variable in the Makefile. If the default of 5455 is Of course if you use a port < 1024, you'll need to be root.
blocked for whatever reason, you can change it to something else.
Of course if you use a port < 1024, you'll need to be root. ### OBFUSCATION
The program's broad structure is fairly straightforward, but
OBFUSCATION individual tasks are rarely done in a straightforward manner. ;)
-----------
Identifier names have mostly been chosen to resemble paddles and
The program's broad structure is fairly straightforward, but balls, and to generally decrease readability.
individual tasks are rarely done in a straightforward manner. ;)
The source has been cleverly formatted to resemble one of the
Identifier names have mostly been chosen to resemble paddles and paddles from the game, rotated 90 degrees. ;) (The "source
balls, and to generally decrease readability. paddle" has approximately the same aspect ratio as the game at 80
columns wide, which is 1:10.)
The source has been cleverly formatted to resemble one of the
paddles from the game, rotated 90 degrees. ;) (The "source Finally, the number of "non-whitespace characters" (as defined by
paddle" has approximately the same aspect ratio as the game at 80 the rules) in the file is exactly 2048, which I think is rather
columns wide, which is 1:10.) unexpectedly cool. :)
Finally, the number of "non-whitespace characters" (as defined by ### BUGS
the rules) in the file is exactly 2048, which I think is rather
unexpectedly cool. :) There are 3 warnings when I compile with gcc 2.95.3 (-Wall -ansi
-pedantic) on my Linux system, but all are completely harmless.
BUGS I don't like the curses and/or termcaps/terminfos on IRIX and
---- Solaris (the only two non-Linux systems I have access to).
Despite calling timeout(0), notimeout(win, TRUE), nodelay(win,
There are 3 warnings when I compile with gcc 2.95.3 (-Wall -ansi TRUE) and/or keypad(win, FALSE), it still seems to force a delay
-pedantic) on my Linux system, but all are completely harmless. 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,
I don't like the curses and/or termcaps/terminfos on IRIX and because it basically plays havoc with the input code, particularly
Solaris (the only two non-Linux systems I have access to). the read-ahead canceller. It still works, but not nearly as well
Despite calling timeout(0), notimeout(win, TRUE), nodelay(win, (keypresses are dodgey and holding down keys doesn't always work),
TRUE) and/or keypad(win, FALSE), it still seems to force a delay and so I _much_ prefer and recommend Linux libncurses.
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, Sometimes when 'q' is pressed in one, the other will crash out
because it basically plays havoc with the input code, particularly with "Broken pipe".
the read-ahead canceller. It still works, but not nearly as well
(keypresses are dodgey and holding down keys doesn't always work), If the specified port can't be bound or connected to, the program
and so I _much_ prefer and recommend Linux libncurses. segfaults.
Sometimes when 'q' is pressed in one, the other will crash out If your terminal is too wide (we're talking gigantic here - over
with "Broken pipe". 500 characters wide) then the program can segfault. It's also
possible to crash the program a player scores over a billion
If the specified port can't be bound or connected to, the program points (1e9). Maybe you can consider that the goal... ;)
segfaults.
If you run the client and server on different architectures, both
If your terminal is too wide (we're talking gigantic here - over architectures need to have the same character systems (ie. don't
500 characters wide) then the program can segfault. It's also try mixing ASCII and EBCDIC). It is independent of endianness
possible to crash the program a player scores over a billion though.
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.