In the climatic scene of the movie Wargames, the WOPR computer plays Tic-Tac-Toe. A question is asked, “Can the computer play itself?” This postulation forms the basis of all computer learning, but that wasn’t the puzzle for this month’s Exercise.
Continue reading
Author Archives: dgookin
Implementing Hunt the Wumpus in C
In last week’s Lesson, I described the history and gameplay for the classic text mode game, Hunt the Wumpus. The task of coding the game took considerably longer than writing the blog post.
Continue reading
Automated Guessing Game
Last month, I published a post of the classic programming chestnut, a number-guessing game. In the post, I wrote: “Variable tries
is set equal to 6 because I read somewhere that it’s possible to guess a value between 1 and 100 in six or fewer tries (though I’m probably incorrect).” And, yes, I was wrong.
Continue reading
Hunt the Wumpus
The game Hunt the Wumpus isn’t difficult to code in C. In fact, all you need do is start with the basic number-guessing game presented in last week’s Lesson and you can build just about any text-mode game. That’s what I did when I started my own C language version of Hunt the Wumpus.
Continue reading
The Essence of the Text Game
I was perusing Rosetta Code the other day, looking for more programming ideas to explore. One of the tasks provided, with examples in a variety of programming languages, was to code the old computer game Hunt the Wumpus.
Continue reading
Fun with the asprintf() Function
If you desire to store formatted output in a buffer, the snprintf() function, covered in last week’s Lesson, is a safe alternative to the standard Library sprintf() function. An even better choice is the asprintf() function.
Continue reading
Remove Trailing Blank Lines – Solution
The problem with snipping blank lines from the end of a file is storing the file as it’s processed. At least that’s the issue I faced as I worked through my solution to this month’s Exercise.
Continue reading
The snprintf() Function
Another non-standard library function is snprintf(). Like the strlcpy() and strlcat() functions shown in previous Lessons, snprintf() is safer than its standard Library counterpart, sprintf().
Continue reading
Remove Trailing Blank Lines
Recently, I wrote a utility that required the final line of text in a file to terminate with a special code. The code had to sit at the end of a line of text, not on a blank line. What I discovered is that many text files end with one or more blank lines.
Continue reading
My own strlcat() Function
Coding my own version of the non-standard strlcat() function proved to be a bit more work than I anticipated. That’s because I also had to code my own versions of the strcpy() and strlen() functions to make the thing work.
Continue reading