-
Notifications
You must be signed in to change notification settings - Fork 1
/
PlayerModel.m
327 lines (271 loc) · 12.1 KB
/
PlayerModel.m
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
#import "ChipModel.h"
#import "CardModel.h"
#import "PlayerModel.h"
@implementation PlayerModel
+(PlayerModel*)playerModel
{
return [[[PlayerModel alloc] init] autorelease];
}
@synthesize status = _status;
@synthesize cards = _cards;
@synthesize orderedCards = _orderedCards;
@synthesize chips = _chips;
@dynamic chipTotal;
@dynamic betTotal;
@dynamic numberOfCardsMarked;
@dynamic cardKeys;
@dynamic heldKeys;
@dynamic heldCards;
-(int)chipTotal
{
return [[self.chips objectForKey:@"1"] chipCount] * 1
+ [[self.chips objectForKey:@"5"] chipCount] * 5
+ [[self.chips objectForKey:@"10"] chipCount] * 10
+ [[self.chips objectForKey:@"50"] chipCount] * 50
+ [[self.chips objectForKey:@"100"] chipCount] * 100
+ [[self.chips objectForKey:@"500"] chipCount] * 500
+ [[self.chips objectForKey:@"1000"] chipCount] * 1000
+ [[self.chips objectForKey:@"5000"] chipCount] * 5000
+ [[self.chips objectForKey:@"10000"] chipCount] * 10000;
}
-(void)setChipTotal:(int)total
{
[[self.chips objectForKey:@"1"] setBetCount:0];
[[self.chips objectForKey:@"5"] setBetCount:0];
[[self.chips objectForKey:@"10"] setBetCount:0];
[[self.chips objectForKey:@"50"] setBetCount:0];
[[self.chips objectForKey:@"100"] setBetCount:0];
[[self.chips objectForKey:@"500"] setBetCount:0];
[[self.chips objectForKey:@"1000"] setBetCount:0];
[[self.chips objectForKey:@"5000"] setBetCount:0];
[[self.chips objectForKey:@"10000"] setBetCount:0];
float chipTotal = total;
int chipCount10000;
int chipCount5000;
int chipCount1000;
int chipCount500;
int chipCount100;
int chipCount50;
int chipCount10;
int chipCount5;
int chipCount1;
if(chipTotal <= 2000)
{
//1 5 10 50 100
chipCount10000 = 0;
chipCount5000 = 0;
chipCount1000 = 0;
chipCount500 = 0;
chipCount100 = fminf(rint(chipTotal / 166), floor(chipTotal / 100)); chipTotal -= chipCount100 * 100;
chipCount50 = fminf(rint(chipTotal / 66), floor(chipTotal / 50)); chipTotal -= chipCount50 * 50;
chipCount10 = fminf(rint(chipTotal / 16), floor(chipTotal / 10)); chipTotal -= chipCount10 * 10;
chipCount5 = fminf(rint(chipTotal / 6), floor(chipTotal / 5)); chipTotal -= chipCount5 * 5;
chipCount1 = fminf(rint(chipTotal / 1), floor(chipTotal / 1));
}
else if(chipTotal <= 10000)
{
//5 10 50 100 500
chipCount10000 = 0;
chipCount5000 = 0;
chipCount1000 = 0;
chipCount500 = fminf(rint(chipTotal / 665), floor(chipTotal / 500)); chipTotal -= chipCount500 * 500;
chipCount100 = fminf(rint(chipTotal / 165), floor(chipTotal / 100)); chipTotal -= chipCount100 * 100;
chipCount50 = fminf(rint(chipTotal / 65), floor(chipTotal / 50)); chipTotal -= chipCount50 * 50;
chipCount10 = fminf(rint(chipTotal / 15), floor(chipTotal / 10)); chipTotal -= chipCount10 * 10;
chipCount5 = fminf(rint(chipTotal / 5), floor(chipTotal / 5));
chipCount1 = 0;
}
else if(chipTotal <= 20000)
{
//10 50 100 500 1000
chipCount10000 = 0;
chipCount5000 = 0;
chipCount1000 = fminf(rint(chipTotal / 1660), floor(chipTotal / 1000)); chipTotal -= chipCount1000 * 1000;
chipCount500 = fminf(rint(chipTotal / 660), floor(chipTotal / 500)); chipTotal -= chipCount500 * 500;
chipCount100 = fminf(rint(chipTotal / 160), floor(chipTotal / 100)); chipTotal -= chipCount100 * 100;
chipCount50 = fminf(rint(chipTotal / 60), floor(chipTotal / 50)); chipTotal -= chipCount50 * 50;
chipCount10 = fminf(rint(chipTotal / 10), floor(chipTotal / 10));
chipCount5 = 0;
chipCount1 = 0;
}
else if(chipTotal <= 100000)
{
//50 100 500 1000 5000
chipCount10000 = 0;
chipCount5000 = fminf(rint(chipTotal / 6650), floor(chipTotal / 5000)); chipTotal -= chipCount5000 * 5000;
chipCount1000 = fminf(rint(chipTotal / 1650), floor(chipTotal / 1000)); chipTotal -= chipCount1000 * 1000;
chipCount500 = fminf(rint(chipTotal / 650), floor(chipTotal / 500)); chipTotal -= chipCount500 * 500;
chipCount100 = fminf(rint(chipTotal / 150), floor(chipTotal / 100)); chipTotal -= chipCount100 * 100;
chipCount50 = fminf(rint(chipTotal / 50), floor(chipTotal / 50));
chipCount10 = 0;
chipCount5 = 0;
chipCount1 = 0;
}
else
{
//100 500 1000 5000 10000
chipCount10000 = fminf(rint(chipTotal / 16600), floor(chipTotal / 10000)); chipTotal -= chipCount10000 * 10000;
chipCount5000 = fminf(rint(chipTotal / 6600), floor(chipTotal / 5000)); chipTotal -= chipCount5000 * 5000;
chipCount1000 = fminf(rint(chipTotal / 1600), floor(chipTotal / 1000)); chipTotal -= chipCount1000 * 1000;
chipCount500 = fminf(rint(chipTotal / 600), floor(chipTotal / 500)); chipTotal -= chipCount500 * 500;
chipCount100 = fminf(rint(chipTotal / 100), floor(chipTotal / 100));
chipCount50 = 0;
chipCount10 = 0;
chipCount5 = 0;
chipCount1 = 0;
}
[[self.chips objectForKey:@"1"] setChipCount:chipCount1];
[[self.chips objectForKey:@"5"] setChipCount:chipCount5];
[[self.chips objectForKey:@"10"] setChipCount:chipCount10];
[[self.chips objectForKey:@"50"] setChipCount:chipCount50];
[[self.chips objectForKey:@"100"] setChipCount:chipCount100];
[[self.chips objectForKey:@"500"] setChipCount:chipCount500];
[[self.chips objectForKey:@"1000"] setChipCount:chipCount1000];
[[self.chips objectForKey:@"5000"] setChipCount:chipCount5000];
[[self.chips objectForKey:@"10000"] setChipCount:chipCount10000];
}
-(int)betTotal
{
return [[self.chips objectForKey:@"1"] betCount] * 1
+ [[self.chips objectForKey:@"5"] betCount] * 5
+ [[self.chips objectForKey:@"10"] betCount] * 10
+ [[self.chips objectForKey:@"50"] betCount] * 50
+ [[self.chips objectForKey:@"100"] betCount] * 100
+ [[self.chips objectForKey:@"500"] betCount] * 500
+ [[self.chips objectForKey:@"1000"] betCount] * 1000
+ [[self.chips objectForKey:@"5000"] betCount] * 5000
+ [[self.chips objectForKey:@"10000"] betCount] * 10000;
}
-(void)cancelBets
{
[[self.chips objectForKey:@"1"] setBetCount:0];
[[self.chips objectForKey:@"5"] setBetCount:0];
[[self.chips objectForKey:@"10"] setBetCount:0];
[[self.chips objectForKey:@"50"] setBetCount:0];
[[self.chips objectForKey:@"100"] setBetCount:0];
[[self.chips objectForKey:@"500"] setBetCount:0];
[[self.chips objectForKey:@"1000"] setBetCount:0];
[[self.chips objectForKey:@"5000"] setBetCount:0];
[[self.chips objectForKey:@"10000"] setBetCount:0];
}
-(void)allIn
{
[[self.chips objectForKey:@"1"] setBetCount:[[self.chips objectForKey:@"1"] chipCount]];
[[self.chips objectForKey:@"5"] setBetCount:[[self.chips objectForKey:@"5"] chipCount]];
[[self.chips objectForKey:@"10"] setBetCount:[[self.chips objectForKey:@"10"] chipCount]];
[[self.chips objectForKey:@"50"] setBetCount:[[self.chips objectForKey:@"50"] chipCount]];
[[self.chips objectForKey:@"100"] setBetCount:[[self.chips objectForKey:@"100"] chipCount]];
[[self.chips objectForKey:@"500"] setBetCount:[[self.chips objectForKey:@"500"] chipCount]];
[[self.chips objectForKey:@"1000"] setBetCount:[[self.chips objectForKey:@"1000"] chipCount]];
[[self.chips objectForKey:@"5000"] setBetCount:[[self.chips objectForKey:@"5000"] chipCount]];
[[self.chips objectForKey:@"10000"] setBetCount:[[self.chips objectForKey:@"10000"] chipCount]];
}
-(int)numberOfCardsMarked
{
int marked = 0;
for(CardModel* card in self.cards)
{
if(!card.isHeld) { marked++; }
}
return marked;
}
-(NSArray*)cardKeys
{
NSMutableArray* keys = [NSMutableArray array];
for(CardModel* card in self.cards)
{
[keys addObject:card.key];
}
return keys;
}
-(NSArray*)heldKeys
{
NSMutableArray* keys = [NSMutableArray array];
for(CardModel* card in self.cards)
{
if(card.isHeld) { [keys addObject:card.key]; }
}
return keys;
}
-(NSArray*)heldCards
{
NSMutableArray* cards = [NSMutableArray array];
for(CardModel* card in self.cards)
{
if(card.isHeld) { [cards addObject:card]; }
}
return cards;
}
-(NSArray*)drawnKeys
{
NSMutableArray* keys = [NSMutableArray array];
for(CardModel* card in self.cards)
{
if(!card.isHeld) { [keys addObject:card.key]; }
}
return keys;
}
-(NSArray*)drawnCards
{
NSMutableArray* cards = [NSMutableArray array];
for(CardModel* card in self.cards)
{
if(!card.isHeld) { [cards addObject:card]; }
}
return cards;
}
-(id)init
{
self = [super init];
if(self)
{
self.cards = [NSMutableArray array];
self.chips = [NSMutableDictionary dictionary];
{ ChipModel* chipModel = [ChipModel chipModel]; chipModel.key = @"1"; [self.chips setObject:chipModel forKey:@"1"]; }
{ ChipModel* chipModel = [ChipModel chipModel]; chipModel.key = @"5"; [self.chips setObject:chipModel forKey:@"5"]; }
{ ChipModel* chipModel = [ChipModel chipModel]; chipModel.key = @"10"; [self.chips setObject:chipModel forKey:@"10"]; }
{ ChipModel* chipModel = [ChipModel chipModel]; chipModel.key = @"50"; [self.chips setObject:chipModel forKey:@"50"]; }
{ ChipModel* chipModel = [ChipModel chipModel]; chipModel.key = @"100"; [self.chips setObject:chipModel forKey:@"100"]; }
{ ChipModel* chipModel = [ChipModel chipModel]; chipModel.key = @"500"; [self.chips setObject:chipModel forKey:@"500"]; }
{ ChipModel* chipModel = [ChipModel chipModel]; chipModel.key = @"1000"; [self.chips setObject:chipModel forKey:@"1000"]; }
{ ChipModel* chipModel = [ChipModel chipModel]; chipModel.key = @"5000"; [self.chips setObject:chipModel forKey:@"5000"]; }
{ ChipModel* chipModel = [ChipModel chipModel]; chipModel.key = @"10000"; [self.chips setObject:chipModel forKey:@"10000"]; }
}
return self;
}
-(NSDictionary*)saveToDictionary
{
NSMutableDictionary* dictionary = [NSMutableDictionary dictionary];
[dictionary setObject:[NSNumber numberWithInt:(int)self.status] forKey:@"status"];
[dictionary setObject:self.cards forKey:@"cards"];
[dictionary setObject:self.orderedCards forKey:@"orderedCards"];
[dictionary setObject:self.chips forKey:@"chips"];
return dictionary;
}
-(void)loadFromDictionary:(NSDictionary*)dictionary
{
NSNumber* status = [dictionary objectForKey:@"status"];
NSMutableArray* cards = [dictionary objectForKey:@"cards"];
NSMutableArray* orderedCards = [dictionary objectForKey:@"orderedCards"];
NSMutableDictionary* chips = [dictionary objectForKey:@"chips"];
self.status = [status intValue];
for(NSDictionary* card in cards)
{
CardModel* cardModel = [CardModel cardModel];
[cardModel loadFromDictionary:card];
[self.cards addObject:cardModel];
}
for(NSDictionary* card in orderedCards)
{
CardModel* cardModel = [CardModel cardModel];
[cardModel loadFromDictionary:card];
[self.orderedCards addObject:cardModel];
}
for(NSString* key in chips)
{
ChipModel* chipModel = [ChipModel chipModel];
[chipModel loadFromDictionary:[chips objectForKey:key]];
[self.chips setObject:chipModel forKey:key];
}
}
@end