BairesDev
  1. Blog
  2. Innovation
  3. AI Castaway: Can an LLM Survive on a Remote island?
Innovation

AI Castaway: Can an LLM Survive on a Remote island?

AI Castaway demonstrates deep AI integration in games, using LLMs to drive core mechanics. This goes beyond surface interactions and highlights its potential to create more dynamic, responsive game worlds.

Danilo Vaccalluzzo

By Danilo Vaccalluzzo

As Senior Director of AI and SEO at BairesDev, Danilo Vaccalluzzo leads AI innovation and process automation across the company, enhancing efficiency and customer engagement.

11 min read

AI Castaway

In the 2010s, developers began incorporating more complex decision-making trees in games. The Witcher 3: Wild Hunt (2015) featured branching narratives with choices that impacted entire game regions. In games like Detroit: Become Human (2018), developers coded complex, adaptive storylines. These storylines offered players more personalized experiences. However, neither incorporated AI to build those dynamic storylines that would differ from player to player. 

Now, with Generative AI (GenAI) and large language models (LLMs) stepping in, AI could drive core gameplay mechanics. It would not only enhance surface-level interactions and layouts, but also open new avenues for responsive game worlds. Additionally, it would offer a high degree of replayability since no two playthroughs are exactly the same. 

In demonstrating this to the development community, I’ve created AI Castaway, a survival simulation set on a remote island. This project is open-source, making it accessible for the development community to explore and contribute to. The cognitive engine for its main character integrates with LLMs. This transforms traditional NPC behavior into an adaptive experience. For the development community, AI Castaway serves as a proof of concept for deep AI integration into game systems. 

Rather than trotting behind a scripted non-player character (NPC) with limited decision trees, the AI player can improvise and learn. It better reflects the complexity of human decision-making. But will he survive?

AI Can Learn from Past Mistakes

The 2014 reality TV series “The Island with Bear Grylls,” dropped 13 normal people on inhibited islands to fend for themselves. It gripped viewers who watched the players forego food and resources when they committed survivalist mistakes. On watching more, viewers were rewarded by witnessing the players learn from those mistakes. The players built more sufficient encampments and gathered more food. In general, they survived better. 

Similarly, AI Castaway brings that element of unpredictability. The protagonist is not coded to run through a pre-conceived storyline. It can update its memory as it makes decisions that deplete its resources and adapts to changing circumstances. The traditional player-controlled experience is replaced by an AI that adapts strategies. It learns from mistakes and develops new survival techniques. It’s a first in showcasing unprecedented autonomy in gaming.

The intricate web of survival mechanics

In AI Castaway, the island environment is more than just a backdrop; it’s a dynamic, evolving challenge that tests the AI protagonist at every turn. The survival mechanics are intricately woven into the fabric of the game, creating a rich playground for the AI. Resource scarcity and distribution, a crafting system with evolving dependencies, and fluctuating vital statistics add layers of complexity. The terrain itself is a maze of hidden resources and potential dangers. All the while, long-term strategic objectives guide the AI’s journey.

As the AI navigates this intricate world, every decision it makes has rippling effects on its survival and future possibilities. It must continuously adapt its strategies, learning from past experiences and reacting to the ever-changing environment. The AI balances immediate survival needs with long-term goals. Additionally, it provides natural language explanations for its decisions. This adds new depth to the gameplay.

The deep integration of LLMs in AI Castaway illustrates how advanced language models can transform core gameplay mechanics. This project sets a new standard for creating immersive and intelligent game worlds. Bridging the game engine with a sophisticated AI makes this possible. In the following sections, we’ll explore the technical architecture behind this innovation. We’ll reveal the synergy between the game engine, server, and language model.

Balancing Short-Term Survival with Long-Term Goals

Balancing immediate survival needs with long-term objectives is a core challenge for the AI in AI Castaway. To navigate this complexity, several strategies are employed:

  1. The game’s objectives are organized into a hierarchy. The AI is guided to prioritize actions from urgent survival tasks to ultimate escape goals.
  2. Prompts to the LLM are dynamically adjusted based on the AI’s current state. Focus is placed on immediate survival when necessary and long-term planning when stable. 
  3. A memory system allows the AI to learn from past experiences, refining its decision-making over time. 
  4. The AI develops sophisticated, context-aware behavior by simulating the consequences of potential actions. It also employs multi-turn planning for complex tasks.

