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
#
# 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:
#
# 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/
SHELL= /bin/sh
CAT= cat
RM= rm
SED= sed
TRUE= true
#CINCLUDE= -I ${HOMEBREW_PREFIX}/include/SDL2
# optimization
#############################
# shell used by this Makefile
#############################
#
# Most compiles will safely use -O2. Some can use only -O.
# A few compilers have broken optimizers and thus you may
# not want anything.
SHELL= bash
#######################
# 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= -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,
# 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}
CFLAGS= ${CSTD} ${CWARN} ${ARCH} ${CDEFINE} ${CINCLUDE} ${OPT}
# NOTE: On some systems, the library path does not include the location
# of the X11 libraries. You might need to use a -L/path/to/X11/lib/dir
# in order to compile with these libs.
# Libraries needed to build
#
X11CCFLAGS= -I/usr/X11R6/include -I/usr/X11R6/include/X11 -I/usr/include/X11
#X11CCFLAGS=
X11LDFLAGS= -L/usr/X11R6/lib -Wl,-R/usr/X11R6/lib
#X11LDFLAGS=
#LIBS=
LIBS= -lncurses
#LIBS= -L ${X11_LIBDIR} -lX11
#LIBS= `${SDL2_CONFIG} --libs`
# ANSI compiler
#
# 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.
# C compiler to use
#
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 \
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
ifeq ($(CC),clang)
#
anonymous: anonymous.c
magic='${MAY_NEED_GCC} -O1'; \
X='-DA(X)=#X'; \
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
CSILENCE+= -Wno-float-conversion -Wno-implicit-int-conversion -Wno-missing-prototypes \
-Wno-missing-variable-declarations -Wno-poison-system-directories \
-Wno-shorten-64-to-32 -Wno-sign-conversion
#
bellard: bellard.c
${CC} -rdynamic ${CFLAGS} bellard.c -o bellard -ldl
bellard_files: bellard.otccex.c
# Best short program
CWARN+= -Weverything
#
cheong: cheong.c
${CC} ${CFLAGS} cheong.c -o cheong
endif
# Most obfuscated sound
# Specific add-ons or replacements for gcc only
#
coupard: coupard.c
${CC} ${CFLAGS} -o coupard coupard.c
# Worst Driver
ifeq ($(CC),gcc)
#
ctk: ctk.c
${CC} ${CFLAGS} -o ctk ctk.c
# Worst AI
#CSILENCE+=
#
dgbeards: dgbeards.c
${CC} ${CFLAGS} -DE=break -DF=char -DK=case -DP=int -DR=return \
-DI=0xFFFF dgbeards.c -o dgbeards
# Best abuse of the C preprocessor
#CWARN+=
#
herrmann1: herrmann1.c herrmann1.sh
@echo "NOTE: $@ must be built/run using the script $@.sh"
${SHELL} ./herrmann1.sh
endif
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
${MAY_NEED_GCC} ${CFLAGS} herrmann2.c -o herrmann2 \
-include /usr/include/stdlib.h -include /usr/include/stdio.h \
-include /usr/include/time.h -include /usr/include/unistd.h
herrmann2_files: herrmann2.cup herrmann2.ioccc
# Best Of Show
OBJ= ${PROG}.o
DATA=
TARGET= ${PROG}
#
jason: jason.c
${CC} ${CFLAGS} -o jason jason.c
ALT_OBJ=
ALT_TARGET=
# Best Curses Game
#################
# build the entry
#################
#
kev: kev.c
${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
all: data ${TARGET}
@${TRUE}
install: all
${CAT} ${WINNERS} ${ALT_NAMES} > /dev/null
.PHONY: all alt data everything clean clobber install \
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
School of Information Technologies
@@ -8,188 +8,185 @@ Best Curses Game:
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;
arguably, one of the oldest. Requires a functioning network, and curses.
The graphics aren't the impressive part; the graphics and network are.
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.
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.
## Author's comments:
NETWORK P*NG!
[=================]
Kevin Pulo
kev@pulo.com.au
Selected Author's Comments:
### REQUIREMENTS
NETWORK P*NG!
[=================]
* TCP sockets
* curses
* usleep
Kevin Pulo
kev@pulo.com.au
REQUIREMENTS
------------
* TCP sockets
* curses
* usleep
DESCRIPTION
-----------
This program is a two-player networked version of the eighties
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
terminal size) and game speeds. Each player has a paddle to hit
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.
./kev
Then run the client with a single command line argument which is
the name of the machine running the server, eg.
./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
blocked by a firewall.
Here's a good quick example to see it in action on your own
machine, assuming you have Xwindows:
xterm -geometry 80x40 -fg green -bg black -fn 9x15bold -e ./kev &
xterm -geometry 80x40 -fg green -bg black -fn 9x15bold -e ./kev localhost&
PLAYING
-------
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. '<'
but don't press shift). To move your paddle right, hold down '.'.
To quit, either player may press 'q'.
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
missed the ball.
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
just bounces normally off it. If your paddle is moving in the
same direction as the ball, then the ball's speed in that
direction will increase. If your paddle is moving in the opposite
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
around).
You might want to increase your keyboard repeat rate before
playing. On the Linux console try "kbdrate -r 24.0 -d 250"
(kbdrate might be "hidden" from normal users in /sbin, and you
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
can reset it later).
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
terminal size).
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
the delay between frames in milliseconds. Thus a value of 0 will
make the game go as fast as your network can handle, and values
less than 50 are useful for larger terminals or more exciting
games. The program needs bandwidth equal to 1/s bytes per second
(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 value of s you want to have. Given that loopback and fast
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
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
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
individual tasks are rarely done in a straightforward manner. ;)
Identifier names have mostly been chosen to resemble paddles and
balls, and to generally decrease readability.
The source has been cleverly formatted to resemble one of the
paddles from the game, rotated 90 degrees. ;) (The "source
paddle" has approximately the same aspect ratio as the game at 80
columns wide, which is 1:10.)
Finally, the number of "non-whitespace characters" (as defined by
the rules) in the file is exactly 2048, which I think is rather
unexpectedly cool. :)
BUGS
----
There are 3 warnings when I compile with gcc 2.95.3 (-Wall -ansi
-pedantic) on my Linux system, but all are completely harmless.
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,
TRUE) and/or keypad(win, FALSE), it still seems to force a delay
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,
because it basically plays havoc with the input code, particularly
the read-ahead canceller. It still works, but not nearly as well
(keypresses are dodgey and holding down keys doesn't always work),
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.
### DESCRIPTION
This program is a two-player networked version of the eighties
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
terminal size) and game speeds. Each player has a paddle to hit
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.
```sh
./kev
```
Then run the client with a single command line argument which is
the name of the machine running the server, eg.
```sh
./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
blocked by a firewall.
Here's a good quick example to see it in action on your own
machine, assuming you have Xwindows:
```sh
xterm -geometry 80x40 -fg green -bg black -fn 9x15bold -e ./kev &
xterm -geometry 80x40 -fg green -bg black -fn 9x15bold -e ./kev localhost&
```
### PLAYING
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. '<'
but don't press shift). To move your paddle right, hold down '.'.
To quit, either player may press 'q'.
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
missed the ball.
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
just bounces normally off it. If your paddle is moving in the
same direction as the ball, then the ball's speed in that
direction will increase. If your paddle is moving in the opposite
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
around).
You might want to increase your keyboard repeat rate before
playing. On the Linux console try "kbdrate -r 24.0 -d 250"
(kbdrate might be "hidden" from normal users in /sbin, and you
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
can reset it later).
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
terminal size).
### 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
the delay between frames in milliseconds. Thus a value of 0 will
make the game go as fast as your network can handle, and values
less than 50 are useful for larger terminals or more exciting
games. The program needs bandwidth equal to 1/s bytes per second
(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 value of s you want to have. Given that loopback and fast
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
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
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
individual tasks are rarely done in a straightforward manner. ;)
Identifier names have mostly been chosen to resemble paddles and
balls, and to generally decrease readability.
The source has been cleverly formatted to resemble one of the
paddles from the game, rotated 90 degrees. ;) (The "source
paddle" has approximately the same aspect ratio as the game at 80
columns wide, which is 1:10.)
Finally, the number of "non-whitespace characters" (as defined by
the rules) in the file is exactly 2048, which I think is rather
unexpectedly cool. :)
### BUGS
There are 3 warnings when I compile with gcc 2.95.3 (-Wall -ansi
-pedantic) on my Linux system, but all are completely harmless.
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,
TRUE) and/or keypad(win, FALSE), it still seems to force a delay
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,
because it basically plays havoc with the input code, particularly
the read-ahead canceller. It still works, but not nearly as well
(keypresses are dodgey and holding down keys doesn't always work),
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.