As usual, create two directories for today's class. Create a
directory called lecture20
under activities, and
a directory called lab20
under labs.
Time to spin the wheel and find out what you will be submitting for your final portion of this weeks quiz grade.
Create a file called guessing_game.py
in your lecture20
directory. The program in this file should generate a random
number, and prompt the user to enter a guess of the number. The
user should be allowed to keep guessing until they get the guess correct.
Your program should indicate if the users guess is higher or lower than the randomly selected value.
I've been forcing you to do a lot of things this semester, and most of you are not sure exactly why. Let's spend some time exploring how to approach solving problems.
Read the following mini-assignment prompt. I will go through the "lazy" solution in class.
Create a program that draws a triangle and a random point and tests if the point is inside the triangle. The program should draw a triangle that takes up the majority of the window. You can pick the location of each of the corners, or vertices, of the triangle. The program should also generate and draw a random point in the window. The color of the circle should be determined by whether the point is inside or outside the triangle.
A point is inside a triangle if it is on the interior side of all three edges of the triangle. For example, the point P in the illustration below is on the interior side of the edge from B to C and the edge from C to A, but it is not on the interior side of the edge from A to B.
It is possible to determine which side of an edge a point is on using the equation:
Where V1 and V2 are vertices that define an edge of the triangle, and P is a point. If the vertex V1 is clockwise from V2, then s will be positive if P is on the interior side of the line segment between V1 and V2.
The Prisoners Dilemma is a classical psycological experiment that has deep ties to game theory as well. It was originally proposed in the 1950's, but research in the field continues to this day.
In the Prisoners Dilemma, two prisoners (A and B) are pitted against each other. Both prisoners are given the same options: confess to the crime, or deny the crime. They are even given the following information:
Write a program prisoners_dilemma.py
where you can play
the prisoners dilemma against a random computer. Your program
should keep track of how many years you (and the computer) serve in
each round. After some number of pre-defined rounds, print the
average number of years served by you, and the average number of
years served by the computer prisoner.
Make sure you test your program well. How many test cases do you need? Include your test cases in your program file. Comment them appropriately.
When you have finished, create a tar file of your lab20
directory. To create a tar file, execute the following commands:
cd ~/cs120/labs tar czvf lab20.tgz lab20/
To submit your activity, go to cseval.roanoke.edu. You should
see an available assignment called Lab Assignment 20
. Only
one of your pair should submit your activity. Make sure both partners
are listed in the header of your files.
Do not forget to email your partner today's files!