SE1SA5 – Programming Project Review

As part of my degree studies at the University of Reading I was required to design and implement a either a Chatbot, or code analysis program in C.  I opted for the former project as I thought it would be a more interesting challenge.

Sinclair Spectrum +2The first considerations were: how do Chatbots work; how are they implemented; are there existing examples of source to reference?  Unfortunately it would seem as though C is not the best programming language to choose to develop a Chatbot; a point noted in a Tweet from Shirley Williams.

I looked around for quite a while at existing implementations and kept coming across A.L.I.C.E and ELIZA, two famous Chatbots that have been influential in the development of games and other software since their creation.  Needless to say it was unrealistic to expect a similarly functional program to be designed, developed and tested in the time allowed with the skills acquired over the course so far; so I set about desiging a very simple Chatbot to ask a few questions, remember information and perform some basic deduction.

The errors I continually came across were generally my fault; simple problems such as using an ‘=’ sign when not appropriate, or missing off a semicolon from the end of a statement, although there were one or two interesting issues that kept me thinking for hours at a time, most notably: getchar().

printf("Ready? (y or n)n");

userAnswer = getchar();

This code should ask the simple question requiring a ‘y’ or ‘n’ answer, it should then read in the answer to the ‘userAnswer’ variable using getchar(); however, every time I ran the program it would seem to skip over line #58 and end the program.  I spent a long time searching for the answer, and eventually discovered that getchar() was registering a previous carriage return as an input, and was in fact working.  The simplest, albeit least elegant solution was to run the line twice, thereby avoiding the problem:

printf("Ready? (y or n)n");

userAnswer = getchar();
userAnswer = getchar();	

I also struggled getting my head round nested IF statements; not particularly hard in principle, but difficult to keep track of in practise.

I am not a particularly confident programmer, most especially in C, so I deliberately set out to keep the program small, simple and most of all – working! I know that the program will not work as intended on other operating systems, this is due wholly to the fact that I have used code to clear the output screen, and to pause the program that is compatible with Windows only; there are similar functions that will also work in Linux, but for the moment the program will only work in Windows:

int clearScreen()
{
	/*	Function clears the standard
		output, only works in Windows.
	*/

	system("cls");
	return 0;
}
int pauseProgram()
{
	/*	Function pauses program,
		waits for user to press any key,
		only works in Windows.
	*/
	system("PAUSE");
	return 0;
}

In conclusion I would say that the assignment was challenging and enjoyable, but not without its difficulties. I would have preferred to develop the program in C++, most especially as our lectures had moved onto C++ already by the time the assignment started; remembering to switch back to C commands was an extra consideration which I think was a disadvantage.

I have certainly learned to structure my code and comment sensibly, as well as learning the need for a solid set of specifications rather than programming on the fly. Even if the specifications are small in number, it does not mean they are easy to implement.

James

Read More

%d bloggers like this: