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 package com.buckosoft.fibs.document;
33
34 import java.util.LinkedList;
35
36 import com.buckosoft.fibs.domain.Board;
37 import com.buckosoft.fibs.domain.SavedMatch;
38
39
40
41
42
43
44
45
46 public class Document {
47
48
49
50
51 private String name = "?";
52 private boolean allowPip;
53 private boolean autoBoard;
54 private boolean autoDouble;
55 private boolean autoMove;
56 private boolean away;
57 private boolean bell;
58 private boolean crawford;
59 private boolean askDouble;
60 private int experience;
61 private boolean greedy;
62 private boolean moreBoards;
63 private boolean moves;
64 private boolean notify;
65 private double rating;
66 private boolean ratings;
67 private boolean ready;
68 private int redoubles;
69 private boolean report;
70 private boolean silent;
71 private String timezone;
72
73 private Board board = new Board();
74 private LinkedList<SavedMatch> savedMatches = new LinkedList<SavedMatch>();
75
76 private LinkedList<SavedMatch> missManners = new LinkedList<SavedMatch>();
77
78
79
80
81
82 public Board getBoard() {
83 return board;
84 }
85
86
87
88
89 public void setBoard(Board board) {
90 this.board = board;
91 }
92
93
94
95 public void resetGame() {
96 this.greedy = false;
97 this.askDouble = true;
98
99
100 this.board.setYourTurnToRollOrDouble(false);
101 }
102
103
104
105
106 public void setYouDouble(boolean doubleFlag) {
107 this.board.setYourTurnToRollOrDouble(false);
108
109 }
110
111
112
113
114 public String getName() {
115 return name;
116 }
117
118
119
120
121 public boolean isAllowPip() {
122 return allowPip;
123 }
124
125
126
127
128 public boolean isAutoBoard() {
129 return autoBoard;
130 }
131
132
133
134
135 public void setAutoBoard(boolean autoBoard) {
136 this.autoBoard = autoBoard;
137 }
138
139
140
141
142 public boolean isAutoDouble() {
143 return autoDouble;
144 }
145
146
147
148
149 public boolean isAutoMove() {
150 return autoMove;
151 }
152
153
154
155
156 public boolean isAway() {
157 return away;
158 }
159
160
161
162
163 public boolean isBell() {
164 return bell;
165 }
166
167
168
169
170 public boolean isCrawford() {
171 return crawford;
172 }
173
174
175
176
177 public boolean isAskDouble() {
178 return this.askDouble;
179 }
180
181 public void setAskDouble(boolean askDoubles) {
182 this.askDouble = askDoubles;
183 }
184
185
186
187
188 public int getExperience() {
189 return experience;
190 }
191
192
193
194
195 public boolean isGreedy() {
196 return greedy;
197 }
198
199 public void setGreedy(boolean greedy) {
200 this.greedy = greedy;
201 }
202
203
204
205
206 public boolean isMoreBoards() {
207 return moreBoards;
208 }
209
210
211
212
213 public boolean isMoves() {
214 return moves;
215 }
216
217
218
219
220 public boolean isNotify() {
221 return notify;
222 }
223
224
225
226
227 public double getRating() {
228 return rating;
229 }
230
231
232
233
234 public boolean isRatings() {
235 return ratings;
236 }
237
238
239
240
241 public boolean isReady() {
242 return ready;
243 }
244
245
246
247
248 public void setReady(boolean ready) {
249 this.ready = ready;
250 }
251
252
253
254
255 public int getRedoubles() {
256 return redoubles;
257 }
258
259
260
261
262 public boolean isReport() {
263 return report;
264 }
265
266
267
268
269
270 public boolean isSilent() {
271 return silent;
272 }
273
274
275
276
277 public String getTimezone() {
278 return timezone;
279 }
280
281
282
283
284
285
286 public String getSavedMatchString(String playerName) {
287 for (SavedMatch sm : savedMatches) {
288 if (sm.getOpponentName().equals(playerName)) {
289 StringBuffer sb = new StringBuffer();
290 sb.append("Saved Match. Length: ");
291 sb.append(sm.getMatchLength());
292 sb.append(" Score: (you) ");
293 sb.append(sm.getYourScore());
294 sb.append(" - (");
295 sb.append(sm.getOpponentName());
296 sb.append(") ");
297 sb.append(sm.getOpponentScore());
298 return(sb.toString());
299 }
300 }
301 return(null);
302 }
303
304
305
306
307
308
309 public SavedMatch parseSavedMatch(String s) {
310 try {
311 String[] ss = s.split(" +");
312 SavedMatch sm = new SavedMatch();
313 if (ss[0].startsWith("**")) {
314 sm.setOpponentName(ss[0].substring(2));
315 sm.setMatchLength(Integer.parseInt(ss[1]));
316 sm.setYourScore(Integer.parseInt(ss[2]));
317 sm.setOpponentScore(Integer.parseInt(ss[4]));
318 } else if (ss[1].startsWith("*")){
319 sm.setOpponentName(ss[1].substring(1));
320 sm.setMatchLength(Integer.parseInt(ss[2]));
321 sm.setYourScore(Integer.parseInt(ss[3]));
322 sm.setOpponentScore(Integer.parseInt(ss[5]));
323 } else {
324 sm.setOpponentName(ss[1]);
325 sm.setMatchLength(Integer.parseInt(ss[2]));
326 sm.setYourScore(Integer.parseInt(ss[3]));
327 sm.setOpponentScore(Integer.parseInt(ss[5]));
328 }
329 this.savedMatches.add(sm);
330 return(sm);
331 } catch (Exception ex) {
332 throw new RuntimeException("Failed to parseSavedMatch '" + s + "'", ex);
333 }
334 }
335
336
337
338
339
340
341 public void removeSavedMatch(String playerName) {
342 for (SavedMatch sm : savedMatches) {
343 if (sm.getOpponentName().equals(playerName)) {
344 savedMatches.remove(sm);
345 break;
346 }
347 }
348 }
349
350
351
352
353
354 public String getMissMannersString(String playerName) {
355 for (SavedMatch sm : missManners) {
356 if (sm.getOpponentName().equals(playerName)) {
357 StringBuffer sb = new StringBuffer();
358 sb.append("MissManners warns: ");
359 sb.append(playerName);
360 sb.append(" has ");
361 sb.append(sm.getMatchLength());
362 sb.append(" saved games");
363 return(sb.toString());
364 }
365 }
366 return(null);
367 }
368
369
370
371
372
373
374 public SavedMatch parseMissManners(String s) {
375 try {
376 String[] ss = s.split(" +");
377 if (!ss[1].equals("MissManners"))
378 return(null);
379 SavedMatch sm = new SavedMatch();
380 sm.setOpponentName(ss[4]);
381 sm.setMatchLength(Integer.parseInt(ss[6]));
382 this.missManners.add(sm);
383 return(sm);
384 } catch (Exception ex) {
385 throw new RuntimeException("Failed to parseMissManners '" + s + "'", ex);
386 }
387 }
388
389
390
391
392
393
394
395
396
397
398 public void parseOwnInfo(String s) {
399 String[] t = s.split(" ");
400 this.name = t[1];
401 this.allowPip = Integer.parseInt(t[2]) == 1 ? true : false;
402 this.autoBoard = Integer.parseInt(t[3]) == 1 ? true : false;
403 this.autoDouble = Integer.parseInt(t[4]) == 1 ? true : false;
404 this.autoMove = Integer.parseInt(t[5]) == 1 ? true : false;
405 this.away = Integer.parseInt(t[6]) == 1 ? true : false;
406 this.bell = Integer.parseInt(t[7]) == 1 ? true : false;
407 this.crawford = Integer.parseInt(t[8]) == 1 ? true : false;
408 this.askDouble = Integer.parseInt(t[9]) == 1 ? true : false;
409 this.experience = Integer.parseInt(t[10]);
410 this.greedy = Integer.parseInt(t[11]) == 1 ? true : false;
411 this.moreBoards = Integer.parseInt(t[12]) == 1 ? true : false;
412 this.moves = Integer.parseInt(t[13]) == 1 ? true : false;
413 this.notify = Integer.parseInt(t[14]) == 1 ? true : false;
414 this.rating = Double.parseDouble(t[15]);
415 this.ratings = Integer.parseInt(t[16]) == 1 ? true : false;
416 this.ready = Integer.parseInt(t[17]) == 1 ? true : false;
417 this.redoubles = t[18].equals("unlimited") ? -1 : Integer.parseInt(t[19]);
418 this.report = Integer.parseInt(t[19]) == 1 ? true : false;
419 this.silent = Integer.parseInt(t[20]) == 1 ? true : false;
420 this.timezone = t[21];
421 }
422
423 }