Sunday, March 16, 2025

Google I/O Puzzle: Gemini’s Role In Finding Hidden Worlds

Using Gemini to unlock additional worlds for the Google I/O puzzle.

Breaking the code

Google I/O puzzle Breaking the code
Image Credit To Google

Players must use prisms to alter light and colour in order to unlock different areas of the game world in this year’s Google I/O puzzle. The gameplay bonus worlds, which are concealed behind riddles created using the Gemini API, have been expanded outside the main game loop. help go over the process of created it in this blog!

An innovative and expandable option is the Gemini integration

As Gemini models create original puzzles for players to solve and locate, hidden tiles are dynamically added to the map. The objective? to encourage players to investigate new facets of the AI-built puzzle in order to increase interest.

There employed artificial intelligence (AI) to assist us with scaling the feature in a difficult and distinctive way, as opposed to manually hardcoding hundreds of potential secret tile placements and associated riddles.

Google I/O Puzzle
Image Credit To Google

Dynamic riddle generation is the solution

Also came up with a method that coupled algorithmic accuracy with AI-powered creativity in order to capitalize on Gemini’s advantages. Based on the game rules, a backend algorithm positioned hidden tiles on the map and produced a prompt for the Gemini API that included three straightforward instructions identifying the location. This made guaranteed that, within the parameters of the game, each puzzle had a logical answer. The algorithmically produced response was converted into a smart riddle using Gemini.

Generating prompts using algorithms

Individuals automatically identified a “secret location” on the game board that served as Gemini’s prompt based on the game’s rules. This made guaranteed that every riddle had a valid and solvable solution.

// 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,
    }
  }

Simple text like this was the algorithm’s output:

  1. Right beneath a wall.
  2. A rainbow node is exactly two tiles distant.
  3. Within the first section.

Making a Gemini riddle

It then used the Gemini API to develop a riddle that cryptically explained the location of the secret tile after establishing a consistent framework for the prompt’s generation. It were able to produce interesting and difficult riddles that were consistently formatted so that the front end application could show them to users by providing Gemini with the required context and limitations.

// 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
  }

Why riddles?

A certain amount of uncertainty is required, because riddles are by their very nature cryptic and entertaining. This made it possible for us to accept the sporadic “red herring” or unexpected phrase that could appear in output produced by AI. In addition, riddles test players’ ability to reason by requiring them to use their imagination and their understanding of the game’s rules to analyse the board’s arrangement in order to find the hidden tile.

Making sure that the output produced by LLM adheres to the system instructions

The challenges of working with AI are unique. The propensity of AI to “hallucinate” or stray from established norms is among the most important. By creating a prompt programmatically and including examples and a defined JSON output in the System Instructions for the prompt, one can were able to reduce this risk:

**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.

It also made use of human reasoning abilities. Gamers are skilled at deciphering and analysing cryptic clues. This enabled players to overcome any possible discrepancies in AI output by designing riddles that demanded logical deduction. In the end, it came down to striking the correct balance between human creativity and AI-generated material.

Build with the Gemini API in your apps today

The first Google I/O puzzle with the Gemini API was released this year, marking a significant milestone. It was more than just integration between the technical and design teams; it was a careful investigation into a new age of AI-powered collaborative creation. Not only were it developing a new function, in addition to were also leading the way in interactive experiences. Keep in mind these three important principles while deciding how to incorporate the Gemini API into your own projects:

  • Creativity: Use AI in your products in previously unattainable ways to generate dynamic content, scale, and automate tasks.
  • Design: To test your results with various Gemini models and capabilities, try composing prompts that work and make prototypes in Google AI Studio.
  • Implementation: To make your output more structured and consistent in a way that your application can understand, write comprehensive System Instructions that specify the output format with examples of the required model response.

AI is creating new and engaging user experiences by altering how people engage with the games and apps.

Come see this year’s spectacular announcements live from Shoreline Amphitheatre in Mountain View at Google I/O May 20–21 online. The potential of Gemini to provide your consumers with more enjoyable and beneficial experiences is limitless, therefore would invite you to give it a try.

Drakshi
Drakshi
Since June 2023, Drakshi has been writing articles of Artificial Intelligence for govindhtech. She was a postgraduate in business administration. She was an enthusiast of Artificial Intelligence.
RELATED ARTICLES

Recent Posts

Popular Post

Govindhtech.com Would you like to receive notifications on latest updates? No Yes