-
Notifications
You must be signed in to change notification settings - Fork 0
/
Toss.java
114 lines (99 loc) · 2.28 KB
/
Toss.java
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package siteswapsuite;
public class Toss {
private ExtendedInteger height;
private int charge; // integer version of isAntitoss
private Integer destHand;
public Toss(int emptyHandIndex) {
this.height = new ExtendedInteger(0);
this.destHand = emptyHandIndex;
this.charge = 1;
}
public Toss(int height, int destHand, boolean isAntitoss) {
this.height = new ExtendedInteger(height);
this.destHand = destHand;
if(isAntitoss) {
this.charge = -1;
} else {
this.charge = 1;
}
}
public Toss(InfinityType height, boolean isAntitoss) {
this.height = new ExtendedInteger(height);
this.destHand = null;
if(isAntitoss) {
this.charge = -1;
} else {
this.charge = 1;
}
}
public ExtendedInteger height() {
return this.height;
}
public Integer destHand() {
return this.destHand;
}
public Boolean isAntitoss() {
if(this.charge == 0) {
return null;
} else {
if(this.charge == 1) {
return false;
} else {
return true;
}
}
}
// whether this toss has height zero
public boolean isZero() {
if(this.height.isInfinite()) {
return false;
}
return this.height.finiteValue() == 0;
}
// whether this toss is a true zero toss (not a 0x)
public boolean isZero(int sourceHand) {
if(this.height.isInfinite()) {
return false;
}
return this.height.finiteValue() == 0 && this.destHand == sourceHand;
}
public int charge() {
return this.charge;
}
public Toss getStarredToss() {
if(destHand != null) {
return new Toss(this.height.finiteValue(), (this.destHand + 1) % 2, this.charge < 0);
} else {
return this.deepCopy();
}
}
public void starify() {
if(destHand != null)
this.destHand = (this.destHand + 1) % 2;
}
public Toss deepCopy() {
if(this.height.isInfinite()) {
return new Toss(this.height.infiniteValue(), this.charge < 0);
} else {
return new Toss(this.height.finiteValue(), this.destHand, this.charge < 0);
}
}
public String toString() {
String out = "(";
if(this.height.isInfinite()) {
if(this.height.infiniteValue() == InfinityType.NEGATIVE_INFINITY) {
out += "-";
}
if(this.charge < 0) {
out += "_";
}
out += "&)";
} else {
if(this.charge < 0) {
out += "_";
}
out += height.finiteValue().toString() + ", " + destHand.toString() + ")";
}
return out;
}
}