Improving time complexity for Count the Islands DFS
Given there are only 22-28 tiles in a Hive game, the time complexity of the check probably doesn't matter much.  Nevertheless, a modified scanline fill algorithm might be faster than a DFS.  This answer explains the algorithm fairly well. In this use case it might be easier to scan down the columns instead of across the rows.
From the rules of the Hive game, it seems the &quot;one hive rule&quot; would need to be checked when a tile is put down on the playing field and when it is picked up from the playing field (e.g., to move it).  When a tile is put down, it is sufficient to make sure it touches another tile (beside or on top).
When a tile is picked up, it is necessary to make sure it's former neighbor tiles are still connected via another path.  This may be trivial such as when the neighbors are adjacent, or may require searching for a path using a DFS, BFS, spanning tree, or fill/paint algorithm.
In any case, the AI should know which tile is being moved, so it shouldn't be necessary to scan the hex grid.  Just start from one of the tiles neighbors.