battleAiLogic.lua 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  1. local skynet = require "skynet"
  2. local battleConst = require "battle.battleConst"
  3. local battleLog = require "battle.battleLog"
  4. local battleUtils = require "battle.battleUtils"
  5. local battleAdapt = require "adapt.battleAdapt"
  6. local battleDefine = require "battle.battleDefine"
  7. local battleAiUtils = require "battleAiUtils"
  8. local utils_bt_supply = require "utils_bt_supply"
  9. local root = {}
  10. local Total_Weight = {2, 8, 11, 9, 7, 3}
  11. local Grid_Color_Weights = {
  12. {num = 7, colors = {{p1 = 4, p2 = 3}, {p1 = 3, p2 = 4}}},
  13. {num = 8, colors = {{p1 = 4, p2 = 4}}},
  14. {num = 9, colors = {{p1 = 5, p2 = 4}, {p1 = 4, p2 = 5}}},
  15. {num = 10, colors = {{p1 = 5, p2 = 5}}},
  16. {num = 11, colors = {{p1 = 5, p2 = 6}, {p1 = 6, p2 = 5}, {p1 = 7, p2 = 4}, {p1 = 4, p2 = 7}}},
  17. {num = 12, colors = {{p1 = 6, p2 = 6}, {p1 = 7, p2 = 5}, {p1 = 5, p2 = 7}}},
  18. {num = 13, colors = {{p1 = 7, p2 = 6}, {p1 = 6, p2 = 7}, {p1 = 8, p2 = 5}, {p1 = 5, p2 = 8}}},
  19. {num = 14, colors = {{p1 = 7, p2 = 7}, {p1 = 8, p2 = 6}, {p1 = 6, p2 = 8}}},
  20. {num = 15, colors = {{p1 = 8, p2 = 7}, {p1 = 7, p2 = 8}, {p1 = 9, p2 = 6}, {p1 = 6, p2 = 9}}},
  21. {num = 16, colors = {{p1 = 8, p2 = 8}, {p1 = 9, p2 = 7}, {p1 = 7, p2 = 9}}},
  22. {num = 17, colors = {{p1 = 9, p2 = 8}}},
  23. {num = 18, colors = {{p1 = 9, p2 = 9}}},
  24. {num = 19, colors = {{p1 = 10, p2 = 9}}},
  25. {num = 20, colors = {{p1 = 10, p2 = 10}}}
  26. }
  27. -----------------------------------------------
  28. ------------------色块生成逻辑------------------
  29. --[[ 生成50个色块
  30. ]]
  31. function root:initGrid(core)
  32. self:printToConsole("-->initGrid...")
  33. local needColorData1, needColorData2 = self:getGridTotalColorNum(core)
  34. local grids1 = self:createGridColor(core, 0, needColorData1) or {}
  35. local grids2 = self:createGridColor(core, 1, needColorData2) or {}
  36. self:printToConsole(string.format("结果1:%s", table.concat(grids1, ", ")))
  37. self:printToConsole(string.format("结果2:%s", table.concat(grids2, ", ")))
  38. return self:tableConcat(grids1, grids2)
  39. -- {3, 2, 3, 2, 4, 1, 4, 3, 2, 4, 2, 1, 4, 1, 1, 2, 3, 2, 3, 2, 3, 3, 2, 3, 3, 3, 2, 3, 2, 4, 1, 4, 3, 2, 4, 2, 1, 4, 1, 1, 2, 3, 2, 3, 2, 3, 3, 2, 3, 3}
  40. end
  41. -- 获取双方 四种颜色总数
  42. function root:getGridTotalColorNum(core)
  43. local totalWeight = Total_Weight
  44. local totalStartIndex = 9
  45. local gridColorWeights = Grid_Color_Weights
  46. local totalRedIndex = self:randomWeightToIndex(totalWeight)
  47. local totalRed = totalStartIndex + totalRedIndex
  48. local totalGreenIndex = self:randomWeightToIndex(totalWeight)
  49. local totalGreen = totalStartIndex + totalGreenIndex
  50. local totalBlueIndex = self:randomWeightToIndex(totalWeight)
  51. local totalBlue = totalStartIndex + totalBlueIndex
  52. local total = core.areaW * core.areaH * 2
  53. local totalYellow = total - totalRed - totalGreen - totalBlue
  54. -- self:printToConsole( string.format("totalRed=%d, totalGreen=%d, totalBlue=%d, totalYellow=%d", totalRed, totalGreen, totalBlue, totalYellow) )
  55. local needColorData1 = {red = 0, green = 0, blue = 0, yellow = 0}
  56. local needColorData2 = {red = 0, green = 0, blue = 0, yellow = 0}
  57. local colorNum = self:getGridColorNumByColor(gridColorWeights, totalRed)
  58. needColorData1.red = colorNum.p1
  59. needColorData2.red = colorNum.p2
  60. colorNum = self:getGridColorNumByColor(gridColorWeights, totalGreen)
  61. needColorData1.green = colorNum.p1
  62. needColorData2.green = colorNum.p2
  63. colorNum = self:getGridColorNumByColor(gridColorWeights, totalBlue)
  64. needColorData1.blue = colorNum.p1
  65. needColorData2.blue = colorNum.p2
  66. colorNum = self:getGridColorNumByColor(gridColorWeights, totalYellow)
  67. needColorData1.yellow = colorNum.p1
  68. needColorData2.yellow = colorNum.p2
  69. -- self:printToConsole( string.format("needColorData1=%d,%d,%d,%d", needColorData1.red, needColorData1.yellow, needColorData1.green, needColorData1.blue) );
  70. -- self:printToConsole( string.format("needColorData2=%d,%d,%d,%d", needColorData2.red, needColorData2.yellow, needColorData2.green, needColorData2.blue) );
  71. return needColorData1, needColorData2
  72. end
  73. function root:getGridColorNumByColor(gridColorWeights, totalNum)
  74. for i, v in ipairs(gridColorWeights) do
  75. if v.num == totalNum then
  76. local randomIndex = math.random(1, #v.colors)
  77. local colorObj = v.colors[randomIndex]
  78. return colorObj
  79. end
  80. end
  81. return {p1 = 0, p2 = 0}
  82. end
  83. -- 创建格子颜色(1红,2黄,3绿,4蓝)
  84. function root:createGridColor(core, castleIndex, needColorData)
  85. local gridColorList = {}
  86. local printGridCount = {0, 0, 0, 0}
  87. local colorWeights = {10, 10, 10, 10}
  88. local isCanLink = false
  89. local total = core.areaW * core.areaH
  90. for i = 1, total do
  91. colorWeights[1] = needColorData.red > 0 and 10 or 0
  92. colorWeights[2] = needColorData.yellow > 0 and 10 or 0
  93. colorWeights[3] = needColorData.green > 0 and 10 or 0
  94. colorWeights[4] = needColorData.blue > 0 and 10 or 0
  95. local tempColorWeights
  96. if not isCanLink and i >= total - 2 then
  97. colorWeights = {10, 0, 0, 0}
  98. if i == total then
  99. self:printToConsole("-------- 强制生成三块红色 --------")
  100. end
  101. else
  102. tempColorWeights = self:checkNearGridColor(gridColorList, colorWeights)
  103. end
  104. if colorWeights[1] == 0 and colorWeights[2] == 0 and colorWeights[3] == 0 and colorWeights[4] == 0 then
  105. -- self:printToConsole("重新初始化权重")
  106. colorWeights = {10, 10, 10, 10}
  107. if
  108. tempColorWeights[1].w == 0 and tempColorWeights[2].w == 0 and tempColorWeights[3].w == 0 and
  109. tempColorWeights[4].w == 0
  110. then
  111. -- self:printToConsole('### 相邻色块都超过5 ###')
  112. else
  113. for j = 1, 4 do
  114. if tempColorWeights[j].w == 0 then
  115. colorWeights[j] = 0
  116. end
  117. end
  118. end
  119. end
  120. local colorType = self:randomWeightToIndex(colorWeights)
  121. table.insert(gridColorList, colorType)
  122. printGridCount[colorType] = printGridCount[colorType] + 1
  123. if colorType == 1 then
  124. needColorData.red = needColorData.red - 1
  125. elseif colorType == 2 then
  126. needColorData.yellow = needColorData.yellow - 1
  127. elseif colorType == 3 then
  128. needColorData.green = needColorData.green - 1
  129. elseif colorType == 4 then
  130. needColorData.blue = needColorData.blue - 1
  131. end
  132. if tempColorWeights and tempColorWeights[colorType].n >= 3 then
  133. isCanLink = true
  134. end
  135. end
  136. -- self:printToConsole( string.format("玩家%d:红-%d, 黄-%d,绿-%d, 蓝-%d", castleIndex, printGridCount[1], printGridCount[2], printGridCount[3], printGridCount[4]) )
  137. return gridColorList
  138. end
  139. -- 找出相邻4种色块长度
  140. function root:checkNearGridColor(gridColorList, colorWeights)
  141. local tempColorWeights = {{w = 10, n = 0}, {w = 10, n = 0}, {w = 10, n = 0}, {w = 10, n = 0}}
  142. if #gridColorList < 4 then
  143. return tempColorWeights
  144. end
  145. for i = 1, 4 do
  146. local nearGridColorCount = self:getNearGridColorCount(gridColorList, i)
  147. if nearGridColorCount > 5 then
  148. colorWeights[i] = 0
  149. tempColorWeights[i].w = 0
  150. -- self:printToConsole( string.format(" %d 相邻色块超过5,把权重调0", #gridColorList) )
  151. end
  152. tempColorWeights[i].n = nearGridColorCount
  153. end
  154. return tempColorWeights
  155. end
  156. -- 找出某种色块相邻长度
  157. function root:getNearGridColorCount(gridColorList, color, index)
  158. local gridIndex = index ~= nil and index or #gridColorList
  159. local list = {gridIndex}
  160. local index = 1
  161. while index <= #list do
  162. local checkIndex = list[index]
  163. index = index + 1
  164. local gridX = checkIndex % 5
  165. local gridY = math.floor(checkIndex / 5)
  166. for i = -1, 1 do
  167. for j = -1, 1 do
  168. if (i ~= 0 or j ~= 0) and (gridX + i) >= 0 and (gridY + j) >= 0 and (gridX + i < 5) and (gridY + j < 5) then
  169. local tempIndex = self:getGridIndexByXY(gridX + i, gridY + j)
  170. local tempColor = gridColorList[tempIndex + 1]
  171. if
  172. tempColor and self:checkIsSameColor(tempColor, color) and
  173. self:findGridIndex(list, tempIndex) <= 0
  174. then
  175. table.insert(list, tempIndex)
  176. if color == battleConst.COLOR_TYPE.ALL then
  177. color = tempColor
  178. end
  179. end
  180. end
  181. end
  182. end
  183. end
  184. -- self:printToConsole( string.format("[%d] color=%d, data=%s, list=%s", gridIndex, color, table.concat(gridColorList, "," ), table.concat(list, "," )) )
  185. return #list
  186. end
  187. -- 判断色块是否相同,5是万能色块
  188. function root:checkIsSameColor(tempColor, color)
  189. return tempColor == battleConst.COLOR_TYPE.ALL or color == battleConst.COLOR_TYPE.ALL or tempColor == color
  190. end
  191. function root:findGridIndex(list, tempIndex)
  192. for i, v in ipairs(list) do
  193. if tempIndex == v then
  194. return i
  195. end
  196. end
  197. return 0
  198. end
  199. function root:getGridIndexByXY(gridX, gridY)
  200. return gridY * 5 + gridX
  201. end
  202. local function log2Client(core, logStr)
  203. if not logStr then
  204. return
  205. end
  206. battleLog:logClient(logStr)
  207. core:notifyClientLog(logStr)
  208. end
  209. -----------------------------------------------
  210. ------------------色块补充逻辑------------------
  211. function root:supplyGrids(core, actionCastle)
  212. local grids = core.map
  213. local curRound = core:getCurRound()
  214. -- 将需要补充的色块,重置颜色为0
  215. for _, block in ipairs(grids) do
  216. if block.status == battleConst.BLOCK_STATUS.NEEDUPDATE then
  217. block.color = battleConst.COLOR_TYPE.INVAILD
  218. block:clear()
  219. end
  220. end
  221. local enemyCastle = core:getEnemyCastle(actionCastle)
  222. local supplyRound = enemyCastle.supplyRound
  223. local supplyWeight1 = enemyCastle.supplyWeight1
  224. local supplyWeight2 = enemyCastle.supplyWeight2
  225. local supplyWeight = curRound <= supplyRound and supplyWeight1 or supplyWeight2
  226. local supplyType = getRandomWithWeight(supplyWeight)
  227. supplyType = "A57"
  228. local seat = actionCastle.seat
  229. local is2v2 = core.is2v2
  230. utils_bt_supply:supply_grids(core, seat, grids, supplyType, is2v2)
  231. end
  232. -- 根据权重随机下标
  233. function root:randomWeightToIndex(list)
  234. if list == nil or #list == 0 then
  235. return 1
  236. end
  237. local sum = 0
  238. for i, weight in ipairs(list) do
  239. sum = sum + weight
  240. end
  241. if sum <= 0 then
  242. return 1
  243. end
  244. local ret = 1
  245. local r = math.random(1, sum)
  246. local didSum = 0
  247. for index, q in ipairs(list) do
  248. didSum = didSum + q
  249. if r <= didSum then
  250. ret = index
  251. break
  252. end
  253. end
  254. return ret
  255. end
  256. -- 获取可连线选择的龙
  257. local function getOptionLinks(core, actionCastle)
  258. local allLinks = battleUtils:getAllLinkBlocks2(core, core.map, actionCastle.seat)
  259. table.sort(
  260. allLinks,
  261. function(a, b)
  262. return #a.linkIds > #b.linkIds
  263. end
  264. )
  265. for i = #allLinks, 1, -1 do
  266. for j = 1, i - 1 do
  267. local member = true
  268. for _, v in ipairs(allLinks[i].linkIds) do
  269. if not table.member(allLinks[j].linkIds, v) then
  270. member = false
  271. break
  272. end
  273. end
  274. if member then
  275. table.remove(allLinks, i)
  276. break
  277. end
  278. end
  279. end
  280. return allLinks
  281. end
  282. local link = class("link")
  283. function link:ctor()
  284. self.ids = {}
  285. self.size = 0
  286. self.lastY = 0
  287. end
  288. local function createLink(core, actionCastle, linkIds, isFool)
  289. local l = link.new()
  290. l.ids = battleUtils:reverse(core.map, actionCastle.seat, linkIds, isFool)
  291. l.size = #linkIds
  292. local lastBlock = battleUtils:getColorBlockByID(core.map, l.ids[l.size])
  293. l.lastY = lastBlock.y
  294. return l
  295. end
  296. local function findGridSuppressRoute(core, actionCastle)
  297. local nowTime = skynet.time()
  298. local allLinks = getOptionLinks(core, actionCastle)
  299. if table.empty(allLinks) then
  300. battleLog:logInfo(string.format("findGridSuppressRoute empty links error, uid %s", actionCastle.uid))
  301. return
  302. end
  303. local result = {}
  304. local exceptLinks = {}
  305. local enableExSkill = core:getEnableExSkill(actionCastle)
  306. for _, v in ipairs(allLinks) do
  307. local ret, exSkillGridId, except =
  308. battleAiUtils:getLongEvaluate(core, actionCastle, v.linkIds, v.color, false, enableExSkill)
  309. if ret >= 1000000 then
  310. battleLog:logInfo(string.format("findGridSuppressRoute time cost %s", skynet.time() - nowTime))
  311. return v.linkIds, exSkillGridId
  312. end
  313. if except then
  314. table.link(
  315. exceptLinks,
  316. battleUtils:getLinkBlocksWithoutExceptBlocks(
  317. core,
  318. core.map,
  319. actionCastle.seat,
  320. except.blocks,
  321. except.exceptBlocks
  322. )
  323. )
  324. end
  325. table.insert(result, {ids = v.linkIds, size = #v.linkIds, allPower = ret, exSkillGridId = exSkillGridId})
  326. local linkIds = table.reverse(v.linkIds)
  327. ret, exSkillGridId = battleAiUtils:getLongEvaluate(core, actionCastle, linkIds, v.color, true, enableExSkill)
  328. if ret >= 1000000 then
  329. battleLog:logInfo(string.format("findGridSuppressRoute time cost %s", skynet.time() - nowTime))
  330. return linkIds, exSkillGridId
  331. end
  332. table.insert(result, {ids = linkIds, size = #linkIds, allPower = ret, exSkillGridId = exSkillGridId})
  333. end
  334. for _, v in ipairs(exceptLinks) do
  335. local ret, exSkillGridId =
  336. battleAiUtils:getLongEvaluate(core, actionCastle, v.linkIds, v.color, true, enableExSkill)
  337. if ret >= 1000000 then
  338. battleLog:logInfo(string.format("findGridSuppressRoute time cost %s", skynet.time() - nowTime))
  339. return v.linkIds, exSkillGridId
  340. end
  341. table.insert(result, {ids = v.linkIds, size = #v.linkIds, allPower = ret, exSkillGridId = exSkillGridId})
  342. local linkIds = table.reverse(v.linkIds)
  343. ret, exSkillGridId = battleAiUtils:getLongEvaluate(core, actionCastle, linkIds, v.color, true, enableExSkill)
  344. if ret >= 1000000 then
  345. battleLog:logInfo(string.format("findGridSuppressRoute time cost %s", skynet.time() - nowTime))
  346. return linkIds, exSkillGridId
  347. end
  348. table.insert(result, {ids = linkIds, size = #linkIds, allPower = ret, exSkillGridId = exSkillGridId})
  349. end
  350. table.sort(
  351. result,
  352. function(a, b)
  353. if a.allPower ~= b.allPower then
  354. return a.allPower > b.allPower
  355. end
  356. return a.size > b.size
  357. end
  358. )
  359. battleLog:logInfo(string.format("findGridSuppressRoute time cost %s", skynet.time() - nowTime))
  360. return result[1].ids, result[1].exSkillGridId
  361. end
  362. local function findGridCommonRoute(core, actionCastle)
  363. local nowTime = skynet.time()
  364. local allLinks = getOptionLinks(core, actionCastle)
  365. if table.empty(allLinks) then
  366. battleLog:logInfo(string.format("findGridCommonRoute empty links error, uid %s", actionCastle.uid))
  367. return
  368. end
  369. local result = {}
  370. for _, v in ipairs(allLinks) do
  371. table.insert(result, createLink(core, actionCastle, v.linkIds, false))
  372. end
  373. table.sort(
  374. result,
  375. function(a, b)
  376. if a.size ~= b.size then
  377. return a.size > b.size
  378. end
  379. if actionCastle.seat == battleConst.BATTLE_SEAT.DOWN then
  380. return a.lastY < b.lastY
  381. else
  382. return a.lastY > b.lastY
  383. end
  384. end
  385. )
  386. local ids = result[1].ids
  387. local exSkillGridId
  388. local enableExSkill = core:getEnableExSkill(actionCastle)
  389. if enableExSkill then
  390. exSkillGridId = battleAiUtils:getNormatlExSkillGridId(core, actionCastle, ids)
  391. end
  392. battleLog:logInfo(string.format("findGridCommonRoute time cost %s", skynet.time() - nowTime))
  393. return ids, exSkillGridId
  394. end
  395. -- 笨笨的连线AI
  396. local function findGridFoolRoute(core, actionCastle)
  397. local nowTime = skynet.time()
  398. -- 获取全部连线
  399. local allLinks = getOptionLinks(core, actionCastle)
  400. if table.empty(allLinks) then
  401. battleLog:logInfo(string.format("findGridFoolRoute empty links error, uid %s", actionCastle.uid))
  402. return
  403. end
  404. -- 愚蠢取落点低的规则:对手(真人)游戏局数小于5局,或者30%概率
  405. local enemyCastle = core:getEnemyCastle(actionCastle)
  406. local mainPlayer = enemyCastle:getMainPlayer()
  407. local isFool = false
  408. if mainPlayer.battleCount < 5 then
  409. isFool = true
  410. else
  411. isFool = math.random(100) <= 30
  412. end
  413. -- 全部连线结构化
  414. local result = {}
  415. for _, v in ipairs(allLinks) do
  416. table.insert(result, createLink(core, actionCastle, v.linkIds, isFool))
  417. end
  418. -- 连线排序:优先长度,其次落点
  419. table.sort(
  420. result,
  421. function(a, b)
  422. if a.size ~= b.size then
  423. return a.size > b.size
  424. end
  425. if isFool then
  426. if actionCastle.seat == battleConst.BATTLE_SEAT.UP then
  427. return a.lastY < b.lastY
  428. else
  429. return a.lastY > b.lastY
  430. end
  431. else
  432. if actionCastle.seat == battleConst.BATTLE_SEAT.UP then
  433. return a.lastY > b.lastY
  434. else
  435. return a.lastY < b.lastY
  436. end
  437. end
  438. end
  439. )
  440. -- 获取长度最长的连线
  441. local linkIds = result[1].ids
  442. -- 10%的概率漏连。漏连数量在 BattleCommonConfig 配置
  443. if math.random(100) <= 10 then
  444. local lessWeights = battleAdapt:getLessLinkWeights()
  445. local lessCount = RandomWithWeight(lessWeights)
  446. for i = 1, lessCount do
  447. if #linkIds == battleDefine.MIN_LINK_BLOCK then
  448. break
  449. end
  450. table.remove(linkIds, 1)
  451. end
  452. end
  453. local ids = linkIds
  454. local exSkillGridId
  455. local enableExSkill = core:getEnableExSkill(actionCastle)
  456. if enableExSkill then
  457. exSkillGridId = battleAiUtils:getNormatlExSkillGridId(core, actionCastle, ids)
  458. end
  459. battleLog:logInfo(string.format("findGridFoolRoute time cost %s", skynet.time() - nowTime))
  460. return ids, exSkillGridId
  461. end
  462. local function findGridStupidRoute(core, actionCastle)
  463. local nowTime = skynet.time()
  464. -- 获取全部连线
  465. local allLinks = getOptionLinks(core, actionCastle)
  466. if table.empty(allLinks) then
  467. battleLog:logInfo(string.format("findGridStupidRoute empty links error, uid %s", actionCastle.uid))
  468. return
  469. end
  470. local isFool = true
  471. -- 全部连线结构化
  472. local result = {}
  473. for _, v in ipairs(allLinks) do
  474. table.insert(result, createLink(core, actionCastle, v.linkIds, isFool))
  475. end
  476. local ids
  477. local exSkillGridId = nil
  478. -- 随机一条连线
  479. local linkIds = result[math.random(#result)].ids
  480. if #linkIds > 3 then
  481. ids = {}
  482. for i = 1, 3 do
  483. table.insert(ids, linkIds[i])
  484. end
  485. else
  486. ids = linkIds
  487. end
  488. battleLog:logInfo(string.format("findGridStupidRoute time cost %s", skynet.time() - nowTime))
  489. return ids, exSkillGridId
  490. end
  491. -----------------------------------------------
  492. ------------------色块寻路逻辑------------------
  493. --[[寻找最长的路线
  494. ]]
  495. function root:findGridLongRoute(core, actionCastle, aiLinkType)
  496. if not aiLinkType then
  497. log.error("findGridLongRoute aiLinkType is nil")
  498. return
  499. end
  500. -- if aiLinkType == "W" and math.random(100) <= 20 then
  501. -- aiLinkType = "R"
  502. -- elseif aiLinkType == "R" and math.random(100) <= 20 then
  503. -- aiLinkType = "W"
  504. -- end
  505. -- aiLinkType = "R"
  506. log2Client(core, string.format("当前回合%s aiLinkType=%s", core:getCurRound(), aiLinkType))
  507. if aiLinkType == "W" then
  508. return findGridSuppressRoute(core, actionCastle)
  509. elseif aiLinkType == "R" then
  510. return findGridCommonRoute(core, actionCastle)
  511. elseif aiLinkType == "L" then
  512. return findGridFoolRoute(core, actionCastle)
  513. elseif aiLinkType == "S" then
  514. return findGridStupidRoute(core, actionCastle)
  515. end
  516. battleLog:logInfo(string.format("findGridLongRoute error aiLinkType = %s", aiLinkType))
  517. end
  518. -- 数组拷贝
  519. function root:tableConcat(dest, src)
  520. local begin = #dest + 1
  521. local len = #src
  522. for i = 0, len - 1 do
  523. dest[i + begin] = src[i + 1]
  524. end
  525. return dest
  526. end
  527. -------------------------
  528. function root:printToConsole(str)
  529. battleLog:logInfo(str)
  530. end
  531. return root