Wiggly Worms
1 Wiggly Worms in Software Engineering
- We used to give this Wiggly Worms as a code design project in "CS 101": Develop a wiggly worms game. Just using the keyboard, and console text display.
- In these lecture notes, a "working" version of an implementation is given. GUI is ignored. We do a simple console UI.
- We are assuming that we are "done" with requirements and specs. But, practice writing them.
- We are focused on the (i) use of Assertions, (ii) Design by Contract (DbC), and (iii) fluency in C++.
- Does it have bugs? Probably. What does it take to definitively say that it does or does not have bugs?
- Revise the working version so that it is in "proper" OOP form. As given, it is definitely improper! It is all in one file!
- How do we explain to a colleague/ classmate, in just one or two paragraphs, how we discovered and revised the classes?
- The implied design + code as-given do not do anything about the z-axis. Suggest ideas and implement.
- This being an interactive game, how do we test it?
2 Source Code Details
- The file ../Wiggly-Worms/worms-one-file.cpp.html implements a grass
roots game example of wiggly worms (scissor heads, cannibals, or
vegetarian kind) moving about.
sloccount cpp 373 (100.00%)
- The ./worms12-doc.html file has a few more details on the internals.
- There is a little JavaScript that colorizes the worms.cpp into ../Wiggly-Worms/worms-one-file.cpp.html. Here is a link to the plain text source code file: ./worms-one-file.cpp .
- ./GEN contains doxygen-erated listings.
2.1 Linux
- If you work on Linux, you will need to install
ncurses
related development files. https://www.cyberciti.biz/faq/linux-install-ncurses-library-headers-on-debian-ubuntu-centos-fedora/ is a decent tutorial. thor.cs.wright.edu
is a large Linux server located in CECS.- Login to thor.cs.wright.edu. All grad students can obtain an account. From outside campus, you need VPN.
g++ worms-one-file.cpp -o worms -lncurses
will compile and link the program.% file worms
The command namedfile
identifies the content of the named file.worms: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, not stripped
% ldd worms
The command namedldd
lists the dynamic libraries that the named program is linked with.linux-vdso.so.1 => (0x00007ffcfe126000) libncurses.so.5 => /lib64/libncurses.so.5 (0x000000382c000000) libstdc++.so.6 => /usr/local/lib64/libstdc++.so.6 (0x00002acef3b16000) libm.so.6 => /lib64/libm.so.6 (0x000000381b200000) libgcc_s.so.1 => /usr/local/lib64/libgcc_s.so.1 (0x00002acef3e27000) libc.so.6 => /lib64/libc.so.6 (0x000000381ae00000) libtinfo.so.5 => /lib64/libtinfo.so.5 (0x0000003829000000) libdl.so.2 => /lib64/libdl.so.2 (0x000000381b600000) ld.so => /lib64/ld-linux-x86-64.so.2 (0x000055d912f1c000)
2.2 Windows
- If you wish to work on Windows, use Windows-equivalents of ncurses. E.g., https://pdcurses.org/ or https://github.com/peterbrittain/asciimatics .
- There is also a contributed version ./worms-ktsalva-2013.cpp.html, by a past student that should be buildable on Windows. Here is a link to the plain text source code file: ./worms-ktsalva-2013.cpp .
3 Exercises
- Consider our Wiggly Worms program. (i) (10 points) Intuitively describe the "connectedness" of a worm's body from head to the tail. (ii) (10 points) State this as an assertion in mathematical notation using the typedefs originally given (see the link) or the class definitions you have derived from it.
- Consider our Wiggly Worms. We wish to describe how a worm crawls.
First, in English prose. Then, state this as pre- and
post-conditions for the method named
void live(WORM * wp)
- [After Debugging Lectures] Does our Wiggly Worms code have any bugs? We certainly did not do a spec. What def of bugs shall we use? Should we just use some tools, and copy-paste their output as an answer to this question? Note that some tools (eg PMD) show some questionable coding style, not bugs.
4 References
- Prabhaker Mateti, Lecture Notes on Design by Contract and SOLID Principles
- Prabhaker Mateti, Lecture Notes on Assertions in C++