Download presentation
Presentation is loading. Please wait.
Published byGriselda Armstrong Modified over 9 years ago
1
1 CSE1301 Computer Programming: Lecture 25 Group Project: "Hunt the Wumpus”
2
2 Topics Motivation The Game: Hunt the Wumpus Project Specifications Design Document Marking Scheme Generating Random Numbers
3
3 Motivation Experience phases of the software development cycle –on a large software system –with other people (team effort) Apply software design and production principles –modular and well-structured –implementation and testing –incremental development –system integration
4
4 Motivation Put C programming concepts together for a snapshot of the "Big Picture" –variables and values –instructions, selection, iteration –use of functions, parameters and return values –pointers, arrays and struct's Experience the importance of documentation!
5
5 Tasks Analyse a problem specification Decompose a large problem into smaller sub-problems Design representation of data Write algorithms for functions Prepare design document Turn algorithms into code Test functions and complete program
6
6 The Game: Hunt the Wumpus The scenario: You are in the cave of the Wumpus. The Wumpus likes you very much, especially for breakfast. The objective: To avoid being eaten, you must locate the Wumpus, and shoot it with your tranquilizer gun.
7
7 The Wumpus Cave The Wumpus cave has rooms connected by narrow passageways. You travel from one room to another by moving through an exit in a particular direction (north, south, east or west).
8
8 Map of a sample cave (numbered circles are rooms):
9
9 However, there are hazards to beware of. Some rooms contain bottomless pits. –marked P in the sample map. Others contain gigantic bats that will pick you up and carry you to a randomly chosen room. –marked B in the sample map. One room contains the Wumpus. –marked W in the sample map. –Entering the room that holds the Wumpus causes instant death.
10
10 Fortunately, there are warning signs. If there is danger in an adjoining room (i.e. the danger is in the next room through a passageway): –you can feel the breeze from a pit –hear the bats –smell the Wumpus.
11
11 The Dart To win the game, you must capture the Wumpus with your tranquilizer dart. When you shoot a dart, it travels through three rooms, and it can turn any corners in passageways. The darts are "programmable." –Before you shoot a dart, you have to specify its flight path. –You say which direction it should take as it leaves each room.
12
12 If you shoot into a wall (i.e. in a direction where there is no exit to another room), there is a 50% chance it will rebound, or get stuck on the wall. If the dart rebounds, and you are in the same room, then there is a 50% chance it will knock you out. Otherwise, the dart will fly through any of the possible exits (chosen randomly) into an adjoining room. What happens to the dart’s flight path then?
13
13 If the dart returns to the room where you are (either because it bounced off a wall in another room, or you have programmed the dart to do so), you will also be knocked out. If the dart goes to a room where the Wumpus is, then the Wumpus is tranquilized and you win the game! You have 5 tranquilizer darts. What happens when you run out of darts?
14
14 Cave Specifications The cave layout specification should be stored in a file. –Your program should read in the cave layout from this input file. You design the format of the file, which should contain information about each room: –what's in a room: pit, bats or Wumpus –which directions have exits –which room does the passageway at each exit lead to
15
15 The initial location of the player can be: –selected by the player at the start of the game –selected randomly by the program –fixed for a given cave layout If the initial location is fixed for a given cave layout, then the cave specification file should also indicate the initial location.
16
16 User Interface This is not strictly specified - you can use your imaginations! A simple text-based user interface will do. –Note that your project will be marked for the quality of the system design and the programming of the underlying game “engine,” not for a fancy user interface. Minimal user input, such as: –possible action (move to next room, shoot a dart) –direction to move (north, east, south, west) –flight path of dart
17
17 For the program's output: –print out information about current room (where the exits are, what you can hear, feel or smell) –for the cave layout, you can either: display a map, but without the locations of the pits, bats or Wumpus; or print out current room number, and where each doorway leads to. (Recommended) – number of darts left What happens if you have no more darts left? –results of an action (eg. a wall hit your nose, the dart bounced off, the dart knocked you out, etc.)
18
18 You are in Room 5. You can see... North: passageway to Room 0 East : passageway to Room 1 South: passageway to Room 8 West : wall You can hear the bats. You can feel the breeze. You have 5 darts left. Enter action (1=Move, 2=Shoot, 9=Quit): 1 You have decided to move. Which direction? (8=North, 6=East, 4=West, 2=South): 4 Thud! You bumped your nose on a wall. No exit there. You are in Room 5. You can see... North: passageway to Room 0 East : passageway to Room 1 South: passageway to Room 8 West : wall Sample Interface: Moving to a Room continued...
19
19 You can hear the bats. You can feel the breeze. You have 5 darts left. Enter action (1=Move, 2=Shoot, 9=Quit): 1 You have decided to move. Which direction? (8=North, 6=East, 4=West, 2=South): 8 Taking North passageway to Room 0... You are in Room 0. Whoosh! You fell in a pit! Game over!
20
20 You are in Room 4. You can see... North: passageway to Room 0 East : wall South: passageway to Room 8 West : wall You can hear the bats. You can feel the breeze. You have 4 darts left. Enter action (M)ove, (S)hoot, (Q)uit: s You have decided to shoot a dart. Enter the dart's flight path: Path #1 (N)orth, (E)ast, (W)est, (S)outh: N Path #2 (N)orth, (E)ast, (W)est, (S)outh: E Path #3 (N)orth, (E)ast, (W)est, (S)outh: w From Room 4, the dart flies through North passageway to Room 0.. From Room 0, the dart flies through East passageway to Room 8... From Room 8, the dart flies through West passageway to Room 4... Ouch! The dart returned to your location and knocked you out! Game over! Sample Interface: Shooting a Dart
21
21 You are in Room 3. You can see... North: passageway to Room 0 East : passageway to Room 10 South: passageway to Room 7 West : passageway to Room 2 You can hear the bats. You can feel the breeze. You have 5 darts left. Enter action (1=Move, 2=Shoot, 9=Quit): 2 You have decided to shoot a dart. Enter the dart's flight path: Path #1 (1=North, 2=East, 3=West, 4=South): 3 Path #2 (1=North, 2=East, 3=West, 4=South): 4 Path #3 (1=North, 2=East, 3=West, 4=South): 2 The dart flies: Room 2... Room 6... Phew! You've tranquilized the Wumpus! Congratulations! Yet another example...
22
22 Design Document Data section –how data are represented in the program –actual C code for declaring structures and types –description of each member of the structure –documentation of how each structure should be initialised and used –assumptions and limitations
23
23 Modules section –structure chart showing the control and data coupling of the modules –description of the tasks of each module –actual C function prototype showing: function name return type parameter list –pre- and post-conditions of each function –assumptions and limitations
24
24 Program I/O section –data-flow diagram showing processing points, sources, sinks and storage –not so much about the user interface, although you may include a description of the user interface when describing data which go to the screen, and data typed in by the user
25
25 Algorithms section –algorithms for the modules –may be in pseudo-codes or flow diagrams –assumptions and limitations Test data section –based on algorithm (flow diagram) –must test every possible execution path of algorithm –may note limitations of program with regard to invalid data
26
26 Group organisation –equal distribution of labour –requires demonstrator's approval –will be basis for individual marks
27
27 Marking Scheme Preparation: – must be completed before Practical Session 10 –Read the project handout, analyse the problem, and draft a design of the system before coming to Practical Session 10. –individual or group preparation
28
28 Part 1: Design document –group mark –completeness of the document (project requirements, sections, etc.) –quality of the design (modular, cohesive, etc.) –To be marked by your demonstrator during Practical Session 10 or at the start of Practical Session 11. –Target: You should aim to complete the design document (or at least a draft) by the end of the first hour of Practical Session 10.
29
29 Part 2: Individual modules –individual mark, based on completeness and quality of the modules assigned to you –You need to have test programs which can demonstrate that your functions work on the test data. –(See handout for breakdown of marks) –no extra marks for doing other people's tasks, and no mark for submitting code which you did not write –You need to have done the coding and testing of high-priority modules and the prototype versions of your modules by the end of Practical Session 10. –To be marked by the end of Practical Session 11 (requires the design document).
30
30 Part 3: System integration –group mark –successful software integration –satisfaction of project specifications and requirements –To be marked by the end of Practical Session 11. –Last chance for Part 3 marking: first half-hour of Practical Session 12. Not a good option, as you risk not being able to complete Prac 12 in time.
31
31 Hints: A Room Room: 0 Contains: P (or W, B, E) 3 58 4 What if there is no passageway in this direction?
32
32 Hints: A Cave with n rooms Room: 0 Contains: P (or W, B, E) 3 58 4 0 Room: 0 Contains: P (or W, B, E) 3 58 4 Room: 0 Contains: P (or W, B, E) 3 58 4 Room: 0 Contains: P (or W, B, E) 3 58 4... 12n - 1 Room number / id
33
33 Generating a Random Number Use C function rand() Requires #include rand() generates an integer between 0 and RAND_MAX –RAND_MAX is #define -d in stdlib.h, and it is at least 32767
34
34 /* * NAME: * int randomNumberInRange (int min, int max) * * DESCRIPTION: * Returns a random integer which is greater than * or equal to min, and less than or equal to max. * * PRE: * min should be greater than or equal to 0. * min should be less than max. * max should be less than or equal to RAND_MAX. * * POST: * Returns an integer. * * NOTES: * The use of srand() with a systematically chosen * seed number is recommended, but not required * for the purposes of the project. See D&D * if you want to learn more about srand(). * */
35
35 int randomNumberInRange (int min, int max) { return ((rand () % (max - min + 1)) + min); } Example: x = randomNumberInRange(16,30); suppose rand() returns 403 max - min + 1 = 15 403 % 15 = 13 13 + 16 = 29 so x is 29
36
36 Miscellaneous Group coordination: Contact details! Questions? Have fun!
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.