文档介绍:Programming Thinking and Method (8)
Zhao Hai 赵海Department puter Science and EngineeringShanghai Jiao Tong University ******@.
1
Python Programming, 1/e
Objectives
To understand the potential applications of simulation as a way to solve real-world problems.
To understand pseudorandom numbers and their application in Monte Carlo simulations.
To understand and be able to apply top-down and spiral design techniques in plex programs.
2
Python Programming, 1/e
Objectives
To understand unit-testing and be able to apply this technique in the implementation and debugging plex programming.
3
Python Programming, 1/e
Simulating Racquetball
Simulation can solve real-world problems by modeling real-world processes to provide otherwise unobtainable information.
Computer simulation is used to predict the weather, design aircraft, create special effects for movies, etc.
4
Python Programming, 1/e
A Simulation Problem
Denny Dibblebit often plays racquetball with players who are slightly better than he is.
Denny usually loses his matches!
Shouldn’t players who are a little better win a little more often?
Susan suggests that they write a simulation to see if slight differences in ability can cause such large differences in scores.
5
Python Programming, 1/e
Analysis and Specification
Racquetball is played between two players using a racquet to hit a ball in a four-walled court.
One player starts the game by putting the ball in motion – serving.
Players try to alternate hitting the ball to keep it in play, referred to as a rally. The rally ends when one player fails to hit a legal shot.
6
Python Programming, 1/e
Analysis and Specification
The player who misses the shot loses the rally. If the loser is the player who served, service passes to the other player.
If the server wins the rally, a point is awarded. Players can only score points during their own service.
The first player to reach 15 points wins the game.
7
Python Programming, 1/e
Analysis