| Assignment
5: Game Theory Fall 2006, David Matuszek |
Min |
||||||||||||||||||||
| 0 | 1 | 2 | ||||||||||||||||||
| Max |
|
|
||||||||||||||||||
Consider the following very simple "game." There is a two-dimensional array of numbers, and two players, Max and Minnie. At each turn, Max chooses some row and Min chooses some column. Where they intersect is the amount of money Min pays to Max (if it's negative, Max pays Min).
For example, if Max chooses row 1 and Min chooses column 1, then Max wins $14 from Min. But if Max chooses row 3 and Min chooses column 2, then Max pays Min $10. In general: Max wants larger numbers, Min wants smaller numbers.
How should they play?
|
|
|||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
For each player, we pick the "best of the worst." In this example, the worst Max can do if he picks row 0 is -9; if row 1, then 5; if row 2, then -8; and if row 3, then -0. Of these possible worst outcomes, Max prefers the largest, which is 5 (row 1).
Similarly, Min wants smaller numbers. The worst she can do if she picks column 0 is 10; if column 1, then 17; and if column 2, then 5. Of these possible worst outcomes, Min prefers the smallest, which is 5 (column 2).
Since the "best of the worst" (the maximum of the minimums) for Max is 5, and the "best of the worst" (the minimum of the maximums) for Min is also 5, then Max should always choose row 1, and Min should always choose column 2. This is called a saddle point.
Here's why: If Min does choose column 2, then Max will do worse by choosing any other row. And if Max does choose row 1, then Min will do worse by choosing any other column.
It is possible for there to be more than one saddle point, in which case they will all have the same value (for example, they will all be 5), and we don't care which one we find.
This program is a lot easier to test if it consists of a lot of little methods. I do recommend writing the tests first.
To write tests first:
The first time you try to create a JUnit test, Eclipse will tell you that JUnit isn't on your "build path," and will offer to add it. Let Eclipse add it. Depending on your installation, Eclipse may already know where to find it, or it may ask you to find it. If you have to find it, pick the Libraries tab, choose Add External JARs, and find it. It is probably in a place like eclipse > plugins > org.junit_3.8.1 > junit.jar. You don't have to create your unit tests this way. It's just a normal Java file--to add tests, just imitate the tests that are already there. |
Here are the methods and unit tests you should have (where each test is for a single method):
|
Each of these methods can be declared public (but they don't
have to be). Each of them really should be declared static (so you don't
need to create an otherwise unnecessary instance of SaddlePoint), but if
you haven't already declared them that way, you don't have to.
Important note: The JUnit method |
For testing purposes, you can use the above game,
int[][] with = {{-9, 12, -6},
{ 7, 14, 5},
{10, -8, 3},
{ 6, 17,-10}};
which has a saddle point, and the game
int[][] without = {{ 1, -2, 3},
{-6, 5, -4},
{ 7, -8, 9}};
which does not.
Your class should be named SaddlePoint, and it should have these methods:
|
The only method you should test is createRandomArray. Your testCreateRandomArray method should test that:
Thursday, October 12, before midnight.