Skip to main content

Quick Overview

This video is a hands-on developer tutorial presented by Luke Schlangen for Google Cloud Tech. It follows earlier codelabs on building web apps and portfolios, walking viewers through creating a turn-based video game using Google AI Studio Build Mode and Firebase Firestore. It was created to demonstrate how AI development tools and event sourcing architectures can be combined to build and deploy multiplayer games.

Key Points

  • 1.Event sourcing records every game turn as a distinct sequential event rather than overwriting existing database entries.
  • 2.Google AI Studio Build Mode generates the full-stack web application, Firestore integration, and Minimax AI opponents from natural language prompts.
  • 3.Firestore security permission errors can be diagnosed and resolved automatically using the Fix feature in Google AI Studio.
  • 4.Firebase Firestore real-time data synchronization allows live multiplayer matches across separate devices without manual socket configuration.
  • 5.Logging event history enables time-travel features such as scrubbing through past turns and rolling back moves.

Summary

Luke Schlangen presents a tutorial on creating and deploying a turn-based web game using Google AI Studio and Firebase. Building on earlier codelabs covering portfolio pages and task applications, this project introduces event sourcing. In standard database updates, existing values are overwritten with new state data. In contrast, event sourcing appends each move as an individual record in a chronological history. This design choice makes it possible for players to scrub through turn history, replay entire games, and undo previous moves.

Development begins in Google AI Studio Build Mode using a detailed prompt for a turn-based Tic-Tac-Toe web application. The prompt specifies Firebase Firestore for persistence, an algorithmic Minimax opponent for single-player play without Large Language Model API calls, Google Sign-In with guest fallback, and shareable match codes for multiplayer. The interface prompts the user to enable Firebase Firestore, which configures the underlying project resources and opens the interactive preview.

When testing single-player mode against the Minimax bot, the initial match creation fails due to missing or insufficient Firestore permissions. Schlangen uses the built-in Fix action in AI Studio, which diagnoses the issue and updates firestore.rules to permit creating match documents and appending events for both authenticated users and guest players. Once applied, solo play works as expected, and a time-travel slider underneath the game grid demonstrates stepping backward through past game events.

The application is published to Cloud Run under a custom domain to test real-time multiplayer functionality across separate browser windows. During the test, the guest player is initially blocked from making a move. Schlangen copies the on-screen error directly into the AI Studio prompt box. The AI diagnoses a session-persistent guest identifier issue, updates automatic seat claiming logic, and republishes the application, resolving the turn-taking block.

Finally, Schlangen navigates to the Firebase console to examine the database structure. The console displays a games collection containing match documents, each holding an events subcollection. Each event entry contains the player actor ID, move sequence number, turn count, timestamp, grid position, and event type. This ledger provides the complete event stream used by the web client to determine board state and handle synchronized multiplayer play.

Understanding Event Sourcing in Game Design

The tutorial introduces event sourcing as a method of state management where every player action is appended as a distinct history entry instead of overwriting existing database values. This structure allows turn-based video games to reconstruct game boards from history, supporting replays and turn rollbacks.

Prompting and Building in AI Studio

Using Google AI Studio Build Mode, a turn-based Tic-Tac-Toe application is generated with Firebase Firestore as the backend, Minimax algorithmic opponents for solo play, and Google authentication alongside guest player options.

Fixing Firestore Rules and Debugging Errors

When early builds encounter Firestore security permission errors or player seat assignment bugs in multiplayer mode, the errors are fed back into Google AI Studio to automatically update security rules and source code.

Deploying and Inspecting the Event Ledger

The application is deployed live to Cloud Run, where multiplayer matches are tested between separate browser windows using match codes, followed by an inspection of the raw event ledger in the Firebase console.

The Bottom Line

The video demonstrates how to combine Google AI Studio Build Mode with Firebase Firestore and Cloud Run to produce a functioning multiplayer web game based on event sourcing. It establishes practical workflows for prompting game logic, debugging automated Firestore security rules, and validating database event logs. It leaves advanced topics, such as incorporating direct LLM calls into gameplay using Firebase AI logic, for future tutorials.

FAQ

What is event sourcing and how is it used in a web-based video game?

Event sourcing is a design pattern where changes to application state are recorded as an append-only sequence of individual events rather than overwriting existing records. In a video game, each turn is saved as a discrete event, allowing the application to rebuild game state and enable features like turn rollbacks and game replays.

How does Google AI Studio Build Mode generate the turn-based video game application?

Google AI Studio Build Mode uses a text prompt specifying the game rules, AI algorithms, authentication options, and database architecture to produce full-stack code, client components, and deployment configurations.

How are missing Firestore security permissions resolved during testing in Google AI Studio?

Permission errors are resolved by clicking the automated Fix option in Google AI Studio, which inspects the error and updates the firestore.rules configuration file to grant appropriate read and write access to authenticated and guest users.

How does the web-based video game handle multiplayer synchronization across different browser windows?

Multiplayer synchronization is handled through Firebase Firestore real-time updates, which sync event records between the host and joined players using a six-character game room code.

What specific data is stored within the Firestore events subcollection for each game move?

Each event document records the player actor ID, sequence number, turn count, move position, timestamp, and event type.

Worth watching for

Web developers and hobbyist game creators interested in using generative AI tools and Firebase Firestore to build and deploy turn-based web games.

  • google-ai-studio
  • firebase
  • firestore
  • event-sourcing
  • cloud-run
  • web-development