åã£ããšã¯ä¿¡ããããŸããã
ãããŠããã«ãç§ã決å®çã«åã£ããšã¯ä¿¡ããããŸããã
ç§ã¯ããã°ã©ãã³ã°ç«¶æã倧奜ãã§ãç§ã«ãšã£ãŠãããŸã§ã§æ倧ãã€æãåºæ¿çãªãã®ã§ããã æ°ã¶æéã®ã³ã³ãã¹ãã®äž»å¬è ãã¢ã·ã¹ã¿ã³ããtcpãµãŒããŒãã¹ããããã³ãã¹ãŠã®ãã¬ã€ã€ãŒã«æè¬ããŸãã
ããã¯ç§ã®ã²ãŒã ã®äŸã§ãïŒ aichallenge.org/visualizer.php?game=346288&user=4513 ïŒ ããã¯èè ã圌ã®èšäºã§åŒçšããã²ãŒã ã§ã¯ãããŸãããèè ã®ãµãŒããŒã«çŽæ¥ä¿åãããŠããããããªã³ã¯ãä»ããããšã¯ã§ããŸããã -çŽTranslã ïŒ ã ãã®èšäºã§ã¯ãç§ã®ã³ãŒããäœãããã®ãããããŠãããã©ã®ããã«æåããã®ãã説æããããšæããŸãã å€ãã®æè¡çãªãã€ã³ãããããäžè¬ã«ãã®èšäºã¯æŠç¥ãã®ãã®ã«é¢ãããã®ã§ã¯ãããŸããããããç°¡åã«èª¬æããããšããŸãã
ã³ãŒãã«ã€ããŠ
Javaã¹ã¿ãŒã¿ãŒããã¯ãããŠã³ããŒããããã¡ã€ã«ã®ååãå€æŽããäžèŠãªãã®ããã¹ãŠåé€ããæ°ããStrategy
ã¯ã©ã¹ãè¿œå ããããšããå§ããããã«ã¢ãªãè¡šãã¯ã©ã¹ãå¿ èŠã«ãªãããšã«æ°ä»ããŸããã ç§ã¯ãã¹ãŠã®ã³ãŒãã
Strategy
ã¯ã©ã¹ã§äœæããŸããããã®çµæãçŽ1800è¡ã®ã³ãŒããäœæãããŸããã ãŸããèå³æ·±ãã®ã¯
Ant.java
ãš
Tile.java
ãã©ã¡ãã
Tile.java
ã®ãã£ãŒã«ããæã€å€ãªããžã§ã¯ãã§ãã
ç§ã¯ã¹ã¿ãŒã¿ãŒããã¯ããã¢ã€ãã¢ãæ®ããŸããããã®ããã¯ã§ã¯ãäžæãªé åãããã©ã«ãã§å°é¢ãšèŠãªãããŠããŸããã ãããã®èŠéãèšç®ããªãã£ããããã©ã®çŽ°èãå®éã«å°çã§ãããä»ãŸã§èŠãããšã®ãªã现èã§ãããããç¥ããŸããã§ããã
ãããã®åã»ã«ã«ã¯ãã²ãŒã å šäœã§äœ¿çšãããã¿ã€ã«ã®ã€ã³ã¹ã¿ã³ã¹ã1ã€ã ããããŸãã ã¢ãªã¯ããã¹ãŠã®ç§ã®ã¢ãªãšæµã®ã¢ãªã®åã¿ãŒã³ã®éå§æã«äœæãããŸãã
èªåã§ãœãŒã¹ã³ãŒããèŠããå Žåã¯ãç¥ã£ãŠããå¿ èŠããããŸããgovnokodaã§ãã£ã±ãã§ãããç§ã¯ç¹ã«èªãã«æã£ãŠããŸããã ãã ããããããäœããã®åœ¢ã§èŠããã®ã§ã ããããããŠã³ããŒãã§ããŸãã
æŠç¥ã®å®æœ
å€ãã®äººãããã€ãã®äžè¬çãªæŠç¥ã«ã€ããŠè©±ããŸããããæ®å¿µãªãããç§ã¯ãããæã£ãŠããŸããã ç§ã¯ãã¢ãªã®æ°ãå é å°ã®å²åã«åºã¥ããŠæ±ºå®ãäžããŸããã ãããã¯åã¡è² ããŠãæŠè¡ãå€ããŸããã 圌ã¯ããã«ã€ããŠå šãç¥ããŸããã ããã«ãç§ã¯ä»ã®åããèŠãŠããªãããæåã¯ãã¹ãŠã999çªç®ãšãŸã£ããåãããã«èµ·ããã ç§ã¯ãæŠéäžã§ãã£ãŠãæµãåºå¥ãããè»å¡ã®æ§è³ªãä¿åããŸããã ããã·ã§ã³ã®å©ããåããŠè»å¡ããã¢ãªãéãããšã«å ããŠãååãã¯ã¢ãªã®ããŒã«ã«ç°å¢ã®ã¿ã«äŸåããŸããã§ã¯ãæ¯ã¿ãŒã³æ£ç¢ºã«äœãèµ·ããã®ã§ããããïŒ ãã¹ãŠã®åæåãšäºåèšç®ã®åŸã次ã®ã¡ãœããããã®é åºã§åŒã³åºããŸãã
- initMissionsïŒïŒ;
- enemyHillsïŒïŒ;
- é£åïŒïŒ;
- initExploreïŒïŒ;
- createAreasïŒïŒ;
- æŠãïŒïŒ;
- é²è¡ïŒïŒ;
- approachEnemiesïŒïŒ;
- attackDetachedEnemiesïŒïŒ;
- escapeEnemiesïŒïŒ;
- é åžïŒtrueïŒ;
- æ¢çŽ¢ïŒïŒ;
- doMissionsïŒïŒ;
- createMissionsïŒïŒ;
- é åžïŒfalseïŒ;
- cleanAreasïŒïŒ;
ã¯ã€ãæ€çŽ¢
ããã§ã¯ãäžè¬ã«BFSãååŸããæ¹æ³ã«ã€ããŠèª¬æããŸãã ããã©ãŒãã³ã¹äžã®çç±ãããåã¿ã€ã«ã«ã¯é£æ¥ããã»ã«ïŒæ°Žãé€ãïŒãããããã2次å é åã«ã¢ã¯ã»ã¹ããŠãrowsããã³colsããããã£ã䜿çšããå¿ èŠã¯ãããŸããã ïŒ ããã«ãããããã©ãŒãã³ã¹ãå€§å¹ ã«åäžããããšã¯çããã-ãããTranslã ïŒå žåçãªBFSïŒããã³ãããã®å€ãã䜿çšïŒã¯ã次ã®ããã«ãªããŸãã LinkedList<Tile> openList = new LinkedList<Tile>(); LinkedList<Tile> changedTiles = new LinkedList<Tile>(); openList.add(foodTile); foodTile.dist = 0; foodTile.isReached = true; changedTiles.add(foodTile); while (!openList.isEmpty()) { Tile tile = openList.removeFirst(); if (tile.dist >= 10) break; for (Tile n : tile.neighbors) { if (n.isReached) continue; if (n.type == Type.MY_ANT) { // found one of my ants at the tile n } n.isReached = true; n.dist = tile.dist + 1; changedTiles.add(n); openList.add(n); } } for (Tile tile : changedTiles) tile.isReached = false;
ãã®äŸã§ã¯ãfoodTileããå§ããŠã10ã¹ãããã§å°éå¯èœãªã¢ãªãæ¢ããŸãã HashMapã䜿çšããŠæ¢ã«ã¢ã¯ã»ã¹ããã»ã«ãä¿åããæ¹ãå¹ççã§ããå Žåã¯ãæåŸã«ã«ãŒããåãé€ãããšãã§ããŸãã
ã³ãŒã¹ã®åæå
å移åã®éå§æã«ãè¿ãã«ãããå人ãã®æ°ãè¿ãã®æµã®ãªã¹ããšããããŸã§ã®è·é¢ãªã©ãã¢ãªã®ããããçš®é¡ã®æ¯çãã«ãŠã³ãããŸãã ããã§ã®è·é¢ã¯ãŠãŒã¯ãªãããšãã³ããã¿ã³ã®äž¡æ¹ã§ãããBFSã®ã¹ãããæ°ã«ãã£ãŠèæ ®ããããããããã¯å°ããããã«ããã§ããæµãŸã§ã®è·é¢ã«å¿ããŠãã¢ãªã«ã¯ïŒéæ¥çãªå¯èœæ§ãããïŒå±éºããããã©ããã瀺ããã©ã°ããããŸãã æµã®å Žåãå€ç«ããŠãããã©ããïŒã€ãŸããè¿ãã«ä»ã®æµã¢ãªããããã©ããïŒã確èªããŸããã
åæåäžã«å®è¡ãããå¥ã®ã¿ã¹ã¯ã¯ãæ°åã®ç§»åã§ç§»åããŠããªãæµã¢ãªãèå¥ããããšã§ãã ãã®ãããªåãã®æ°ã5ã«éããå Žåãããã«æ¬¡ã®åãã«ç«ã€ãšæ³å®ãããŸããã
ç 究ãšããã·ã§ã³
è»ãè»å¡ããé ãããæ°ããé åãæ¢çŽ¢ããå®è£ ã§å¯èŠé åãæ倧åããããšã¯ãäºãã«éåžžã«å¯æ¥ã«é¢é£ããŠããããããããããç§ã®ãããã®åäœã§æãéèŠãªéšåã§ãããªãµãŒã
ExploreValueã¯ããããäžã®åã»ã«ã«ä¿åãããŸãããã®ã»ã«ã¯ãå°ãªããšã1ã€ã®ã¢ãªãš10ã¿ãŒã³ã§BFSã§å°éã§ããªãå Žåã1ã¿ãŒã³ããšã«å¢å ããŸãã ã»ã«ã«å°éã§ããå Žåãã«ãŠã³ã¿ãŒã¯ãŒãã«ãªã»ãããããŸãã ãããã£ãŠãexploreValueã¯ãã»ã«ã§äœãèµ·ãã£ãŠããã®ãããããªãã£ãæéã®å°ºåºŠã§ãããããã£ãŠãæ¢çŽ¢æ¹æ³ã§ã¯ãå¥ã®ã¿ã¹ã¯ã«äœ¿çšãããªãã£ããã¹ãŠã®ã¢ãªãããæ倧深ã11ã¹ãããã§BFSãèµ·åãããŸãããæåŸã®ã¹ãããã®ã¿ã«é¢å¿ããããŸãïŒæåã®10åã®exploreValueã¯0ã§ããããšãä¿èšŒãããŠããããïŒã ã¹ããã11ã§å°éå¯èœãªãã¹ãŠã®ã»ã«ã®exploreValueããŒãã®å Žåãããã¯ã¢ãªããèªåèªèº«ããŸãã¯æ°Žã«å²ãŸããŠããããšãæå³ããŸãã ãã以å€ã®å Žåãã¹ããã11ã®exploreValueåèšãæ倧ã«ãªãæ¹åã«ã¢ãªã移åããŸãïŒã€ãŸãã10ã¹ãããã§å ¥åããã»ã«ããå°éå¯èœãªãã¹ãŠã®ã»ã«ã®exploreValueåèšïŒã 2ã€ã®ç°ãªãæåã®ã¹ããããå®è¡ããããšã§11ã¹ãããã§ä»»æã®ã»ã«ã«å°éã§ãããããBFSã§ã¯1ã€ãŸãã¯2ã€ã®æåã®åãã®ãªã¹ããä¿åãããŸãã
ãã®ããã«ããŠãå°å³ãæ¢çŽ¢ãããã¹ãŠã®ãµã€ãã衚瀺ããŸãã
ããã·ã§ã³
ã§ã¯ãã¢ãªãèªåã®ã¢ãªã«å²ãŸããŠãããšãããã©ãã§ããããïŒ ãã¡ãããå¢çç·ã«ç§»åããŸãïŒ å¢çç·ã®ããæ£ç¢ºãªå®çŸ©ã¯createAreasã¡ãœããã«ãããããã«ã€ããŠã¯åŸã§è©³ãã説æããŸãã åœå¢ã«ç§»åããããšãããã·ã§ã³ãšåŒã³ãŸãã ããã·ã§ã³ã¯ãã¢ãªãšåœå¢ã®æšç现èã®2ã€ã ãã§æ§æãããŠããŸãã ããã·ã§ã³ã¯ã移åã®éã«ä¿åãããããã€ãã®ããŒã¿ã®äŸã§ãããç®æšãžã®ãã¹ã¯æ¯åA *ã§ã«ãŠã³ããããŸãã ã¢ãªããã§ã«ããã·ã§ã³ãæã£ãŠããå Žåãããã¯ãããå®çŸãç¶ããŸããããã§ãªããã°ãæ°ãããã®ãäœæãããŸãã ã¢ãªã«ããã·ã§ã³ããã£ããããããä»ã®ç®çïŒé£ç©åéãæŠéãé²è¡ïŒã«äœ¿çšãããå Žåãããã·ã§ã³ã¯ãã£ã³ã»ã«ãããŸããåå°ãšåœå¢
createAreasã¡ãœããã¯ãããããã»ã¯ã·ã§ã³ã«åå²ããŸãã ä»åã¯å¥ã®BFSãå®è¡ããŸãããä»åã¯ãã¹ãŠã®ã¢ãªïŒæµãå«ãïŒããåæã«å®è¡ããŸãã éå§æã«ãåã¢ãªã«ã¯ç¬èªã®ããããããããã©ãŠã³ãããªããäžã«å°éãããã¹ãŠã®ã»ã«ãããã«çµåããŸãã ãããã1人ã®ãã¬ãŒã€ãŒã«å±ããã»ã¯ã·ã§ã³ãè¡çªãããšããããã¯1ã€ã®å€§ããªã»ã¯ã·ã§ã³ã«ããŒãžããããã®åŸãäœåºŠãããŒãžã§ããŸãã BFSã®åŸãèªåã®ãšãªã¢å ã®ãã¹ãŠã®ã»ã«ã調ã¹ãå°ãªããšã1ã€ã®é£æ¥ã»ã«ãå¥ã®ãšãªã¢ã«å±ããŠããåã»ã«ãå¢çã»ã«ãšèŠãªããŸãã ãã®BFSã§ã¯ãç§ã¯20ã®åããããæ·±ãã¯è¡ããªãããã39æ©ã®è·é¢ã«ãã2ã€ã®ã¢ãªã¯ããããã®éã«é§ãããã£ãŠããŠãåããšãªã¢ã«ããŸãã ããã«ãããæããã«èªåã«å±ããŠããé åã«çªç¶ã®å¢çç·ããªãããšãä¿èšŒãããŸãã å¢çã»ã«ã¯ãã¢ãªãšæµããçè·é¢ã«ããããã¢ãªãã20æ©é¢ããã»ã«ã§ãããæµãèŠããªãããšãããããŸãã 2çªç®ã®ã±ãŒã¹ã§ã¯ãå¢çã»ã«ãä»ãŸã§èŠãããšã®ãªãæ°Žã®äžã«ããããšãå€æããå Žåããããæ°Žãæ€åºãããšããã«ããã·ã§ã³ãåé€ããŸããããã·ã§ã³ãäœæãããšããå¢çã»ã«ã®1ã€ãã¿ãŒã²ãããšããŠéžæããå¿ èŠããããŸãã ã¢ãªãç§ã®è»å¡ã®äžã«ç«ããªãå Žåãå¢çã»ã«ãéžæããããããžè¡ãã®ãæãéããªããŸãïŒBFSã䜿çšããŠæ±ºå®ãããŸãïŒã ãã以å€ã®å Žåãã¿ãŒã²ããã»ã«ã¯ããã®ã»ã«ã®è¿ãã«ããèªåã®ã¢ãªãšæµã®ã¢ãªã®æ°ã®æ¯çãæµã®è»å¡ãŸã§ã®æšå®è·é¢ãè¿ãã®ã»ã«ã«è¡ãããã·ã§ã³ããã§ã«æã£ãŠããã¢ãªã®æ°ãããã³ããã«çããŸã§ã«ãããæéã䜿çšããè€éãªåŒã«ãã£ãŠæ±ºå®ãããŸãããã«çã...ãããåè«ã§ã:)ããã¯å¶ç¶ã«æ±ºå®ãããŸãã 絶察ã«å¶ç¶ã ãã®ããã«ïŒ
target = area.border.get(turnRandom.nextInt(area.border.size()));
ããã¯ç§ã®æåã®å®è£ ã§ãããéåžžã«ããŸãæ©èœãããããå€æŽããããšã¯ãããŸããã§ããã ããã·ã§ã³ãä»ã®ã¿ã¹ã¯ïŒé£æã®åéãªã©ïŒã«ãã£ãŠäžæãããå Žåãæ°ãããã®ã決å®çã«éžæããããããåäœã¯ãŸã å®å šã«ã©ã³ãã ã§ã¯ãªãã£ãããšã«æ³šæããŠãã ããã ããã«ãåã¿ãŒã³ã®å¢çã¯ç°ãªããããããã·ã§ã³ã¯éææŽæ°ããå¿ èŠããããŸãã ããã¯ãååãªæéãããã°ããã¹ãŠã®ç§»åããšã«è¡ãããåžžã«å°ãªããšã10åã®ç§»åããšã«è¡ãããŸãã
éå€
ã»ã«ã¯10åã®ç§»åã§å°éå¯èœã§ãããšçºèšããããšãã§ããŸã- ã»ã«ãŸã§ã®è·é¢ã77以äžã§ãããšæ£ç¢ºã«åãã§ã¯ãããŸããããããªãè¿ãã®ã§ãåé¡ã¯ãããŸããã§ãããããªãã®æéãã¢ãªãè¡ãæ¥ããããšããããããŸãã ããšãã°ã圌ãæ°Žã«å²ãŸããæŽçªã«äžäººã§ããŠãåºå£ã1ã€ãããªãå Žåã ãã®å Žåãã¢ãªã¯11ã¿ãŒã³ã®è·é¢ã«ããã±ãŒãžã調ã¹ãå¿ èŠãããããã1ã¿ãŒã³ããšã«ã¢ãªã¯æŽçªã«è¶³ãèžã¿å ¥ããŸãã ãããŠã次ã®åãã§ã調æ»ãããã®ãäœããªãããšãå€æãããããã¢ãªã¯åœå¢ã«è¡ãã次ã®åãã§ç©èªãç¹°ãè¿ãããŸãã ããã·ã§ã³ã®äœæã¯å®äŸ¡ãªæäœãªã®ã§ãããã¯ããã»ã©æãããšã§ã¯ãããŸããã ïŒ ãŸããã¯ãããããæããã«ã¢ã€ãã«ãªã¢ãªã¯ãããããæªãã§ãã-çŽtranslã ïŒ
é£ã¹ç©
ããã§ç¹ã«èå³æ·±ããã®ã¯ãããŸããã ç®ã«èŠãããã¹ãŠã®é£ç©ããBFSãèµ·åãã圌女ã®æ¹åã§èŠã€ãã£ãæãè¿ãã¢ãªãéããŸãã ç§ã¯é£ã¹ç©ã®å Žæãä¿åãã ã1ã€ã®ã¢ãªãäºãã«è¿ã2ã€ã®é£ã¹ç©ãåéã§ãããšã¯æããªã ã ããããé£ã¹ç©ã®è¿ãã«æµãããå Žåã«è¡åããç¹å¥ãªè«çããããŸãã éåžžãç§ã¯ã¢ãªã®äº€æãé¿ããããšããŸãããé£ã¹ç©ã®é£ã«ãŸã ã¢ãªãããå Žåãæµãé£ã¹ç©ãéããããšæ±ºããããç§ã¯ã¢ãªãç ç²ã«ããæºåãã§ããŠããŸããMcLeopoldã¯ãããã圌ã«ã©ã®ããã«èµ·ãã£ãã®ãã«ã€ããŠèªã£ãè¯ãæçš¿ãæžããŸããã
æµã®è»å¡
é£ã¹ç©ãšåæ§ã«ãæµã®è»å¡ããå§ããŠBFSãäœããŸãã æµã®è»å¡ãã20æ©ä»¥å ã®è·é¢ã«ãã4å¹ä»¥äžã®ã¢ãªã襲æããŸãã 10å以äžã®ã¢ãªãããå Žåãæµã®è»å¡ãäºãã«éåžžã«è¿ããããã§ã²ãŒã ã®æåã®éäŒã§åé¡ãåé¿ããããã«1ã€ã ããéä¿¡ããŸãã è»å¡ã«çŽæ¥4å¹ä»¥äžã®è»ãéãããšã¯ãããŸããããæµã®è»ãè¿ãã«ããããšãå€ããéåžžã«ç©æ¥µçã«ãã¬ã€ããã®ã§ãããã«ããããã®è»ãããŸããæŠã
ããŠã楜ãã¿ãå§ãŸããŸããïŒ ééããªããæŠãã®è«çãæãè°è«ãããåé¡ã§ãããç§ã®ã¢ãããŒãã¯ããã§ããæŠéæ©ãã°ã«ãŒãã«åããŠã次ã®ã¿ãŒã³ã«äœãèµ·ãããèŠãŠã¿ãŸãããã ãããè¡ãã«ã¯ãããŒãžã§ã³2以éã®ãã¹ãŠã§ã¯ãªããã¢ãªãå®è¡ã§ãããã¹ãŠã®åããã·ãã¥ã¬ãŒãããŸãããã¹ãŠã®çµã¿åããã«ã€ããŠãçžæã®èããããåãã調ã¹ãç¶æ³ãè©äŸ¡ããŠãæãæå©ãªãªãã·ã§ã³ãéžæããŸããæµã¯ç§ãã©ã®ããã«èŠããããç¥ã£ãŠãããç§ã«ãšã£ãŠæãå±éºãªæ¹æ³ã®ããã«èãããŸãã
ããã¯ããããã¯ã¹ããã³ã¢ã«ãã¡ããŒã¿ã¯ãªããã³ã°ã«éåžžã«äŒŒãŠãããããã€ãã®æ倧ããŒãïŒã¢ãªçšïŒããã³æµçšã®æå°ããŒããå¿ èŠã§ãã
äŸ
以äžã®ç¶æ³ãèŠãŠã¿ãŸãããã ã¢ãªAãBãCã¯å°é·ïŒç·ïŒãæµã¯ã¢ãªXãšYïŒéïŒã§ãã ïŒ ããŒã»ã³ã-æ°Žããã€ã³ã-åå°-çŽtranslã ïŒ% % % % % % % % A % % % % % . B % % % % . . C % % X . . . % % % Y . . % % % % % % %
ç§ã¯äœãèµ·ãã£ãŠãããã瀺ãå°ããªå³ãæãã®ãé¢åã§ã¯ãããŸããã§ããïŒ
N / E / S / Wã¯ããããå/æ±/å/西ã«ç§»åããããšãæå³ããã-ãã¯ãã®å Žã«çãŸãããšãæå³ããŸãã
ããªãŒã¯ãDFSã䜿çšããŠãªã³ã¶ãã©ã€ã§çæãããŸãã ã¢ãªAã®å¯èœãªåããæ€èšããããšããå§ãããã®åããã·ãã¥ã¬ãŒãããã¢ãªBã«ã€ããŠç¶è¡ããŸããæåŸã®æµã®ã¢ãªã移åããåŸãåçŽãªåŒã䜿çšããŠç¶æ³ãè©äŸ¡ããŸãïŒïŒæ»ãã æµã¢ãªã®æ°ïŒ-ïŒæ»ãã è»ã®æ°myïŒã æµã®ããŒãïŒæå°ïŒã¯åžžã«çµæãæå°ã«ãªãåããéžæããããŒãïŒæ倧ïŒã¯ãã®åŒã®å€ãæ倧ã«ãªãå€ãéžæããŸãã AãBãCãåïŒå·Šã®ãµãããªãŒïŒã«ç§»åãããšãäž¡æ¹ã®æµãã©ãã«ç§»åããŠãæ»ã¬ãããå€ã¯+2ã§ãã ããããAããã®ãŸãŸã«ããŠBãšCã ãã移åãããšãäž¡æ¹ã®æµãæ±ã«ç§»åã§ãããã®çµæãå šå¡ãæ»äº¡ããæçµçãªå€ã¯2-2 = 0ã«ãªããŸããããã¯çŽ æŽããããªãã·ã§ã³ã§ãã 2ã®çµæã«ã€ãªããå¯èœæ§ã®ããçµã¿åãããããããšã¯æ¢ã«ç¥ãããŠãããããè¶è²ã®ãã¬ãŒã ã®ä»ã®éšåãèŠãŠã¯ãããŸããããæµã¯åžžã«ç§ãã¡ã«ãšã£ãŠæãæçã§ã¯ãªãåããéžæããããããã®è¶è²ã®ãã¬ãŒã ã§ã¯0ãè¶ ããªãå€ãéžæãããŸãã
ã芧ã®ãšããããµãããªãŒãæç»ããŸããã§ããã ããã«ãå¯èœãªåãã®æ°ã¯éåžžã«å°ãªããã¢ãªã¯5ã€ãããªãããããã®å ŽåãããªãŒã¯ã¢ãªã®æ°ããææ°é¢æ°çã«ã¯ããã«åŒ·ããªããŸãã
æ¬äŒŒã³ãŒãã§ã®å®è£ ã¯æ¬¡ã®ããã«ãªããŸãã
List myAnts List enemyAnts bestValue = -Infinity void max(antIndex) { if antIndex < myAnts.size myAnt = myAnts[antIndex] for each possible move of myAnt simulate move max(antIndex+1) undo move else value = min(0) if value > bestValue bestValue = value save the current simulated moves of all my ants } int min(antIndex) { if antIndex < enemyAnts.size minValue = +Infinity enemyAnt = enemyAnts[antIndex] for each possible move of enemyAnt simulate move value = min(antIndex+1) undo move if value < bestValue return -Infinity // cut! if value < minValue minValue = value return minValue else return evaluate() }
ã¢ãªã®ãªã¹ããåããŠãããæé©ãªåãã®ãªã¹ããååŸããçµæãšããŠãmaxïŒ0ïŒãåŒã³åºãå¿ èŠããããŸãã
æé©å
移åããªãé£æ¥ãã2ã€ã®ã¢ãªã¯ãå Žæãåãæ¿ããå Žåãšåãã§ããããã2çªç®ã®ãªãã·ã§ã³ã¯ç¡èŠã§ããŸãã ãããéæããããã«ãæŠéåã«åã¢ãªã®äœçœ®ãç¶æããŸããæåã®ããŒãžã§ã³ã§ã¯ã8ã€ãŸã§ãæ°çŸããªç§å¿ èŠã ã£ãããã7ã€ä»¥äžã®ã¢ãªã§ããã«ã¢ã«ãŽãªãºã ã䜿çšããŸããã åæã«ããã€ãã®æŠããããå¯èœæ§ããããããããã¯æããã«å€ãããŸãã
ãã§ãã¯ãããåãã®ãªã¹ã
2çªç®ã®ããŒãžã§ã³ã§ã¯ãããŸããŸãªæé©åãè©ŠããŸãããããã«ãããå€ãã®ç¶æ³ã§èãã倧ããªã°ã«ãŒãããµããŒãã§ããŸããã ä»åºŠã¯æ°Žãªãã®å¥ã®äŸãèŠãŠã¿ãŸããããåã¢ãªã«ã¯ã移åã®ããã®5ã€ã®ç°ãªããªãã·ã§ã³ããããŸãïŒ2ã€ã®ã¢ãªãåãã»ã«ã«è¡ããšãã¯ã«ãŠã³ãããŸããïŒã. . . . . . . . A . . . . . . B . . . . . . C . . . . . . . . XY . . . . . . . . .
ã¢ãªAã¯ã©ããªããŸããïŒ åœŒãåã«è¡ãã°ã圌ã¯æŠãã«åå ã§ããŸããã圌ããã®å Žã«çãŸããªãã圌ã¯æŠãããé¢ããŸãã ãã¡ãããæ»æããæå³ããããã©ããã¯ãŸã ããããªãã®ã§ãäž¡æ¹ã®ã±ãŒã¹ãèæ ®ããå¿ èŠããããŸãã ããããAã西ãåããŸãã¯æ±ã«è¡ãã®ã¯ã©ãã§ããïŒ ãããã£ãŠã圌ã¯ééããªãæŠãã«åå ããããšã¯ãªããè©äŸ¡ã¯åœŒããã®å Žã«çãŸãå ŽåãšãŸã£ããåãã«ãªãããããã®åãã¯éèŠã§ã¯ãªããèæ ®ããå¿ èŠã¯ãããŸããã ããããBãšCãæå®ã®äœçœ®ã«æ®ã£ãŠããå ŽåãYã¯ããããæ»æããåã«åãã£ãŠæ©ããŸãã ãŸããBãšCã«ã€ããŠã¯ãååãã®åãã®æšå®å€ãæ±åãã®åãã®æšå®å€ã«çããããšã«æ°ä»ãããšãã§ããŸãããç§ã¯ãããèæ ®ããŸããã§ããã ãã®ãããã¢ãªããšã«ããã§ãã¯ããå¿ èŠãããåãã®ãªã¹ããèšç®ã§ããŸãã ãã¹ãããããµã€ã¯ã«ã¯å€æ°ãããŸããã°ã«ãŒãå ã®åã¢ãªãšè¿ãã«ãããã¹ãŠã®æµã®è¿ãã®ã»ã«ããã¹ãŠãã§ãã¯ããå¿ èŠãããããã§ãã
æµã«å¯ŸããŠã¯ã䌌ããããªããšãããããšãã§ããŸããããããã«ç°ãªããŸãã Aããã®ãŸãŸã«ããŠãBãšCãåã«åããŸãã XãšYã¯ã¢ã¯ã»ã¹ãŸãŒã³ã®å€ã«ãããŸããäœãããã«ããŠãããã®è©äŸ¡ã¯ããªãããã®å Žã«çãŸãã®ãšåãã ããã§ãã BããŸã åã«è¡ãããåãå Žæã«æ®ã£ãŠããå ŽåãYã¯åãžã®ç§»åãèæ ®ããå¿ èŠããããŸããããã¯ããããæŠéã«ã€ãªããããã§ãã æµãåããèæ ®ããå¿ èŠããããã©ãããç¥ãããã«ã¯ãç§ã®ã¢ãªãç¹å®ã®ã»ã«ã«ãããã©ãããç¥ãå¿ èŠãããããšãããããŸãã ãããã£ãŠãåæµã«ã¯ãã»ã«ïŒç§ã®ã¢ãªãããå¯èœæ§ãããïŒãããã§ãã¯ããå¿ èŠãããåãã®ãªã¹ããžã®å¯Ÿå¿ããããŸãã ãããã®éä¿¡ã¯ããã¹ããããã«ãŒãã®ãã倧ããªã¯ã©ãŠãã§æ§ç¯ãããŠããŸã...
ããã§ã¯è¡ãšåã®çªå·ïŒè¡/åã瀺ãããŠããŸãïŒã䜿çšããŠäŸåé¢ä¿ããŒãã«ã衚瀺ããå¥ã®äŸããããããäŸãæ°ã«å ¥ã£ãŠããã ããã°å¹žãã§ãã
0 1 2 3 4 5 0 . . . . . . 1 . . , A . . 2 . . . , B . 3 . . . . , . 4 . X . . . . 5 . . . . . .
ïŒ1/2ïŒã«ã¢ãªãããå Žåãant Xã¯ïŒ3/1ïŒã確èªããå¿ èŠããããŸãã ïŒ2/3ïŒããªã³ã®å ŽåãïŒ3/1ïŒããã³ïŒ4/2ïŒã確èªããŸãã ïŒ3/4ïŒã®å ŽåãïŒ4/2ïŒããã§ãã¯ããŸãã ããŒãã«ã¯æ¬¡ã®ããã«ãªããŸãã
(1/2) => [ (3/1) ] (2/3) => [ (3/1), (4/2) ] (3/1) => [ (4/2) ]
ãããã®ãªã¹ãã¯ããªãŒã®åå²ãå€§å¹ ã«åæžããŸãããæ®å¿µãªãããèšç®ã«ãããæéãèŠç©ããããšã¯å°é£ã§ãã ç§ã¯ã¢ãªã®æ°ã«åºã¥ããŠã°ã«ãŒããåãé¢ããŸããããèæ ®ããå¿ èŠãããåãã®æ°ãšæµã®æ°ã«å¶éã課ããŸãã
ã°ã«ãŒããæ§æãããšããç§ã¯ä»»æã«æåã®ã¢ãªãéžæãããã®åŸã圌ãšåœŒãã移åããå Žåã«æŠéã«åå ã§ãããã¹ãŠã®æµã¢ãªãã°ã«ãŒãã«è¿œå ããŸãã 次ã«ããããã®æµãæ»æã§ããã¢ãªãè¿ãã«æã£ãŠãããã©ããã確èªããŸãã ãã®ãããªãã®ãè€æ°ããå Žåãæåã«æåã®ã¢ãªã«è¿ãæ¹ãè¿œå ãã圌ã®ããã«æµãæ¢ããŠããŸãã ãã®ããã»ã¹ã¯ãå¶éã«éããããè¿œå ã§ãã人ããªããªããŸã§ç¹°ãè¿ãããŸãã ç§ã®ã¢ãªã®ããããã«ãšã£ãŠã圌ã®ã°ã«ãŒãã«ã¯ãã¹ãŠã®æµãããããšãéèŠã§ãã åæã«ãç§ã®ã¢ãªã¯1ã€ã®ã°ã«ãŒãã«ããæå±ã§ããŸããããæµã¯äžåºŠã«è€æ°ã®ã°ã«ãŒãã«æå±ããå¯èœæ§ããããŸãã
æ Œä»ã
è©äŸ¡é¢æ°ã¯ã殺ããã人ãšèŠç¥ãã¬äººã®æ°ã ãã§ãªããç§ãšã¢ãªã®æµãšã®è·é¢ãèæ ®ããŸãã ããã«ãããŸãïŒ if (beAgressive) return enemyDeadCount * 300 - myDeadCount * 180 - distValue; else return enemyDeadCount * 512 - myDeadCount * (512+256) - distValue;
beAgressiveãã©ã°ãèšå®ãããŠããå Žåãæ»ãã æµã®ã³ã¹ãã¯300ãã€ã³ãã«ãªããæ»ãã æµã¯180ããã«ãã£ãç§ããããŸãããããã£ãŠã1人ã®ã¢ãªã殺ããŠ1人ã®æµã殺ãã3人ã®ã¢ãªã殺ããŠ2人ã殺ããŸãã éã¢ã°ã¬ãã·ãã¢ãŒãã§ã¯ããããã¯åçã®äº€æãè¡ããŸãããã3察2ãäžããæºåãã§ããŠããŸããdistValue-åã¢ãªããæãè¿ãæµãŸã§ã®è·é¢ã®åèšãæµã«è¿ãæ¹ãè¯ãããããã®éãå·®ãåŒããŸãã
beAgressiveãtrueã«èšå®ãããã®ã¯ãã€ã§ããïŒããã¯ãã¢ãªã®ç·æ°ãäœçœ®çåªäœæ§ãšã¯é¢ä¿ãããŸãããããã«ã«è¿ãã¢ãªã®æ°ã«ã®ã¿äŸåããŸããããæ£ç¢ºã«ã¯ãç§ã®ã¢ãªã®é£ã®ããã«ïŒã°ã«ãŒãã§ã¯ãªããããã«ïŒã®ã¢ãªã®æ倧æ°ã14以äžã®å Žåã«ãã©ã°ãèšå®ãããŸãããªãã§ããïŒäž»ã«42ã14ã§å²ãããŠããããã§ãïŒ
æ¥è¿ããæµ
approachEnemiesã¡ãœããã¯ãæŠéã®çŽåŸã«åŒã³åºãããæµã®è¿ãã«ããç§ã®ã¢ãªã®æ¹åãéä¿¡ããŸããã¢ãªããšã«ãæåã«A *ãèµ·åããŸããããã¯ãããªãŒã»ã«ã®ã¿ã«æ²¿ã£ãŠç§»åããŸãïŒã€ãŸããä»ã®ã¢ãªãããã»ã«ã¯ãã§ãã¯ããŸããïŒããã®æ¹æ³ã§ãã¹ãèŠã€ãã£ãå Žåããã®ãã¹ã®æåã®ç§»åãå®è¡ãããŸããããã®çç±ã§ããããã¯äžåã«äžŠãã§ããããšããããããŸãããªããªããåç·ã«ãã€ãã圢æããããšã2è¡ç®ã®èª°ããããã«ããã«è¡ã£ãããã§ãããŸããããŒã¿çã®æ®ãã®éšåã§ããattackDetachedEnemiesã¡ãœããããããæåã«å€ç«ããæµã«ã¢ãããŒãããå¿ èŠããããŸããã
ä¿è·
æåã®ããŒãžã§ã³ã§ã¯ä¿è·ããŸã£ãããããŸããã§ãããã2çªç®ã®ããŒãžã§ã³ã§ã¯ãå€ãã®ã¢ãªãå«ãã«ãŒãã®äººæ°ãé«ãŸã£ããšãã«ããããè¿œå ããŸãããè»å¡ãä¿è·ããã®ã¯ã4é 以äžã®å Žåã®ã¿ã§ãããããçã«ããªã£ãŠãããã©ããã¯ããããŸãããããããããããšãã¯ããŸã奜ãã§ã¯ãããŸãããç§ã¯è»å¡ã®è¿ãã§æµãæ¢ããŠããŸã-ä¿¡ããããªãã§ããã-å¹ åªå æ¢çŽ¢ïŒæ¬¡ã«ããããã®æµãè·é¢ã§äžŠã¹æ¿ããããããã«å¯ŸããŠ1人ã®ãã£ãã§ã³ããŒãèŠã€ããããšããŸããæåã«ãç§ã¯æµãè»å¡ã«å°éããããã«è¡ããªããã°ãªããªãçµè·¯ã«è¿ã人ã ã®äžããæ€çŽ¢ããŸãããã®ãã¹ã¯ç°¡åã«ååŸã§ããŸããBFSäžã«ä¿åãããŠããæ å ±ã«ã€ããŠã¯ãåã®ã»ã«ã«æ»ãã ãã§ããé²åŸ¡è ãããªãå Žåãå¥ã®BFSãèµ·åããŸããããã¯ããã®æµã®é²è·¯ã®1/4ã«æãè¿ãã¢ãªãæ¢ããŠããŸãããã®zashitnikã1/2ã®æ¹æ³ã§éä¿¡ããŸããã¢ãªã1察1ã§äº€æããããšã¯ãã¢ãªã倱ãããšãããæããªãããããããå®å šãã©ããã¯ãã§ãã¯ããŸãããæµã®åé¿
äžè¬çã«ãç§ã¯1察1ã®ããåããé¿ããããšããããã1人以äžã®æµã®ç®ã§ç§ã ãã®ã¢ãªãéããŸããç§ã¯ã¢ãªã®å¯èœãªãã¹ãŠã®åããèæ ®ããå®å šãªãã®ãèŠã€ããããšããŠããŸããããã§ãªãå Žåã¯ãæµãç§ã®æ¹åã«è¡ãã°ãå°ãªããšãæµã殺ãåããããŸããã»ãšãã©ã®å Žåãããã€ãã®å®å šãªåããããããšãã§ããŸããéžæããããã«ãããŒãžã§ã³3ã§æåŸã«è¿œå ãããæ¥ãã§å€æŽãããããžãã¯ã®1ã€ã§ããããšãå€æããŸãããè¿·è·¯ããããESCAPE_CHECK_DISTã®æ倧深床ïŒ8ã«çããïŒã§BFSãèµ·åãããã¹ãŠã®å®å šãªåãã®å€ãåèšããããšã§ããããåé¿ããŸããã
int addValue = (ESCAPE_CHECK_DIST+1-tile.dist); if (tile.type == Type.MY_ANT) addValue *= 3; else if (tile.type.isEnemy()) addValue *= -3;
é åž
ãŸããããã¯ã»ãšãã©ã®å ŽåãããŒã¿çã®ãšã³ãŒã§ããããããåãé€ãããšã¯ã§ããŸããã§ãããããŒã¿çã§ã¯ãè»å¡ã®ç Žå£ã¯ãããŸããã§ããã®ã§ã誰ããæåã«é£ã¹ç©ã«å°éããããã«ãéæãŸãŒã³ã«ã§ããã ãå€ãã®çŽ°èãä¿æããããšããŸããã
ç§ã¯ã¢ãªãšåœŒã®è¿ãã«ãããã¹ãŠã®äººããBFSãéå§ããŸããèãããããã¹ãŠã®åãã«ã€ããŠãå€ãåèšããæå°ã®åãã§å°éã§ããã»ã«ã®æ°ãæ倧ã«ããåããæ¢ããŸããïŒç§ã¯ç解ããããã«ãã®ãã¬ãŒãºã5åèªã¿çŽããŸããïŒ-çŽç¿»èš³ïŒã
ãããã®æçµããŒãžã§ã³ã§ã¯ãããã¯ãã£ãã«äœ¿çšãããŸããã§ãããäžéšã®ç¶æ³ã§ãç§ã®ã¢ãªã®1人ãæµã®é£ã«ãããšãã ãã§ãã
ããŠãããã ãã§ãïŒ
ç§ã説æããªãã£ãå€ãã®å°ããªè©³çŽ°ããããšç¢ºä¿¡ããŠããŸãããå šäœåã衚瀺ãããã¯ãã§ããããªãããããèªãã ãšããäºå®ããããªããããããã®æèŠãæã£ãŠããããšãé¡ã£ãŠããŸãããããŠãç§ã¯ããæ¥ãªã¢ã«ãŽãªãºã ã䜿çšããªãããšãè¬çœªããŸãã
IRCã«ã¯åŒãç¶ãåå ã§ããŸãããããã次ã®ã³ã³ãã¹ãã«åå ããŸãããåã³å€ãã®æéãè²»ããããšã¯ã§ããªãã§ãããã
翻蚳è ãã
æ£çŽãªãšããããã®èšäºãèªãã ãšãã¯ãšãŠãé©ããŸãããåè ã®ã¢ã«ãŽãªãºã ã«ã¯éåžžã«å€ãã®æ¬ é¥ããããŸããã倩äºããåã£ãå®æ°ãä¿æ°ãèŠããŠããããå€ãã®éåžžã«éèŠãªèŠçŽ ãèæ ®ããªãã ãã§ããããã«ãããããããåè ãæ¹å€ããããšã¯å°é£ã§ãããªããªãã圌ããèšãããã«ããæåã«ãããæã«å ¥ãããïŒããæãæåããã®ã¯ããã«ã¢ã«ãŽãªãºã ã§ãããéåžžã«ã·ã³ãã«ã§ãããæããã«éåžžã«å¹æçã§ããçŽæ¥ã®æŠãã§ã¯ãxathisãæ確ãªãªãŒããŒã ã£ãããã§ãã圌ã®èãã«åºã¥ããŠãä¿æ°ã®åçéžæãåããããäžè¬çãªã·ã¹ãã ããŸããªãäœæãããTCPãµãŒããŒã§éåžžã«å£®å€§ãªæŠããèµ·ãããšèããããŠããŸãã
ããªããèå³ãæã£ãŠããããšãé¡ã£ãŠããŸãã