Unlocking bonus worlds with Gemini for the Google I/O puzzle

3月 13, 2025
Jay Chang Senior Product Marketing Manager Developer Activations

Cracking the code


This year’s Google I/O puzzle challenges players to manipulate light and color through prisms to unlock sectors of the game world. Beyond the core game loop, a new dimension was added to the gameplay–bonus worlds hidden behind riddles generated with the Gemini API. This blog will review how we built it!

The Gemini integration: A creative and scalable solution

Hidden tiles are dynamically placed on the map as Gemini models generate unique riddles for players to solve and find them. The goal? To create higher engagement by incentivizing players to explore new dimensions of the puzzle built with AI.

Rather than manually hardcoding 100s of possible secret tile locations and corresponding riddles, we used AI to help us scale the feature in a way that was challenging and unique.

Our solution: Dynamic riddle generation

To leverage Gemini's strengths, we devised a solution that combined algorithmic precision with AI-powered creativity. A backend algorithm placed hidden tiles on the map and generated a prompt for the Gemini API based on the game rules describing the location with three simple instructions. This ensured that every riddle had a logical solution within the game's framework. We used Gemini to transform the algorithmically generated answer into a clever riddle.


Algorithmic prompt generation

Based on the game's rules we programmatically determined a "secret location" on the game board that was used as the prompt for Gemini. This ensured that the answer to each riddle was always valid and solvable.

// Finds a new hiding spot for the Gemini token and generates a clue string
  getHiddenLocation() {
    const geminiCluePositions = GameWorld.getCluePositions() // Returns positions that are designated as a "Clue" tile. We tag important tiles when designing a level. These are generally tiles that are not movable by the player.


    // We get all the tiles positions in the level, a position is a simple XY coordinate
    const secretLocations = GameWorld.getAllTilePositions()
      // we remove tiles that are not adjacent to a clue position...
      .filter((tileA) => geminiCluePositions.some((tileB) => GameWorld.isNextTo(tileA, tileB)))
      // we remove invalid positions, such as tiles that are not empty
      .filter(({gridX, gridY}) => GameWorld.isValidGeminiPosition(gridX, gridY))


    // we randomly choose a hiding spot
    const randomPosition = secretLocations[Math.floor(Math.random() * secretLocations.length)]


    const randomTile = Gameworld.getTileByPosition(randomPosition)


    // now that we have a hiding spot, we generate a clue string
    const riddleClues = GameWorld.generateGeminiRiddleClues(tilePosition)


    return {
      position: randomPosition,
      clues: riddleClues,
    }
  }

The output of the algorithm was simple text like:

1. Directly below a wall.

2. Exactly 2 tiles away from a rainbow node.

3. In the first sector.


Gemini riddle creation

With a consistent structure for the prompt to be generated, we then turned to the Gemini API to create a riddle that cryptically described the secret tile’s location. By prompting Gemini with the necessary context and constraints, we were able to create engaging and challenging riddles that were consistently formatted in a way our front end application could display them to users.

// Build a prompt based on the tile position. We always output 3 rules in this order:
    // Clue 1. The type of one adjacent tile to the secret location
    // Clue 2. The sector which contains the secret location
    // Clue 3. The closest color node to the secret location, and exactly how many tiles away it is.
  generateGeminiRiddleClues(tilePosition) {
    const adjacentTiles = GameWorld.getAdjacentTiles(tilePosition) // Get the left, right, top and bottom neighboring tiles
    const locationSector = GameWorld.getTileSector(tilePosition) // get the "sector" of the tile. Levels are divided in sectors or 'chunks' by the level designer.


    const nodeTiles = GameWorld.getAllNodeTiles() // get every 'Node' tile in the level


    // clue 1
    const randomAdjacentTile = adjacentTiles[Math.floor(Math.random() * adjacentTiles.length)]
    const direction = GameWorld.getDirection(randomAdjacentTile, tilePosition)
    const randomTileType = randomAdjacentTile.type
    const firstClue = `Directly ${direction} a ${randomTileType} tile` // e.g. "Directly above a wall tile"


    // clue 2
    const secondClue = `In sector ${locationSector}` // e.g. "In sector 3"


    // clue 3
    const closestNode = nodeTiles.reduce((closest, node) => {
      const distance = GameWorld.getDistance(node.position, tilePosition)
      if (distance < closest.distance) {
        return {node, distance}
      }
      return closest
    }, {node: null, distance: Infinity})


    const thirdClue = Exactly ${distance} tiles away from a ${closestNode.node.color} node`


    const clues = `1. ${firstClue}. 2. ${secondClue}. 3. ${thirdClue}.`


    return clues
  }

The resulting riddle was then:

I stand directly below a wall so high,

Two tiles from a rainbow node, I lie.

Within the first sector, my place you'll see,

Solve this and claim the token's victory.


Why riddles?

Riddles are inherently cryptic and fun, plus a degree of ambiguity is expected. This allowed us to embrace the occasional "red herring" or unexpected turn of phrase that might arise from AI generated output. Furthermore, riddles engage players' reasoning skills, encouraging them to think creatively and apply their knowledge of the game's rules, analyzing the layout of the board as they search for the hidden tile.


Ensuring consistency in LLM generated output with System Instructions

Working with AI comes with its own set of challenges. One of the most significant is the tendency for AI to "hallucinate" or deviate from provided rules. We mitigated this risk by programmatically generating a prompt, providing examples and a defined JSON output in the System Instructions for the prompt:

**Important Instructions:**
        - Respond **only** with the JSON object in the exact format specified.
        - Do **not** include any explanations, code blocks, or additional text.
        - Do **not** enclose the JSON in triple backticks or any markdown formatting.
        - Ensure all strings in the JSON are properly escaped.
        - Escape special characters like newlines (`\\n`), tabs (`\\t`), and quotation marks (`\\"`) within strings.
        - Do not use single quotes; use double quotes for all JSON keys and string values.
        - Ensure the JSON is valid and parsable.

We also leaned into the human capacity for reasoning. Players are adept at interpreting and deciphering cryptic clues. By creating riddles that required logical deduction, we empowered players to overcome any potential inconsistencies in AI output. Ultimately, it was about finding the right balance between AI-generated content and human ingenuity.


Build with the Gemini API in your apps today

This year marked a milestone: the first Google I/O puzzle featuring the Gemini API. For our design and engineering teams, it was more than just integration—it was a thoughtful exploration into a new era of collaborative creation with AI. We weren't just building a feature; we were pioneering a new approach to interactive experiences. As you consider bringing the Gemini API into your own projects, remember these three key lessons in determining your approach:

  • Creativity: Leverage AI in your products for dynamic content generation, scalability, and automation in ways you haven’t been able to before.

  • Design: Test writing effective prompts and create prototypes in Google AI Studio to test your results with different Gemini models and capabilities.

  • Implementation: Write detailed System Instructions to define output format with examples of your desired model response to make your output more structured and consistent in a way your application can interpret.


AI is changing how users interact with our apps and games, opening doors to new and exciting user experiences.

Join us online for Google I/O May 20-21, for this year’s exciting announcements streaming live from Shoreline Amphitheatre in Mountain View. We encourage you to experiment with Gemini and explore its potential to create more helpful and fun experiences for your users; the possibilities are endless.