Initial add (with Netbeans project and build script)
[shoot.git] / src / shoot_the_moon / Bid.java
blob81a3d111ca0a54d9cf933adbb0c7c5e219fb9c4d
1 package shoot_the_moon;
4 public final class Bid {
5 private int number;
6 private Trump trump;
8 private boolean isShoot;
9 private boolean isPass;
10 private int shootNumber;
12 private Bid( int number, Trump trump, boolean isShoot, boolean isPass, int shootNumber ) {
13 this.number = number;
14 this.trump = trump;
15 this.isShoot = isShoot;
16 this.isPass = isPass;
17 this.shootNumber = shootNumber;
20 /**
21 * Makes a bid that is neither a pass or a shoot (ie. a normal bid)
22 * @param number The number of the bid (ie. "6 hearts"-> number = 6)
23 * @param trump The trump suit associated with the bid
24 * @return a new normal Bid with given number and trump
26 public final static Bid makeNormalBid( int number, Trump trump ) {
27 return new Bid( number, trump, false, false, -1 );
30 /**
31 * Makes a bid that is a pass
32 * @return a new Bid that represents a pass
34 public final static Bid makePassBid( ) {
35 return new Bid( -1, null, false, true, -1 );
38 /**
39 * Makes a shoot bid
40 * @param shootNumber Single shoot = 1, Double shoot = 2, etc...
41 * @param trump trump suit to shoot in
42 * @return a new Shoot bid with given shoot number and trump
44 public final static Bid makeShootBid( int shootNumber, Trump trump ) {
45 return new Bid( -1, trump, true, false, shootNumber );
48 /**
49 * @return true if this bid is a pass, false otherwise
51 public boolean isPass() {
52 return isPass;
55 /**
56 * @return true if this bid is a shoot, false otherwise
58 public boolean isShoot() {
59 return isShoot;
62 /**
63 * @return true if this bid is neither a shoot or a pass, false otherwise
65 public boolean isNormalBid() {
66 return ( !isPass && !isShoot );
69 /**
70 * Gets the number associated with a normal bid. This method will throw a RuntimeException if the bid is not a normal bid (ie shoot or pass)
71 * @return the number associated with the bid (ie. "I bid 5 hearts"-> number = 5)
73 public int getNumber() {
74 if ( isShoot || isPass ) {
75 throw new RuntimeException( "Illegal call to getNumber(), bid is a shoot or pass so it does not have a number.");
77 return number;
80 /**
81 * If the bid was a shoot, returns what kind of shoot it was.
82 * A single shoot will return 1, a double shoot will return 2, etc...
83 * Throws a runtime exception if the bid is not a shoot.
84 * @return the shoot number
86 public int getShootNumber() {
87 if ( !isShoot() ) {
88 throw new RuntimeException( "Illegal call to getShootNumber(), bid is not a shoot." );
90 return shootNumber;
93 /**
94 * Gets the trump associated with this bid. Throws a runtime exception if the bid was a pass.
95 * @return trump associated with bid
97 public Trump getTrump() {
98 if ( isPass ) {
99 throw new RuntimeException( "Illegal call to getTrump(), bid is a pass and has no trump" );
101 return trump;
105 * @param otherBid the other bid to check against
106 * @return whether or not this bid is greater than another bid (ie, would beat another bid for the highest bid)
108 public boolean isBetterThan( Bid otherBid ) {
109 if ( otherBid == null ) throw new RuntimeException( "Illegal null argument passed to Bid.isBetterThan()." );
110 //if other bid is a pass and this isn't, return true
111 if ( otherBid.isPass() & !this.isPass() ) return true;
112 //if this a shoot, but the other isn't, return true
113 if ( !otherBid.isShoot() & this.isShoot() ) return true;
114 //if both bids are passes, return false
115 if ( otherBid.isPass() && this.isPass() ) return false;
116 //if both bids are regular bids, check number
117 if ( otherBid.isNormalBid() && this.isNormalBid() ) {
118 return this.getNumber() > otherBid.getNumber();
120 //if both bids are shoots, check shoot number
121 if ( otherBid.isShoot() && this.isShoot() ) {
122 return this.getShootNumber() > otherBid.getShootNumber();
124 //all other cases, other bid is better, so return false
125 return false;
128 public String toString() {
129 if (isPass()) {
130 return "pass";
131 } else if ( isShoot() ) {
132 return "shoot(x" + shootNumber+") in " + trump.getName();
133 } else {
134 return number + " " + trump.getName();