Skip to content

Grasshopper

Jon Thysell edited this page Feb 28, 2018 · 2 revisions

Each player starts with three Grasshopper tiles.

Movement

The Grasshopper moves by leaping up and over a straight line of bugs. It can both start and/or end completely surrounded by other bugs. It can leap over stacks of Beetles. It cannot leap over a gap. It cannot break the hive.

Calculating Movement

Pick a direction from the starting position. If there's a tile in that direction, then keep checking for further tiles in that direction. Stop when there's no more tiles in that direction. If there was at least one tile in that direction, save the move to the last position you checked (where there was no tile). Repeat for all directions from the starting position.

Assuming you've already validated that moving the Grasshopper does not break the Hive, the pseudo-code looks as follows:

validMoves = new collection of valid movements
startingPosition = starting position of Grasshopper

foreach (Direction direction in Directions)
    landingPosition = position in direction from startingPosition
    
    distance = 0
    while (HasPieceAt(landingPosition))
        landingPosition = position in direction from landingPosition
        distance++
    
    if (distance > 0)
        validMoves.Add(move to landingPosition)

return validMoves