{"id":26187,"date":"2024-11-24T11:23:54","date_gmt":"2024-11-24T03:23:54","guid":{"rendered":"https:\/\/fwq.ai\/blog\/26187\/"},"modified":"2024-11-24T11:23:54","modified_gmt":"2024-11-24T03:23:54","slug":"%e5%a6%82%e4%bd%95%e9%80%9a%e8%bf%87%e6%8a%bd%e5%8f%96%e5%87%bd%e6%95%b0%e5%92%8c%e4%bc%98%e5%8c%96%e5%be%aa%e7%8e%af%e6%9d%a1%e4%bb%b6%e6%9d%a5%e7%ae%80%e5%8c%96%e5%88%a4%e6%96%ad%e8%bf%9e%e6%88%90-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/26187\/","title":{"rendered":"\u5982\u4f55\u901a\u8fc7\u62bd\u53d6\u51fd\u6570\u548c\u4f18\u5316\u5faa\u73af\u6761\u4ef6\u6765\u7b80\u5316\u5224\u65ad\u8fde\u6210\u4e09\u5b50\u60c5\u51b5\u7684\u4ee3\u7801\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173085595738863.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u901a\u8fc7\u62bd\u53d6\u51fd\u6570\u548c\u4f18\u5316\u5faa\u73af\u6761\u4ef6\u6765\u7b80\u5316\u5224\u65ad\u8fde\u6210\u4e09\u5b50\u60c5\u51b5\u7684\u4ee3\u7801\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u901a\u8fc7\u62bd\u53d6\u51fd\u6570\u548c\u4f18\u5316\u5faa\u73af\u6761\u4ef6\u6765\u7b80\u5316\u5224\u65ad\u8fde\u6210\u4e09\u5b50\u60c5\u51b5\u7684\u4ee3\u7801\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u7b80\u5316\u4ee3\u7801\u793a\u4f8b<\/strong><\/p>\n<p><strong>\u539f\u59cb\u4ee3\u7801\uff1a<\/strong><\/p>\n<pre>\/\/\/ ... \u7701\u7565\u4ee3\u7801\n\n\/\/ \u7528\u4e8e\u5224\u65ad\u662f\u5426\u6709\u8fde\u6210\u4e09\u5b50\u7684\u60c5\u51b5\nfunction determineequare3(maxtime = 3, userplace = 1, box = previousbox) {\n  let times = 0;\n  let prep = -1;\n  let geyi = false;\n  let temparr = [];\n  \/\/ ... \u7701\u7565\u4ee3\u7801\n}\n\n\/\/\/ ... \u7701\u7565\u4ee3\u7801<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>\u7b80\u5316\u540e\u7684\u4ee3\u7801\uff1a<\/strong><\/p>\n<pre>\/\/ \u7528\u4e8e\u5224\u65ad\u662f\u5426\u6709\u8fde\u6210\u4e09\u5b50\u7684\u60c5\u51b5\nfunction determineEquare3(maxTime = 3, userPlace = 1, box = previousBox) {\n  return checkDirections(box, userPlace, maxTime);\n}\n\nfunction checkDirections(box, userPlace, maxTime) {\n  const directions = [\n    [0, 1], [1, 0], [1, 1], [1, -1] \/\/ \u56db\u4e2a\u65b9\u5411\uff1a\u6c34\u5e73\u3001\u5782\u76f4\u3001\u4e24\u4e2a\u5bf9\u89d2\u7ebf\n  ];\n\n  let result;\n  for (const [dx, dy] of directions) {\n    result = checkDirection(box, userPlace, dx, dy, maxTime);\n    if (result) {\n      break;\n    }\n  }\n\n  return result;\n}\n\nfunction checkDirection(box, userPlace, dx, dy, maxTime) {\n  let times = 0;\n  let preP = -1;\n  let geyi = false;\n  let x = box.x;\n  let y = box.y;\n\n  while (x &gt;= 0 &amp;&amp; x &lt; row.value &amp;&amp; y &gt;= 0 &amp;&amp; y &lt; col.value) {\n    const place = boxs.value[x][y].place;\n    if (place === userPlace) {\n      if (preP === -1 || preP === y - dy) {\n        if (preP === y - dy &amp;&amp; geyi) {\n          x--;\n          continue;\n        }\n        times++;\n      } else {\n        times = 1;\n        geyi = false;\n      }\n    } else {\n      if (times === maxTime - 1 &amp;&amp; geyi) {\n        x--;\n        continue;\n      }\n      break;\n    }\n\n    preP = y;\n    x += dx;\n    y += dy;\n  }\n\n  if (times &gt;= maxTime) {\n    return { x, y, times, geyi };\n  }\n\n  return false;\n}<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>\u7b80\u5316\u539f\u7406\uff1a<\/strong><\/p>\n<ul>\n<li>\u5c06\u56db\u4e2a\u65b9\u5411\u7684\u5224\u65ad\u62bd\u53d6\u6210\u72ec\u7acb\u7684\u51fd\u6570 checkdirections\u3002<\/li>\n<li>\u5c06\u5355\u4e2a\u65b9\u5411\u7684\u5224\u65ad\u4e5f\u62bd\u53d6\u6210\u72ec\u7acb\u7684\u51fd\u6570 checkdirection\u3002<\/li>\n<li>\u5728 checkdirection \u4e2d\uff0c\u4f7f\u7528 while \u5faa\u73af\u904d\u5386\u65b9\u5411\uff0c\u800c\u4e0d\u662f\u5728\u539f\u59cb\u4ee3\u7801\u4e2d\u4f7f\u7528\u7684 for \u5faa\u73af\u3002\u8fd9\u53ef\u4ee5\u7b80\u5316\u5faa\u73af\u6761\u4ef6\u5e76\u907f\u514d\u521b\u5efa\u4e0d\u5fc5\u8981\u7684\u53d8\u91cf\u3002<\/li>\n<li>\u5220\u9664\u4e86\u4e0d\u5fc5\u8981\u7684 sort \u64cd\u4f5c\uff0c\u56e0\u4e3a\u5728\u5224\u65ad\u8fde\u6210\u4e09\u5b50\u7684\u60c5\u51b5\u4e0b\u4e0d\u9700\u8981\u8003\u8651\u987a\u5e8f\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u901a\u8fc7\u62bd\u53d6\u51fd\u6570\u548c\u4f18\u5316\u5faa\u73af\u6761\u4ef6\u6765\u7b80\u5316\u5224\u65ad\u8fde\u6210\u4e09\u5b50\u60c5\u51b5\u7684\u4ee3\u7801\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7b80\u5316\u4ee3\u7801\u793a\u4f8b \u539f\u59cb\u4ee3\u7801\uff1a \/\/\/ &#8230; \u7701\u7565\u4ee3\u7801 \/\/ \u7528\u4e8e\u5224\u65ad\u662f\u5426\u6709\u8fde\u6210\u4e09\u5b50\u7684\u60c5\u51b5 function determineequare3(maxtime = 3, userplace = 1, box = previousbox) { let times = 0; let prep = -1; let geyi = false; let temparr = []; \/\/ &#8230; \u7701\u7565\u4ee3\u7801 } \/\/\/ &#8230; \u7701\u7565\u4ee3\u7801 \u767b\u5f55\u540e\u590d\u5236 \u7b80\u5316\u540e\u7684\u4ee3\u7801\uff1a \/\/ \u7528\u4e8e\u5224\u65ad\u662f\u5426\u6709\u8fde\u6210\u4e09\u5b50\u7684\u60c5\u51b5 function determineEquare3(maxTime = 3, userPlace = 1, box = previousBox) [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-26187","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/26187","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=26187"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/26187\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=26187"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=26187"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=26187"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}