This approach enhances the AI’s ability to balance short-term and long-term goals. It also provides players with insights into its decision-making process, enriching the gameplay experience.

How It Works – Dissecting the AI

The core of AI Castaway lies in its LLM-powered protagonist. It leverages advanced language models like GPT-4, LLaMA3, and Mixtral-8x7B. Let’s delve into how the AI processes game states and makes decisions.

Architecture Overview

To create AI Castaway, I’ve designed a high-level architecture that ensures real-time decision-making while managing the demands of large language models.

The architecture consists of three main components:

  • Unity Game Engine: Handles real-time rendering, physics, and game mechanics. It captures the game state and sends it to the Python server.
  • FastAPI Python Server: Acts as a bridge between Unity and the AI. It processes the game state, interacts with the AI models, and sends decisions back to Unity.
  • LLM Integration: Uses API calls to engage with models like GPT-4 and LLaMA3, generating action plans based on game states and providing observations for decisions.

game-development-architecture

In operation, the Unity engine first captures the game state, then sends it to the Python server, and finally communicates with the AI models. The AI’s decisions are returned to Unity, which performs the action, updates the game stats, and repeats the cycle.

This architecture allows for flexible and scalable AI integration. It balances real-time responsiveness with sophisticated processing. Now, let’s explore the specific strategies used for LLM integration and decision-making.

LLM Integration

In AI Castaway, I’ve employed two distinct approaches for integrating large language models: zero-shot and agentic. Each offers unique benefits and is selected based on the game’s needs.

Zero-Shot Approach
This method provides the LLM with a complete snapshot of the game state in one go, enabling rapid decision-making. It involves a single, comprehensive call to the LLM, delivering all relevant information—current state, inventory, player stats, and recent actions. This approach is straightforward and efficient for quick decisions. However, it can be limiting if the game state becomes too complex or exceeds the LLM’s token limit.

Agentic Approach
The agentic method allows for more nuanced decisions by querying specific pieces of information. Using LangChain, the AI can access various “books” of data before making a decision. This approach helps handle complex scenarios and large game states by focusing on relevant details. It also offers a more refined decision-making process.

Choosing the Right Approach
The choice between zero-shot and agentic methods is made via configuration settings, providing flexibility for different scenarios. Zero-shot is faster and simpler, ideal for straightforward decisions. The agentic approach, though slower, excels in handling complex or large-scale situations.

By incorporating both methods, AI Castaway enhances decision-making capabilities. Additionally, these methods offer valuable insights into how different LLM strategies impact gameplay. This flexibility supports a range of scenarios, contributing to a more dynamic and engaging gaming experience.

Game Mechanics

AI Castaway features a complex set of game mechanics designed to challenge and engage the AI character. These mechanics create a dynamic survival environment that tests the LLM’s decision-making capabilities and fosters emergent gameplay.

Action List
The AI can perform 22 distinct actions. These range from basic survival tasks to complex crafting operations. They include:

  • Resource Gathering: “pick_sticks”, “pick_stones”
  • Survival Actions: “eat”, “drink”
  • Crafting: “craft_axe”, “craft_rope”
  • Construction: “build_shelter”, “build_raft”
  • Exploration: “explore”, “fish”

Each action has specific requirements and consequences. For instance, an axe is needed to ‘cut_wood,’ adding layers of strategic depth.

Resource Management
The inventory system tracks various resources:

  • Basic: sticks, stones
  • Crafted: axe, rope
  • Consumables: berries, fish
  • Advanced: iron, gold
  • Key Items: compass, sail

The dynamic inventory requires the AI to balance immediate needs with long-term crafting goals, such as deciding whether to use fibers for a rope or save them for future needs.

Survival Metrics
Four key metrics simulate survival challenges:

  • Health: Ranges from “Very Low” to “Very Good”
  • Hunger: Affects health over time
  • Thirst: Requires frequent attention
  • Stress: Impacts overall performance

These metrics are qualitative, requiring the AI to interpret and prioritize needs based on descriptive states. For example, “Very Low” health becomes the AI’s top priority, influencing decisions even if other needs are pressing.

Decision-Making Process
In AI Castaway, the decision-making process harnesses the LLM’s capabilities to create nuanced choices. The AI must navigate the interplay between actions, resource management, and survival metrics. It balances immediate survival with long-term goals. This design ensures that each decision impacts gameplay meaningfully, challenging the LLM’s reasoning and adaptability.

