Richard Ambler
7 August 2014
A Shiny remake of a (very) old computer game
Some background
In 1978, Workman Publishing published a book, BASIC Computer Games by David Ahl (editor), that contains lists of BASIC code for computer games. (The book is hosted online at atariarchives.org.)
One of the games in the book is called Mugwump. It is attributed to Bob Albrecht of People's Computer Company and students of Bud Valenti of Project SOLO.
The goal of the game is to guess where four mugwumps (yep, it is a real word!) are hiding on a 10 x 10 grid. After each guess, the distance from the guessed point to each remaining mugwump is returned as a set of clues that may be used to figure out where the mugwumps are hiding.
1978 being among the very early days of home computing, there was text-only output and users were expected to play Mugwump with the aid of a compass and some graph paper.
The image to the right is the relevant page from Basic Computer Games. Notice the grid provided so that readers could draw their own triangulation plots! (The page illustration is by George Beker).
Triangulation
plot(
0, 0,
xlim <- c(-0.5, 10.5),
ylim <- c(-0.5, 10.5),
type = "n",
xaxt = "n",
yaxt = "n",
xlab = "",
ylab = ""
)
for (i in 0:10) {
lines(
c(0, 10), c(i, i),
col = "darkgray"
)
lines(
c(i, i), c(0, 10),
col = "darkgray"
)
}
axis(
1, at = 0:10,
labels = 0:10, tick = FALSE
)
axis(
2, at = 0:10,
labels = 0:10, tick = FALSE
)
# example: let's draw a circle of
# radius 5 centred at (3, 4)
theta <- seq(0, 2 * pi, by = pi / 32)
lines(3 + 5 * cos(theta), 4 + 5 * sin(theta))
To the left is a segment of code that produces an example of a triangulation plot (above).
If a player guesses that a mugwump is hiding at the point (3, 4) and the clue returned is that the mugwump is actually 5 units away from this point, it would mean that the mugwump is somewhere on the circumference of the plotted circle that has radius 5 and is centered at the guessed point. This provides some information that may be useful in making the next guess!
My project
For this project I decided to create a Shiny version of Mugwump. Although the game is very simple it has everything in the project specifications for the course:
The screenshot to the right shows a game in which all four mugwumps have been found. The mugwumps and triangulation circles are plotted based on previous guesses of the user.
Project checklist
Is there some form of widget input?
I originally used sliderInput and a submitButton widgets to allow the player to choose the x and y coordinates and submit guesses. In the end, however, I decided to use the clickId parameter in the function plotOutput to effectively turn the output plot into an input widget. I also used a checkboxInput widget to allow the player to remove colour from the plot and thus make the game a little more demanding.
Did server.R perform some calculations on the input? Are the calculations displayed?
The distances between the guessed points and each of the mugwumps are, of course, calculated using the pythagorean theorem:
\[ d_{gm} = \sqrt{(x_g - x_m)^2 + (y_g - y_m)^2} \]
These calculated values are displayed in a table that logs the player's guesses and are used to perform the triangulation plots. I actually separated the programme logic from the server code by keeping it in a file called mugwump.R; the programme runs by having server.R reactively calling the relevant functions.
Thanks for your time!
And now to find some mugwumps…