Download คณะ วิศวกรรมศาสตร์ มหาวิทยาลัย สงขลา นครินทร์

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
PRINCE OF SONGKLA UNIVERSITY
FACULTY OF ENIGNEERING
Midterm Examination: Semester I
Date: 2 August 2002
Subject: 240- 492 Games Programming with Java
Academic Year: 2002
Time: 13:30-16:30
Room: R301_1
Instructions:
This exam has 6 problems, 4 pages and 27 points. Please show all your work. This
exam is closed book and closed notes. No calculators will be allowed.
1
1. Suppose you must design and implement a single-player Tic-Tac-Toe game with a graphical user
interface.
1.1 What will the design sequence be for the game? Explain in detail what needs to be done at
each step. Do not limit your design to any particular programming tool or language.
Remember that Tic-Tac-Toe is a game for two players, so a single-player version plays
against the computer. (3 points)
1.2 If the topic is changed to require design for a two-player Tic-Tac-Toe (where Player A plays
against Player B), how would your design be affected? (1 point)
2. Consider the 4x4 maze given below:
14
24
34
44
13
23
33
43
12
22
32
42
11
21
31
41
Thick lines represent the walls of the maze, and the dotted lines represent cell boundaries.
Suppose there is a mouse that must travel inside this maze. The mouse cannot move through or over the
walls, but it can move where there are no walls. In other words, the mouse cannot move through the thick
lines but it can move through the dotted lines. Also, the mouse can move only one cell at a time.
Answer the following questions:
2.1 Let the mouse starts at cell 11. Show all the possible paths using a tree diagram. Label each
node using the corresponding cell coordinate. For example:
11
12
(3 points)
2
2.2 From your solution in 2.1, what is the average branching factor? What is the maximum depth
of the search path? (0.5 points)
2.3 If the goal of the mouse is to move from cell 11 to cell 44, Find the best path using a breadthfirst search algorithm. Your solution should be the sequence of cells which the mouse will
visit. (1.5 points)
2.4 Suppose the cost of moving from the current cell to the next cell equals 1 if no turning is
required (go straight), otherwise the cost is 3. Find the best path from cell 11 to 44 using the
best-first search algorithm. (3 points)
2.5 What should a heuristic function be if the A* search algorithm is used to find the best path?
Justify your answer. (1 points)
3. Determine the transformation matrix that rotates the point (10,5) about the point (2,3) for 90 degree in a
clockwise (ตามเข็มนาฬิกา) direction (2 points)
y
(10,5)
(2,3)
x
3
4. Describe the Java Games Profile. Do not include any Java code in your answer. (2)
5. Write a Java application which animates a red circle and a green circle inside a JPanel. The circles
should 'bounce' off the walls of the JPanel. When the circles pass over each other (intersect), the
string "Ouch" should be printed to the DOS window.
Ignore coding problems associated with the resizing of the application's JFrame.
Two useful methods in Java's Rectangle class:
Rectangle Rectangle(x, y, width, height)
// Create a Rectangle object whose top-left corner is specified
// by (x,y), with width and height
boolean intersects(Rectangle r)
// Does this Rectangle object intersect with Rectangle r?
Your code should use a single Timer object to drive the animations. (8)
6. Why is the MediaTracker class useful for writing Java Games? Your answer should include diagrams
and small code fragments. (2)
______________________________________________
4