1
0

clientAI_guess.cpp 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. #include "clientAI.h"
  2. #include <iostream>
  3. #include <cstdlib>
  4. #include <ctime>
  5. #include <vector>
  6. #include <cstring>
  7. #include <cmath>
  8. using namespace std;
  9. const int p[100][8] = {
  10. {0,0,0,0,0,0,0,100000000},
  11. {32621408,0,0,0,0,0,0,67378592},
  12. {36075952,0,0,0,0,0,0,63924048},
  13. {0,0,100000000,0,0,0,0,0},
  14. {100000000,0,0,0,0,0,0,0},
  15. {0,0,0,0,0,0,0,100000000},
  16. {0,23469942,0,0,0,0,0,76530058},
  17. {0,0,100000000,0,0,0,0,0},
  18. {0,100000000,0,0,0,0,0,0},
  19. {0,100000000,0,0,0,0,0,0},
  20. {0,0,0,0,43097261,0,0,56902739},
  21. {18677920,0,0,0,51829611,0,0,29492469},
  22. {24798435,0,0,0,52657387,0,0,22544178},
  23. {19582821,0,21277531,0,48500882,0,0,10638766},
  24. {0,0,0,100000000,0,0,0,0},
  25. {0,0,0,0,0,50886485,0,49113515},
  26. {1,17039297,0,0,0,56062091,0,26898611},
  27. {0,16095830,26889932,0,0,47515220,0,9499018},
  28. {0,0,0,0,0,100000000,0,0},
  29. {0,100000000,0,0,0,0,0,0},
  30. {0,0,0,0,36075952,0,0,63924048},
  31. {18842918,0,0,0,55842058,0,0,25315024},
  32. {0,21276612,0,0,42679548,0,0,36043840},
  33. {4098490,15364398,12724430,0,50147993,0,0,17664689},
  34. {0,0,0,100000000,0,0,0,0},
  35. {0,0,0,0,0,47194419,0,52805581},
  36. {0,20800958,0,0,0,48592407,0,30606635},
  37. {0,22038862,13020947,0,0,49666492,0,15273699},
  38. {0,0,0,0,0,100000000,0,0},
  39. {0,100000000,0,0,0,0,0,0},
  40. {0,0,0,0,100000000,0,0,0},
  41. {12161110,0,0,0,29157372,24322219,0,34359299},
  42. {24788751,285245,0,0,13278624,31961197,0,29686183},
  43. {0,0,35155285,0,0,35155285,0,29689430},
  44. {0,0,0,100000000,0,0,0,0},
  45. {0,0,0,0,0,100000000,0,0},
  46. {0,31392459,0,0,0,33853472,0,34754069},
  47. {0,0,40657004,0,0,31684599,0,27658397},
  48. {0,0,0,100000000,0,0,0,0},
  49. {0,0,0,100000000,0,0,0,0},
  50. {0,0,0,0,100000000,0,0,0},
  51. {0,0,0,0,100000000,0,0,0},
  52. {0,100000000,0,0,0,0,0,0},
  53. {0,0,0,0,100000000,0,0,0},
  54. {0,0,0,100000000,0,0,0,0},
  55. {0,0,0,0,0,100000000,0,0},
  56. {0,0,0,0,0,100000000,0,0},
  57. {0,100000000,0,0,0,0,0,0},
  58. {0,0,0,100000000,0,0,0,0},
  59. {0,0,0,100000000,0,0,0,0},
  60. {0,0,0,0,0,0,0,100000000},
  61. {35363702,0,0,0,0,0,0,64636298},
  62. {47194419,0,0,0,0,0,0,52805581},
  63. {0,0,0,0,0,0,0,100000000},
  64. {100000000,0,0,0,0,0,0,0},
  65. {0,0,0,0,0,0,0,100000000},
  66. {0,34611315,0,0,0,0,0,65388685},
  67. {0,0,0,0,0,0,0,100000000},
  68. {0,100000000,0,0,0,0,0,0},
  69. {0,100000000,0,0,0,0,0,0},
  70. {0,0,0,0,23469942,0,0,76530058},
  71. {19988056,0,0,0,47744174,0,0,32267770},
  72. {27606617,0,0,0,54730328,0,0,17663055},
  73. {0,0,16066507,0,52541034,0,0,31392459},
  74. {0,0,0,100000000,0,0,0,0},
  75. {0,0,0,0,0,34611315,0,65388685},
  76. {0,22154288,0,0,0,47068342,0,30777370},
  77. {0,24914054,0,0,0,52931658,0,22154288},
  78. {0,0,0,0,0,100000000,0,0},
  79. {0,100000000,0,0,0,0,0,0},
  80. {0,0,0,0,100000000,0,0,0},
  81. {9499019,0,0,0,23469942,30667614,0,36363425},
  82. {19991528,0,0,0,22880562,30815387,0,26312523},
  83. {0,0,30080143,0,0,37081469,0,32838388},
  84. {0,0,0,100000000,0,0,0,0},
  85. {0,0,0,0,0,100000000,0,0},
  86. {0,26465829,0,0,0,43771487,0,29762684},
  87. {1,0,33333333,0,0,33333333,0,33333333},
  88. {0,0,0,100000000,0,0,0,0},
  89. {0,0,0,100000000,0,0,0,0},
  90. {0,0,0,0,100000000,0,0,0},
  91. {0,0,0,0,100000000,0,0,0},
  92. {0,100000000,0,0,0,0,0,0},
  93. {0,0,0,0,100000000,0,0,0},
  94. {0,0,0,100000000,0,0,0,0},
  95. {0,0,0,0,0,100000000,0,0},
  96. {0,0,0,0,0,100000000,0,0},
  97. {0,0,100000000,0,0,0,0,0},
  98. {0,0,0,100000000,0,0,0,0},
  99. {0,0,0,100000000,0,0,0,0},
  100. {0,0,0,0,100000000,0,0,0},
  101. {0,0,0,0,100000000,0,0,0},
  102. {100000000,0,0,0,0,0,0,0},
  103. {100000000,0,0,0,0,0,0,0},
  104. {0,0,0,100000000,0,0,0,0},
  105. {0,0,0,0,0,100000000,0,0},
  106. {0,100000000,0,0,0,0,0,0},
  107. {0,0,0,0,0,100000000,0,0},
  108. {0,0,0,100000000,0,0,0,0},
  109. {0,0,0,100000000,0,0,0,0}
  110. };
  111. const long double f[100] = {
  112. -0.000000000,0.569027392,0.844522531,1.000000000,1.000000000,
  113. 0.380517929,0.854607914,1.000000000,1.000000000,1.000000000,
  114. -0.569027392,-0.000000000,0.360371606,0.756777811,1.000000000,
  115. -0.297502954,0.380517929,0.810019631,1.000000000,1.000000000,
  116. -0.844522531,-0.360371606,-0.000000000,0.498520072,1.000000000,
  117. -0.668460599,0.086846049,0.600169444,1.000000000,1.000000000,
  118. -1.000000000,-0.756777811,-0.498520072,-0.000000000,1.000000000,
  119. -1.000000000,-0.372150829,0.194969206,1.000000000,1.000000000,
  120. -1.000000000,-1.000000000,-1.000000000,-1.000000000,0.000000000,
  121. -1.000000000,-1.000000000,-1.000000000,0.380517929,0.854607914,
  122. -0.380517929,0.297502954,0.668460599,1.000000000,1.000000000,
  123. -0.000000000,0.653886849,1.000000000,1.000000000,1.000000000,
  124. -0.854607914,-0.380517929,-0.086846049,0.372150829,1.000000000,
  125. -0.653886849,-0.000000000,0.470683420,1.000000000,1.000000000,
  126. -1.000000000,-0.810019631,-0.600169444,-0.194969206,1.000000000,
  127. -1.000000000,-0.470683420,-0.000000000,1.000000000,1.000000000,
  128. -1.000000000,-1.000000000,-1.000000000,-1.000000000,-0.380517929,
  129. -1.000000000,-1.000000000,-1.000000000,-0.000000000,0.653886849,
  130. -1.000000000,-1.000000000,-1.000000000,-1.000000000,-0.854607914,
  131. -1.000000000,-1.000000000,-1.000000000,-0.653886849,-0.000000000
  132. };
  133. const int stateNum = 100;
  134. const int actionNum = 8;
  135. const int Len = 100;
  136. const int Dmp[2][actionNum] = {{-1, -2, -3, -4, 0, -1, -2, 1},
  137. {-5, -1, -2, -3, -5, 0, -5, 1}};
  138. int e[stateNum][actionNum][actionNum];
  139. int cntRand, randNum[100000];
  140. int last, Set, LimitSet, LimitCase;
  141. vector<int> q[stateNum][actionNum];
  142. int calc(int mymp, int mylv, int opmp, int oplv, ACTION myact, ACTION opact)
  143. {
  144. bool myerr = mymp + Dmp[mylv][myact] < 0;
  145. bool operr = opmp + Dmp[oplv][opact] < 0;
  146. if (myerr && operr) return -3;
  147. if (myerr) return -4;
  148. if (operr) return -5;
  149. if (myact < 4 && opact < 4) {
  150. if (myact > opact) return -1;
  151. if (myact < opact) return -2;
  152. }else {
  153. if (myact < 2 && opact >= 6) return -1;
  154. if (myact == ATTACK_3 && opact != DEFEND_2) return -1;
  155. if (myact == ATTACK_4) return -1;
  156. if (opact < 2 && myact >= 6) return -2;
  157. if (opact == ATTACK_3 && myact != DEFEND_2) return -2;
  158. if (opact == ATTACK_4) return -2;
  159. }
  160. mymp += Dmp[mylv][myact];
  161. if (myact == RAMPAGE) ++mylv;
  162. opmp += Dmp[oplv][opact];
  163. if (opact == RAMPAGE) ++oplv;
  164. if (mymp > 4) mymp = 4;
  165. if (opmp > 4) opmp = 4;
  166. return mymp + mylv * 5 + opmp * 10 + oplv * 50;
  167. }
  168. void init(int totalSet) {
  169. srand(time(0) % 10000);
  170. cntRand = 0;
  171. for (int i = 0; i < 100000; i ++)
  172. randNum[i] = (rand() + rand() + rand() + rand()) % 10000;
  173. Set = 0;
  174. LimitSet = actionNum;
  175. for (int i = 0; i < stateNum; ++i)
  176. for (int j = 0; j < actionNum; ++j)
  177. for (int k = 0; k < actionNum; ++k)
  178. e[i][j][k] = calc(i % 5, i % 10 / 5, i / 10 % 5, i / 50, (enum ACTION)j, (enum ACTION)k);
  179. }
  180. void beginSet(int cntSet) {
  181. if (cntSet % 20 == 0)
  182. for (int i = 0; i < stateNum; ++i)
  183. for (int j = 0; j < actionNum; ++j)
  184. q[i][j].clear();
  185. }
  186. void endSet(int result) {
  187. }
  188. ACTION getAction(int cntRound, int myMP, int myState, int opMP, int opState, ACTION opAction)
  189. {
  190. if (cntRound != 1)
  191. q[last][opAction].push_back(Set);
  192. else
  193. ++Set;
  194. if (myMP > 4) myMP = 4;
  195. if (opMP > 4) opMP = 4;
  196. int S = last = myMP + myState * 5 + opMP * 10 + opState * 50;
  197. int P = randNum[cntRand++] * 10000 + randNum[cntRand++] + 1;
  198. int T = 0, t[actionNum];
  199. memset(t, 0, sizeof(t));
  200. for (int i = 0; i < 8; ++i)
  201. if (opMP + Dmp[opState][i] >= 0)
  202. for (int j = 0; j < q[S][i].size(); ++j)
  203. if (q[S][i][j] >= Set - LimitSet) {
  204. ++T;
  205. t[i] += q[S][i][j] - (Set - LimitSet) + 1;
  206. }
  207. if (T > LimitSet && randNum[cntRand++] % 2 == 0) {
  208. long double c[actionNum][actionNum], v[actionNum];
  209. memset(v, 0, sizeof(v));
  210. for (int j = 0; j < actionNum; ++j)
  211. for (int k = 0; k < actionNum; ++k) {
  212. if (e[S][j][k] >= 0) c[j][k] = f[e[S][j][k]];
  213. else
  214. if (e[S][j][k] == -1) c[j][k] = 1;
  215. else
  216. if (e[S][j][k] == -2) c[j][k] = -1;
  217. else
  218. if (e[S][j][k] == -3) c[j][k] = -100;
  219. else
  220. if (e[S][j][k] == -4) c[j][k] = -100;
  221. else
  222. if (e[S][j][k] == -5) c[j][k] = 100;
  223. if (c[j][k] != 100)
  224. v[j] += c[j][k] * t[k];
  225. }
  226. long double s = 0;
  227. for (int i = 0; i < actionNum; ++i)
  228. if (v[i] > 0) s += v[i] * v[i];
  229. for (int i = 0; i < actionNum; ++i)
  230. if (v[i] > 0) {
  231. P -= int(1e8 * v[i] * v[i] / s + 0.5);
  232. if (P <= 0)
  233. if (myMP + Dmp[myState][i] >= 0) return (enum ACTION)(i);
  234. else break;
  235. }
  236. }
  237. P = randNum[cntRand++] * 10000 + randNum[cntRand++] + 1;
  238. for (int i = 0; i < 8; ++i) {
  239. P -= p[S][i];
  240. if (P <= 0) return (enum ACTION)(i);
  241. }
  242. return RESTORE;
  243. }
  244. /*
  245. int main()
  246. {
  247. init(100);
  248. q[1][ATTACK_1] = 100;
  249. q[1][DEFEND_1] = 50;
  250. q[1][RESTORE] = 20;
  251. cout << getAction(2, 1, 0, 0, 0, RESTORE);
  252. system("pause");
  253. return 0;
  254. }
  255. */