By integrating these elements, AI Castaway provides a rich, challenging environment. The AI character must constantly evaluate trade-offs and adapt to a changing game state.

How the LLM Processes Game State

Before each decision, the LLM receives a comprehensive snapshot of the game state, including:

  • Inventory Levels
  • Survival Metrics: Health, hunger, thirst, stress
  • Available Actions
  • Recent Action History
  • Current Objectives
  • Environmental Information

This snapshot is formatted into a structured prompt that provides context while allowing flexibility in decision-making. For example:

“You are an AI survivor on a remote island. Your current state is [inventory and survival metrics]. Recent actions were [action history]. Your objectives are [current objectives]. What is your next action and why?”

The LLM uses this prompt to analyze the relationships between game elements, weighing factors such as:

  • Urgency of survival needs
  • Action feasibility based on inventory
  • Progress towards objectives
  • Potential consequences of actions

The LLM then outputs a structured response with the chosen action and a brief explanation. This explanation offers insight into the AI’s decision-making, enhancing transparency and player engagement.

Is AI Any Good at Surviving?

I conducted testing to evaluate the performance of various LLMs within the game environment. This analysis provided insights into the capabilities of different models. It also highlighted their limitations in complex, dynamic decision-making scenarios.

Comparison of Different LLM Models

I evaluated several LLMs including GPT-4, LLaMA3-8B-8192, LLaMA3-70B-8192, Mixtral-8x7B-32768, and Gemma-7B-IT, based on their performance in AI Castaway. Here’s a summary of the findings:

  • LLaMA3-8B-8192 & LLaMA3-70B-8192: These models provided solid decision-making for resource gathering, crafting, and exploration. However, they struggled with sudden changes and unexpected challenges.
  • Mixtral-8x7B-32768: Excelled at initial resource gathering and basic survival setup but often got stuck in repetitive action loops. This led to inefficiencies.
  • Gemma-7B-IT: Performed well during initial setup but frequently produced incorrect actions. This caused inefficiencies in advancing through the game.

GPT-4 emerged as the standout performer, showing:

  • Balanced Decision-Making: Effectively managed both short-term survival and long-term goals.
  • Proficient Resource Management: Maintained a stable supply of essential items.
  • Successful Objective Completion: Built a raft and escaped the island, demonstrating strong multi-step planning.
  • Adaptability: Responded well to changing conditions and new challenges.

GPT-4’s superior performance is due to its advanced architecture and training, enabling it to navigate complex scenarios more effectively. However, it also demands higher computational resources, presenting a trade-off between performance and cost.

These insights offer valuable lessons for integrating AI into dynamic gaming environments. Special emphasis is placed on choosing the right model and fine-tuning it for specific applications.

Conclusion: AI’s Place in the Gaming World Future

Could we send a group to a remote island and have them blindly follow AI instructions to survive? If so, we might be able to make gaming less predictable. This could offer a tailored experience for each player, with replayable games featuring deep narrative complexity.

The future of gaming is full of promise, including possibilities such as: 

  • Emergent Narratives: Unique, personalized storylines for each playthrough, leading to infinitely replayable games.
  • Adaptive Difficulty: AI opponents that adjust strategies and skill levels based on player performance.
  • Procedural Content Generation: On-the-fly creation of dialogue, quests, and levels, enhancing game longevity and reducing development costs.
  • Natural Language Interfaces: More sophisticated interactions with NPCs for a more immersive, human-like experience.
  • Engaging AI Companions: Context-aware AI companions that adapt to a player’s style and choices.

I invite the development community to join me in exploring these frontiers. Let’s push the boundaries of interactive entertainment and unlock the next level of AI-powered gaming together. 

Danilo Vaccalluzzo

By Danilo Vaccalluzzo

As Senior Director of AI and SEO at BairesDev, Danilo Vaccalluzzo leads the development of AI systems to innovate and automate processes within the company. Danilo integrates advanced technologies to streamline operations and boost customer engagement. Danilo's expertise in AI and digital marketing helps drive significant growth and business outcomes.

Stay up to dateBusiness, technology, and innovation insights.Written by experts. Delivered weekly.

Related articles

Innovation - The Future of
Innovation

By BairesDev Editorial Team

4 min read

Contact BairesDev
By continuing to use this site, you agree to our cookie policy and privacy policy.