-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRatMarket.java
More file actions
72 lines (62 loc) · 2.67 KB
/
RatMarket.java
File metadata and controls
72 lines (62 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package ratmarket;
import strategies.StrategyMap;
/**
* Runs a 2-player game of RatMarket.
* @param args[0] = the name of alice's strategy
* @param args[1] = the name of bob's strategy
*
* example: java TwoPlayerGame nit nit
*
* @author jeffreymeyerson
*
*/
public class RatMarket {
public final static int GOAL = 50;
public final static int STARTING_PRICE = 1 + Utilities.rand.nextInt(9);
public static void main(String[] args) {
StrategyMap.initialize();
Player alice = new Player("Alice");
Player bob = new Player("Bob");
alice.strategy = StrategyMap.get(args[0]);
bob.strategy = StrategyMap.get(args[1]);
printIntro();
int turn = 0;
Player currentPlayer;
boolean A_TURN = Utilities.rand.nextBoolean();
currentPlayer = A_TURN ? alice : bob;
System.out
.println("Alice and Bob flip a coin. It is randomly decided that "
+ currentPlayer.name + " will take the first turn.");
// Main game loop
while (alice.dollars < GOAL && bob.dollars < GOAL) {
turn++;
//TODO: this update should be moved to Market
if(Market.ratBucket != null){
Market.ratBucket.advance();
}
else
Market.ratBucket = Utilities.generateRatBucket();
printTurnDetails(alice, bob, currentPlayer, turn);
currentPlayer.takeTurn();
Market.updatePrice();
A_TURN = !A_TURN;
currentPlayer = A_TURN ? alice : bob;
}
System.out.println("The game is over. " + currentPlayer + " is the winner.");
}
static void printTurnDetails(Player alice, Player bob, Player currentPlayer, int turn){
System.out.println("**********Turn " + turn + ": "+ currentPlayer.name +"begins***********\n");
System.out.println("----------------------------\n");
System.out.println("Alice has " + alice.dollars + " dollars and " + alice.rats + " rats.");
System.out.println("Bob has " + bob.dollars + " dollars and " + bob.rats + " rats.");
System.out.println("ÉÉÉÉÉÉÉÉÉÉÉÉÉÉÉÉÉÉÉÉÉÉÉÉÉÉÉÉ\n");
System.out.println("The market price of a rat is $" + Market.ratPrice + ".");
System.out.println(Market.simplePriceHistory());
System.out.println(Market.ratBucket.getInfo());
System.out.println("----------------------------\n");
}
static void printIntro() {
System.out
.println("The future is an apocalyptic wasteland. The main source of meat humans find to consume is that of rats. Your goal is to play the market and buy and sell rats. You and your opponent compete by buying and selling rat holdings. Every turn there will be market prices to buy and sell rats, as well as a \"rat bucket\" that players bid on. The rat bucket is initialized as a number between 1 and 10. A rat is added to it after every turn.\n\nFirst player to $1000 wins.");
}
}