1 package shoot_the_moon
;
4 public final class Bid
{
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
) {
15 this.isShoot
= isShoot
;
17 this.shootNumber
= shootNumber
;
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 );
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 );
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
);
49 * @return true if this bid is a pass, false otherwise
51 public boolean isPass() {
56 * @return true if this bid is a shoot, false otherwise
58 public boolean isShoot() {
63 * @return true if this bid is neither a shoot or a pass, false otherwise
65 public boolean isNormalBid() {
66 return ( !isPass
&& !isShoot
);
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.");
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() {
88 throw new RuntimeException( "Illegal call to getShootNumber(), bid is not a shoot." );
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() {
99 throw new RuntimeException( "Illegal call to getTrump(), bid is a pass and has no 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
128 public String
toString() {
131 } else if ( isShoot() ) {
132 return "shoot(x" + shootNumber
+") in " + trump
.getName();
134 return number
+ " " + trump
.getName();