Developing Advanced AI and Innovative Gameplay Mechanics for a YU-GI-OH-Inspired Turn-Based Card Game: Overcoming Current Limitations with Unreal Engine 5 and C++
Project Overview
This project focused on developing a turn-based card game with AI-driven gameplay mechanics inspired by Yu-Gi-Oh!, utilizing Unreal Engine 5 and C++. The aim was to create a strategic, engaging game environment where the AI opponent employs sophisticated decision-making processes, bringing a dynamic and competitive experience for players. The primary objectives included implementing complex AI algorithms (Alpha-Beta Pruning and Monte Carlo Tree Search) and innovating on gameplay mechanics to introduce unpredictability and adaptability in the AI’s behaviour.
Development Workflow
The development process involved a structured approach that covered prototyping, C++ optimization, and AI system implementation:
- Prototyping with Blueprints: Initial gameplay features and mechanics were prototyped using Unreal Engine's Blueprints for rapid iteration.
- Optimization with C++: To enhance performance, core systems were optimized and transferred to C++.
- Gameplay Ability System (GAS): Unreal’s GAS framework was utilized to streamline ability-based actions.
- AI Implementation: Detailed behaviour trees, Alpha-Beta Pruning, and Monte Carlo Tree Search (MCTS) algorithms were incorporated for strategic decision-making.
- Testing and Evaluation: The completed AI and gameplay systems were converted into an executable for testing and fine-tuning.
Core Components
1. Behaviour Tree Setup
- Overview: The AI’s decision-making structure was created using a behaviour tree. This hierarchical model organizes the AI’s actions based on different game phases (draw, main, and battle).
- Implementation: Behaviour tree nodes handled various gameplay mechanics, allowing the AI to follow a structured decision-making path that simulated human-like planning. Actions, like playing cards or setting up attacks, are initiated based on turn phase and game state.
- Enhancements: 'Wait' nodes added natural pauses between actions, lending a more organic flow to the AI's moves and creating a less robotic, immersive gameplay experience.
2. Algorithm Implementation
- Alpha-Beta Pruning:
A/B Pruning Component Header Code
- Purpose: Addressed the need for a strategic depth where AI makes optimal choices despite imperfect information (i.e., hidden player cards).
- Process: Alpha-Beta Pruning enabled the AI to minimize losses or maximize gains by simulating and evaluating possible game states. I designed the
UAlphaBetaPruningComponent
to initiate decision-making in theChooseBestCard
function, which assessed moves based on depth and outcome maximization. - Evaluation: The
EvaluateBoardState
function factored in life points, card ranks, and positioning for scoring each possible game state, leading to adaptive and advantageous AI decisions.
- Monte Carlo Tree Search (MCTS):
- Purpose: Enhanced AI target and unit selection by simulating various scenarios to calculate probable outcomes.
- Process: The MCTS approach uses simulation-based decision-making where each node represents a potential game state following a move. The AI balances exploration and exploitation through iterative simulations, applying the UCB1 (Upper Confidence Bound) formula for optimal node selection.
- Optimization: By adjusting simulation depth and number, I ensured efficient performance while maintaining decision accuracy, especially in complex board states.
Gameplay Mechanics and Usability Enhancements
1. Card and Unit Selection Variants
- Players can select different AI algorithms (Random, Alpha-Beta Pruning, or MCTS) for both card and unit selection, customizing the AI’s approach.
- Impacts on Strategy: The choice of algorithms affects AI predictability, making the game experience variable. For example, MCTS combined with Alpha-Beta Pruning adds depth by combining long-term planning with immediate adaptability.
2. Gameplay Phases
- Draw Phase: The AI and player draw new cards each turn.
- Main Phase: Decisions about card positioning, effects, and setup for the next turn.
- Battle Phase: AI assesses risk and reward to select opponents and execute combat actions.
3. Interactive UI and Game Selectors
- I implemented UI elements to guide players in selecting AI strategies, ensuring a smooth onboarding experience. Options allow switching between algorithmic strategies easily, while pop-ups and gameplay tips help clarify complex mechanics.
Challenges and Solutions
- Challenge: Implementing Alpha-Beta Pruning with Hidden Information
- Solution: To address unknown player hands, the AI generates simulated hands by shuffling remaining deck cards. This allowed the AI to adapt its strategies even without full information, leading to balanced gameplay.
- Challenge: Managing Game Complexity with MCTS
- Solution: By setting constraints on simulation depth and number, I optimized MCTS performance, allowing AI to analyse possible moves without impacting gameplay speed.
- Challenge: Integrating Realistic AI Behaviour
- Solution: Wait nodes within the behaviour tree added pacing to the AI’s actions, while custom evaluation functions ensured that moves align with overall game balance.
Technical Results and Evaluation
- Algorithmic Effectiveness: Through iterative testing, both Alpha-Beta Pruning and MCTS demonstrated effectiveness in creating a challenging, responsive AI opponent. The Alpha-Beta Pruning algorithm excelled at high-level strategic card selection, while MCTS was effective in unit and target prioritization, both increasing gameplay depth.
- Performance Optimizations: The shift from Blueprint to C++ significantly improved frame rate and responsiveness, particularly in complex game states involving multiple AI-driven characters and large action trees.
- Usability Enhancements: A detailed UI and interactive gameplay selectors streamlined player experience, while behaviour tree-driven actions added immersion through a realistic AI behaviour sequence.
Reflections and Future Work
This project illustrated the importance of integrating and balancing strategic decision-making algorithms for engaging AI gameplay. The use of Alpha-Beta Pruning and MCTS not only added complexity but also allowed for dynamic adaptation to player actions, creating an AI that feels both challenging and fair. Future improvements could include extending MCTS for card selection and Alpha-Beta Pruning for unit selection, as well as expanding the AI’s behaviour tree to support more complex in-game scenarios, such as armour, critical health, and special unit abilities.
Conclusion
Developing this project provided valuable insights into advanced AI planning, turn-based mechanics, and the application of decision-making algorithms within Unreal Engine 5. By achieving a balance between predictability and randomness, the game AI remains both challenging and engaging, reflecting real-world applications of game theory and AI strategies. This project highlights the potential of combining AI algorithms in complex gameplay scenarios and underscores the importance of adaptability and innovation in game AI development.
Leave a comment
Log in with itch.io to leave a comment.