-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.mm
122 lines (95 loc) · 3.33 KB
/
main.mm
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
//
// main.m
// TestNSString
//
// Created by zhangjirui on 2/3/16.
// All rights reserved.
//
#import <Foundation/Foundation.h>
#include <iostream>
#include <time.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
// // add for test
// long array[7] = {0, 0, 0, 0, 0, 0};
//
// time_t seed = time(NULL);
// srandom(seed);
//
// for (int i = 0; i < 1000000; i ++) {
// int temp = 1 + random() % 6;
// array[temp] = array[temp] + 1;
// }
// long instantIncome = 0;
// long ruleMaxBetMoney = 500000;
//
// long baseMoney = 200;
//
// long betMoney = 0;
// long maxBetMoney = 0;
// BOOL newRound = true;
//
// long nWin = 0;
// long nLoose = 0;
long finalIncome = 0;
for (int j = 0; j < 365; j ++) {
NSLog(@"");
NSLog(@"Day%d", j+1);
long instantIncome = 0;
long ruleMaxBetMoney = 500000;
long baseMoney = 500;
long betMoney = 0;
long maxBetMoney = 0;
BOOL newRound = true;
long nWin = 0;
long nLoose = 0;
time_t seed = time(NULL);
srandom(seed);
for (int i = 0; i < 1000; i++) {
// bet
if (newRound) {
betMoney = baseMoney;
} else {
betMoney = betMoney * 2;
}
if (betMoney > ruleMaxBetMoney) {
betMoney = baseMoney;
}
if (betMoney > maxBetMoney) {
maxBetMoney = betMoney;
}
instantIncome = instantIncome - betMoney;
int f1 = 1 + random() % 6;
int f2 = 1 + random() % 6;
int f3 = 1 + random() % 6;
BOOL bWin = true;
if ((f1 == f2) && (f2 == f3)) {
bWin = false;
newRound = false;
nLoose = nLoose + 1;
} else {
// bet big
if ((f1 + f2 + f3) >= 11) {
instantIncome = instantIncome + betMoney * 2;
bWin = true;
newRound = true;
nWin = nWin + 1;
} else {
bWin = false;
newRound = false;
nLoose = nLoose + 1;
}
}
// NSLog(@"%d %d %d -> %d \tbetM:%ld \tinstantM:%ld", f1, f2, f3, bWin, betMoney, instantIncome);
}
NSLog(@"finalIncome -> %ld", instantIncome);
NSLog(@"maxBetMoney -> %ld", maxBetMoney);
NSLog(@"nWin:%ld, nLose:%ld", nWin, nLoose);
finalIncome = finalIncome + instantIncome;
sleep(1);
}
NSLog(@" ");
NSLog(@"FinalIncome %ld", finalIncome);
}
return 0;
}