-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathghost.cpp
More file actions
315 lines (267 loc) · 7.37 KB
/
ghost.cpp
File metadata and controls
315 lines (267 loc) · 7.37 KB
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
#include "ghost.h"
void test_lr() {
srand(0);
double learning_rate = 0.1;
int n_epochs = 500;
int train_N = 6;
int test_N = 2;
int n_in = 6;
int n_out = 2;
// training data
int train_X[6][6] = {
{1, 1, 1, 0, 0, 0},
{1, 0, 1, 0, 0, 0},
{1, 1, 1, 0, 0, 0},
{0, 0, 1, 1, 1, 0},
{0, 0, 1, 1, 0, 0},
{0, 0, 1, 1, 1, 0}
};
int train_Y[6][2] = {
{1, 0},
{1, 0},
{1, 0},
{0, 1},
{0, 1},
{0, 1}
};
// construct LogisticRegression
LogisticRegression classifier(train_N, n_in, n_out);
// train online
for(int epoch=0; epoch<n_epochs; epoch++) {
for(int i=0; i<train_N; i++) {
classifier.train(train_X[i], train_Y[i], learning_rate);
}
// learning_rate *= 0.95;
}
// test data
int test_X[2][6] = {
{1, 0, 1, 0, 0, 0},
{0, 0, 1, 1, 1, 0}
};
double test_Y[2][2];
// test
for(int i=0; i<test_N; i++) {
classifier.predict(test_X[i], test_Y[i]);
for(int j=0; j<n_out; j++) {
cout << test_Y[i][j] << " ";
}
cout << endl;
}
}
DWORD WINAPI ThreadFun(LPVOID pM)
{
printf("Sub Thread ID is:%d say Hello World\n", GetCurrentThreadId());
return 0;
}
//子线程函数
unsigned int __stdcall ThreadFun1(PVOID pM)
{
printf("Thread ID:%4d say:Hello World\n", GetCurrentThreadId());
return 0;
}
int main(int argc, char* argv[])
{
//#define TEMPLATE_TEST
#ifdef TEMPLATE_TEST
cout << "\a" << endl;
int i,j=3;
long l=2.1;
i = GetMin <int, long> (j,l); //i=GetMin(j,l)
cout << i << endl;
#endif
//#define THREAD_TEST1
#ifdef THREAD_TEST1
printf("Thread demo1\n");
HANDLE handle = CreateThread(NULL, 0, ThreadFun, NULL, 0, NULL);
WaitForSingleObject(handle, INFINITE);
#endif
//#define THREAD_TEST2
#ifdef THREAD_TEST2
printf("Thread demo2\n");
const int THREAD_NUM = 5;
HANDLE handle[THREAD_NUM];
for (int i = 0; i < THREAD_NUM; i++)
handle[i] = (HANDLE)_beginthreadex(NULL, 0, ThreadFun1, NULL, 0, NULL);
WaitForMultipleObjects(THREAD_NUM, handle, TRUE, INFINITE);
#endif
//#define ARGS_TEST
#ifdef ARGS_TEST
cout << argc << endl;
cout << argv[0] << endl;
cout << argv[1] << endl;
#endif
//#define INSTANCE_TEST
#ifdef INSTANCE_TEST
mgr_logic* pLogic = mgr_logic::GetInstance();
pLogic->Init();
cout<<pLogic->logic<<endl;
#endif
//struct game *rh = (struct game *)malloc(sizeof(*rh));
//cout<<sizeof(*rh)<<endl;
//#define DEEP_TEST
#ifdef DEEP_TEST
test_lr();
#endif
//#define STRING_TEST
#ifdef STRING_TEST
string mystr;
cout << "What's your name? ";
getline (cin, mystr);
cout << "Hello " << mystr << ".\n";
#endif
//#define STRUCT_TEST
#ifdef STRUCT_TEST
struct game *g = new game();
struct game g1;
g1.age=1;
g->age=2;
int a=4;
Hello h;
h.print();
cout<<g<<endl;
cout<<&g1<<endl;
cout<<g->age<<endl;
cout<<g1.age<<endl;
cin>>a;
cout<<a<<endl;
#endif
//#define STORE_TEST
#ifdef STORE_TEST
Study s;
s.queue();
s.vect();
s.vects();
s.compare();
s.lists();
s.maps();
s.maps1();
#endif
//#define ADRESS_TEST
#ifdef ADRESS_TEST
int x = 5, y = 10;
Study s;
s.swap1(x,y);
printf("x = %d, y = %d\n", x, y);
s.swap2(&x,&y);
printf("x = %d, y = %d\n", x, y);
int a=1, b=3, c=7;
s.duplicate (a, b, c);
cout << "a=" << a << ", b=" << b << ", c=" << c <<endl;
#endif
//#define ClASS_TEST
#ifdef ClASS_TEST
Learn l;
l.test();
l.test1();
l.test2();
l.test4();
#endif
//#define PROTO_TEST
#ifdef PROTO_TEST
//pluto test begin
Study s;
s.pluto_alltype_test();
//pluto test end
#endif
//#define NORMAL_END
#ifdef NORMAL_END
putchar('\n');
system("pause");
return 0;
#endif
//#define SOCKET_TEST
#ifdef SOCKET_TEST
//初始化WSA
WORD sockVersion = MAKEWORD(2,2);
WSADATA wsaData;
if(WSAStartup(sockVersion, &wsaData)!=0)
{
return 0;
}
//创建套接字
SOCKET slisten = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if(slisten == INVALID_SOCKET)
{
printf("socket error !");
return 0;
}
//绑定IP和端口
sockaddr_in sin;
sin.sin_family = AF_INET;
sin.sin_port = htons(8888);
sin.sin_addr.S_un.S_addr = INADDR_ANY;
if(bind(slisten, (LPSOCKADDR)&sin, sizeof(sin)) == SOCKET_ERROR)
{
printf("bind error !");
}
//开始监听
if(listen(slisten, 5) == SOCKET_ERROR)
{
printf("listen error !");
return 0;
}
//循环接收数据
SOCKET sClient;
sockaddr_in remoteAddr;
int nAddrlen = sizeof(remoteAddr);
char revData[255];
while (true)
{
printf("wait link...\n");
sClient = accept(slisten, (SOCKADDR *)&remoteAddr, &nAddrlen);
if(sClient == INVALID_SOCKET)
{
printf("accept error !");
continue;
}
printf("acceot a link:%s \r\n", inet_ntoa(remoteAddr.sin_addr));
//接收数据
int ret = recv(sClient, revData, 255, 0);
if(ret > 0)
{
revData[ret] = 0x00;
printf(revData);
}
//发送数据
// const char * sendData = "hello TCP Client I am Server\n";
// send(sClient, sendData, strlen(sendData), 0);
CPluto c1;
c1.Encode(120);
c1 << (uint8_t) 120;
c1 << (uint16_t) 120;
c1 << (uint32_t) 120;
c1 << (uint64_t) 120;
c1 << (int8_t) 120;
c1 << (int16_t) 120;
c1 << (int32_t) 120;
c1 << (int64_t) 120;
c1 << "abcddef";
c1 << EndPluto;
//PrintHexPluto(c1);
cout<<c1.GetLen()<<endl;
send(sClient, c1.GetBuff(), c1.GetLen(), 0);
closesocket(sClient);
}
closesocket(slisten);
WSACleanup();
#endif
//#define READER_TEST
#ifdef READER_TEST
char* pszEtcFile = "F:\\ghost\\cfg.ini";
CCfgReader* m_cfg;
m_cfg = new CCfgReader(pszEtcFile);
string strLuaPath = m_cfg->GetValue("init", "lua_path");
cout<<strLuaPath<<endl;
#endif
#define PARSER_TEST
#ifdef PARSER_TEST
const char* pszEtcFile = "F:\\ghost\\cfg.ini";
CCfgReader* m_cfg;
m_cfg = new CCfgReader(pszEtcFile);
CDefParser m_defParser;
m_defParser.init(m_cfg->GetValue("init", "def_path").c_str());
m_defParser.ReadDbCfg(m_cfg);
cout<<m_defParser.GetDbCfg().m_strHost<<endl;
return 0;
#endif
}