commit | author | age
|
b20e6d
|
1 |
package net.jacekk.brydz; |
JK |
2 |
|
|
3 |
public class BridgeCompute { |
|
4 |
protected int tricks[][] = { |
|
5 |
{0, 20, 40, 60, 80, 100, 120, 140}, // młodsze |
|
6 |
{0, 30, 60, 90, 120, 150, 180, 210}, // starsze |
|
7 |
{0, 40, 70, 100, 130, 160, 190, 220} // bez atu |
|
8 |
}; |
|
9 |
|
|
10 |
protected int wpadki[][][] = { |
|
11 |
{ // przed partią |
|
12 |
{0, 50, 100, 150, 200, 250, 300, 350, 400, 450, 500, 550, 600, 650}, // normalnie |
|
13 |
{0, 100, 300, 500, 700, 900, 1100, 1300, 1500, 1700, 1900, 2100, 2300, 2500}, // kontra |
|
14 |
{0, 200, 600, 1000, 1400, 1800, 2200, 2600, 3000, 3400, 3800, 4200, 4600, 5000} // rekontra |
|
15 |
}, |
|
16 |
{ // po partii |
|
17 |
{0, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300}, // normalnie |
|
18 |
{0, 200, 500, 800, 1100, 1400, 1700, 2000, 2300, 2600, 2900, 3200, 3500, 3800}, // kontra |
|
19 |
{0, 400, 1000, 1600, 2200, 2800, 3400, 4000, 4600, 5200, 5800, 6400, 7000, 7600} // rekontra |
|
20 |
} |
|
21 |
}; |
|
22 |
|
|
23 |
protected int PC[][][] = { |
|
24 |
{ // MY: przed, WY: przed partią |
|
25 |
{-1400, -1400, -1400, -1400, -1200, -1100, -1000, -900, -700, -600, -490, -460, -430, -400, -350, -300, -200, -110, -70, -50, 0, 50, 70, 110, 200, 300, 350, 400, 430, 460, 490, 600, 700, 900, 1000, 1100, 1200, 1400, 1400, 1400, 1400}, |
|
26 |
// MY: przed, WY: po partii |
|
27 |
{-2100, -2100, -2100, -2100, -1800, -1650, -1500, -1350, -1050, -800, -690, -660, -630, -600, -520, -440, -290, -110, -70, -50, 0, 50, 70, 110, 200, 300, 350, 400, 430, 460, 490, 600, 700, 900, 1000, 1100, 1200, 1400, 1400, 1400, 1400} |
|
28 |
}, |
|
29 |
{ // MY: po, WY: przed partią |
|
30 |
{-1400, -1400, -1400, -1400, -1200, -1100, -1000, -900, -700, -600, -490, -460, -430, -400, -350, -300, -200, -110, -70, -50, 0, 50, 70, 110, 290, 440, 520, 600, 630, 660, 690, 800, 1050, 1350, 1500, 1650, 1800, 2100, 2100, 2100, 2100}, |
|
31 |
// MY: po, WY: po partii |
|
32 |
{-2100, -2100, -2100, -2100, -1800, -1650, -1500, -1350, -1050, -800, -690, -660, -630, -600, -520, -440, -290, -110, -70, -50, 0, 50, 70, 110, 290, 440, 520, 600, 630, 660, 690, 800, 1050, 1350, 1500, 1650, 1800, 2100, 2100, 2100, 2100} |
|
33 |
} |
|
34 |
}; |
|
35 |
|
|
36 |
protected int IMPs[] = {0, 20, 50, 90, 130, 170, 220, 270, 320, 370, 430, 500, 600, 750, 900, 1100, 1300, 1500, 1750, 2000, 2250, 2500, 3000, 3500, 4000, 9999999}; |
|
37 |
|
|
38 |
protected int percent_points[][] = { |
|
39 |
{0, 50, 90, 120, 150, 180, 210, 300, 400, 430, 460, 490, 520, 800, 920, 940, 980, 990, 1020, 1400, 1440, 1520, 1530, 9999999}, // przed |
|
40 |
{0, 50, 90, 120, 150, 180, 210, 500, 600, 360, 660, 690, 720, 810, 1370, 1390, 1430, 1440, 1470, 1700, 2000, 2220, 2230, 9999999} //po |
|
41 |
}; |
|
42 |
|
|
43 |
protected int percent_PC[] = {0, 6, 10, 16, 21, 25, 31, 35, 9999999}; |
|
44 |
|
|
45 |
protected int percent[][] = { |
|
46 |
{-1, -1, -1, 50, 44, 26, 8, 0}, |
|
47 |
{83, 74, 65, 56, 47, 29, 11, 0}, |
|
48 |
{86, 77, 68, 59, 50, 32, 14, 0}, |
|
49 |
{89, 80, 71, 62, 53, 35, 17, 0}, |
|
50 |
{92, 83, 74, 65, 56, 38, 20, 2}, |
|
51 |
{95, 86, 77, 68, 59, 41, 23, 5}, |
|
52 |
{98, 89, 80, 71, 62, 44, 26, 8}, |
|
53 |
{100, 92, 83, 74, 65, 47, 29, 11}, |
|
54 |
{100, 95, 86, 77, 68, 50, 32, 14}, |
|
55 |
{100, 98, 89, 80, 71, 53, 35, 17}, |
|
56 |
{100, 100, 92, 83, 74, 56, 38, 20}, |
|
57 |
{100, 100, 95, 86, 77, 59, 41, 23}, |
|
58 |
{100, 100, 98, 89, 80, 62, 44, 26}, |
|
59 |
{100, 100, 100, 92, 83, 65, 47, 29}, |
|
60 |
{100, 100, 100, 95, 86, 68, 50, 32}, |
|
61 |
{100, 100, 100, 98, 89, 71, 53, 35}, |
|
62 |
{100, 100, 100, 100, 92, 74, 56, 38}, |
|
63 |
{100, 100, 100, 100, 95, 77, 59, 41}, |
|
64 |
{100, 100, 100, 100, 98, 80, 62, 44}, |
|
65 |
{100, 100, 100, 100, 100, 83, 65, 47}, |
|
66 |
{100, 100, 100, 100, 100, 86, 68, 50}, |
|
67 |
{100, 100, 100, 100, 100, 89, 71, 53}, |
|
68 |
{100, 100, 100, 100, 100, 100, 95, 90} |
|
69 |
}; |
|
70 |
|
|
71 |
protected int IMP(int points) { |
|
72 |
int i = 0; |
|
73 |
while (IMPs[i + 1] <= points) { |
|
74 |
i++; |
|
75 |
} |
|
76 |
return i; |
|
77 |
} |
|
78 |
|
|
79 |
protected int percent(int PC, int points, int ba) { |
|
80 |
int points_i = 0; |
|
81 |
int PC_i = 0; |
|
82 |
|
|
83 |
while (this.percent_points[ba][points_i + 1] <= points) { |
|
84 |
points_i++; |
|
85 |
} |
|
86 |
|
|
87 |
while (this.percent_PC[PC_i + 1] <= PC) { |
|
88 |
PC_i++; |
|
89 |
} |
|
90 |
|
|
91 |
return this.percent[points_i][PC_i]; |
|
92 |
} |
|
93 |
|
|
94 |
public BridgeResult compute(int bid, int color, int dbl, int baba, int PC, int tricks) { |
|
95 |
BridgeResult result = new BridgeResult(); |
|
96 |
int we_ba = baba / 2; |
|
97 |
int you_ba = baba % 2; |
|
98 |
|
|
99 |
// 4 pasy |
|
100 |
if (bid == 0) { |
|
101 |
result.pointsFor = BridgeResult.PointsFor.Them; |
|
102 |
result.points = this.PC[we_ba][you_ba][PC]; |
|
103 |
result.IMPs = this.IMP(result.points); |
|
104 |
result.percent = 100 - this.percent(PC, 0, we_ba); |
|
105 |
|
|
106 |
return result; |
|
107 |
} |
|
108 |
|
|
109 |
|
|
110 |
// Wynik w punktach |
|
111 |
int result_points; |
|
112 |
// Punkty za lewy kontraktowe |
|
113 |
int result_tricks; |
|
114 |
// Wynik w punktach, uwzględniając ilość PC |
|
115 |
int result_tricks_w_PC; |
|
116 |
|
|
117 |
// Ilość nadróbek |
|
118 |
int additional_tricks = tricks - 6 - bid; |
|
119 |
|
|
120 |
// Mnożnik przy kontrze |
|
121 |
int multiplier = dbl + 1; |
|
122 |
if (multiplier == 3) { |
|
123 |
multiplier = 4; |
|
124 |
} |
|
125 |
|
|
126 |
// Kontrakt ugrany |
|
127 |
if (additional_tricks >= 0) { |
|
128 |
// "Nadróbki: jak za lewy" |
|
129 |
if (multiplier == 1) { |
|
130 |
result_tricks = this.tricks[color][bid]; |
|
131 |
result_points = this.tricks[color][tricks - 6]; |
|
132 |
} |
|
133 |
// Kontra lub rekontra |
|
134 |
else { |
|
135 |
result_tricks = this.tricks[color][bid] * multiplier; |
|
136 |
result_points = result_tricks; |
|
137 |
|
|
138 |
// Za wygranie z kontrą |
|
139 |
result_points += 25 * multiplier; |
|
140 |
// Za nadróbki |
|
141 |
result_points += additional_tricks * (we_ba == 0 ? 50 : 100) * multiplier; |
|
142 |
} |
|
143 |
|
|
144 |
if (bid == 6) { |
|
145 |
// Za szlemika |
|
146 |
result_points += (we_ba == 0 ? 500 : 750); |
|
147 |
} else if (bid == 7) { |
|
148 |
// Za szlema |
|
149 |
result_points += (we_ba == 0 ? 1000 : 1500); |
|
150 |
} |
|
151 |
|
|
152 |
if (result_tricks >= 100) { |
|
153 |
// Za partię |
|
154 |
result_points += (we_ba == 0 ? 300 : 500); |
|
155 |
} else { |
|
156 |
// Za częściówkę |
|
157 |
result_points += 50; |
|
158 |
} |
|
159 |
} |
|
160 |
// Wpadka |
|
161 |
else { |
|
162 |
// Punkty za wpadkę |
|
163 |
result_points = -1 * this.wpadki[we_ba][dbl][-1 * additional_tricks]; |
|
164 |
} |
|
165 |
|
|
166 |
// Uwzględniamy ilość punktów, którą trzeba było zdobyć |
|
167 |
result_tricks_w_PC = result_points - this.PC[we_ba][you_ba][PC]; |
|
168 |
|
|
169 |
// Zapis dla przeciwników |
|
170 |
if (result_tricks_w_PC < 0) { |
|
171 |
result.pointsFor = BridgeResult.PointsFor.Them; |
|
172 |
result.pointsBefore = -1 * result_points; |
|
173 |
result.points = -1 * result_tricks_w_PC; |
|
174 |
result.IMPs = IMP(result.points); |
|
175 |
if (result_points < 0) { |
|
176 |
result.percent = percent(40 - PC, -1 * result_points, you_ba); |
|
177 |
} else { |
|
178 |
result.percent = 100 - percent(PC, result_points, we_ba); |
|
179 |
} |
|
180 |
} |
|
181 |
// Zapis dla rozgrywających |
|
182 |
else { |
|
183 |
result.pointsFor = BridgeResult.PointsFor.Us; |
|
184 |
result.pointsBefore = result_points; |
|
185 |
result.points = result_tricks_w_PC; |
|
186 |
result.IMPs = IMP(result.points); |
|
187 |
if (result_points > 0) { |
|
188 |
result.percent = percent(PC, result_points, we_ba); |
|
189 |
} else { |
|
190 |
result.percent = 100 - percent(40 - PC, -1 * result_points, you_ba); |
|
191 |
} |
|
192 |
} |
|
193 |
|
|
194 |
return result; |
|
195 |
} |
|
196 |
} |