title: A* Pathfinding - Stop moving diagonal through tiles
body: <p>I'm trying to get my head around the A* search algorithm and I got a square moving through a maze but the square will travel through two tiles that are touching by the corners. Here is an example:</p>
  
  <p><a href="https://i.stack.imgur.com/Uv7QI.png" rel="nofollow noreferrer">Image - Click here</a></p>
  
  <p>Is there anyway of stopping the algorithm from adding this to the path</p>
  
  <pre><code>public List&lt;Node&gt; findPath(Vector2i start, Vector2i goal){
  
      List&lt;Node&gt; openList = new ArrayList&lt;Node&gt;();
      List&lt;Node&gt; closeList = new ArrayList&lt;Node&gt;();
  
      Node current = new Node(start, null, 0, getDistance(start, goal));
      openList.add(current);
      while(openList.size() &gt; 0){
          Collections.sort(openList, nodeSorter);
          current = openList.get(0);
          if(current.tile.equals(goal)){
              List&lt;Node&gt; path = new ArrayList&lt;Node&gt;();
              while(current.parent != null){
                  path.add(current);
                  current = current.parent;
              }
              openList.clear();
              closeList.clear();
              return path;
          }
          openList.remove(current);
          closeList.add(current);
          for(int i = 0; i &lt; 9; i++){
              if(i == 4) continue;
              int x = current.tile.getX();
              int y = current.tile.getY();
              int xi = (i % 3) - 1;
              int yi = (i / 3) - 1;
              Tile at = getTile(x + xi, y + yi);
              if(at == null || at == Tile.voidTile) continue;
              if(at.isSolid()) continue;
  
              Vector2i a = new Vector2i(x + xi, y + yi);
              double gCost = current.gCost + getDistance(current.tile, a);
              double hCost = getDistance(a, goal);
              Node node = new Node(a, current, gCost, hCost);
              if(vecInList(closeList, a) &amp;&amp; gCost &gt;= current.gCost) continue;
              if(!vecInList(openList, a) || gCost &lt; node.gCost) openList.add(node);
          }
      }
      closeList.clear();
      return null;
  }
  </code></pre>