Are you ready to dive into the world of Honor of Kings through AI? In this article, we’ll explore how to set up and run your very own AI for this popular game using the newly available 3v3 mode. Let’s get started!
Introduction to Hok_env
The Hok_env is an open environment specifically designed for the Honor of Kings game. This environment provides a reinforcement learning training framework that allows developers to interact with the game core and build intelligent agents that can compete in a dynamic, multi-agent setting.
Requirements
- Python: 3.6 or 3.9
- Operating System: Windows 10/11 or Linux (with WSL 2 for Windows users)
- Docker: Required for deploying Hok_env on Linux containers
Setting Up Hok_env
Before you start, make sure you have all requirements in place. Here’s a simple step-by-step walkthrough:
1. Download the Game Core
First, you need to obtain the game core:
- Apply for the license and game core at this link.
- Place the
license.datfile underhok_env_gamecore/gamecore/core_assets.
2. Test the Game Core
Open CMD and navigate to the game core binaries:
cd gamecore/bin
set PATH=%PATH%;..\\lib
sgame_simulator_remote_zmq.exe sgame_simulator.common.conf
If you see a successful initiation message, congratulations! Your game core is up and running.
Running the 3v3 Mode
To connect to the Honor of Kings AI environment in 3v3 mode, follow these instructions:
GC_SERVER_ADDR = os.getenv(GAMECORE_SERVER_ADDR, "127.0.0.1:23432")
AI_SERVER_ADDR = os.getenv(AI_SERVER_ADDR, "127.0.0.1")
reward_config = RewardConfig.default_reward_config.copy()
env = get_hok3v3(GC_SERVER_ADDR, AI_SERVER_ADDR, reward_config)
3. Reset the Environment
Now, reset your environment and start a new game:
use_common_ai = [True, False]
camp_config = {
"mode": "3v3",
"heroes": [
[{"hero_id": 190}, {"hero_id": 173}, {"hero_id": 117}],
[{"hero_id": 141}, {"hero_id": 111}, {"hero_id": 107}]
]
}
env.reset(use_common_ai, camp_config, eval_mode=True)
4. Implement Game Loop
Here’s where the action happens! Use the following code to implement a loop for your game:
gameover = False
while not gameover:
for i, is_common_ai in enumerate(use_common_ai):
if is_common_ai:
continue
continue_process, features, frame_state = env.step_feature(i)
gameover = frame_state.gameover
if not continue_process:
continue
probs = random_predict(features, frame_state)
ok, results = env.step_action(i, probs, features, frame_state)
if not ok:
raise Exception("Step action failed")
env.close_game(force=True)
Think of this code as a team of three friends coordinating a heist. Each friend has their role: some execute actions stealthily while others (the AI) keep watch and make sure everything is under control. The game loop continues until the mission (game) is complete!
Troubleshooting
Here are some common issues you might encounter along the way:
- Ensure that the game core server is running on the correct address (127.0.0.1:23432).
- If your script fails, double-check your Python version and dependencies.
- Review your configuration settings in the
config.jsonfile.
For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.
Conclusion
Now you’re equipped to experiment with the Honor of Kings AI Open Environment! The potential for innovation in AI within competitive gaming is immense, and with the right tools, your AI agents can mimic the strategies of actual players.
At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.
