Answers.Body: <p>Most OpenAI gym environments are thin wrappers around existing games and libraries. You could do the same with your game. See e.g. <a href="https://towardsdatascience.com/beginners-guide-to-custom-environments-in-openai-s-gym-989371673952" rel="nofollow noreferrer">https://towardsdatascience.com/beginners-guide-to-custom-environments-in-openai-s-gym-989371673952</a> for a tutorial. There are many others, you can search &quot;open ai gym custom environment&quot; for more</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-07-29T12:34:16.890Z
Answers.Text: Thanks for the reply! I've read it and tried creating my environment but I'm still stuck when it comes to how to model the custom environment as it is somewhat complex. 
  Would it be possible to use my PyTorch DQN and prepare the data it needs on my own and calculate a reward? And not use the Gym Framework at all? Since my code already does simulate games.
Answers.UserDisplayName: monkey_ball
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-07-29T16:24:35.460Z
Answers.Text: You don't have to use the provided wrappers, or follow Gym's API exactly, but you take more risks with incompatibility or making a mistake. If you know what you are doing, it's fine to connect your environment direct to the DQN agent though.
Answers.UserDisplayName: Neil Slater
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-07-29T10:11:37.320Z
Answers.LastActivityDate: 2021-07-29T10:11:37.320Z
Answers.UserDisplayName: Neil Slater
Body: <p>In a project for college I created a simple turn based game, with up to 4 players that can either move or attack the opponents. The players are playing over the network, meaning the clients are supposed to be programmed AIs. The client itself is fully functional, meaning it has all the game logic and can simulate complete games.</p>
  <p>Now my task is to create a RL-Agent with a Deeq-Q-Network that learns to play the game. However, I don't really find any source to how that should be done. I was able to create an Agent with a DQN for the <code>CartPole</code> environment of OpenAI gym with PyTorch. Now my guess would be to create my own environment with the gym framework, but since the game itself is already implemented I was thinking if it was possible to feed data in the DQN without having to create the gym environment. As a <code>state</code> it would get the gamestate (which is a 2d grid, with information about the players and their remaining hitpoints) and all the possible moves in the current state as the <code>action space</code>. And since the game is network based, it would save the network after each game and reload it when the next starts during the training. For the training I would start the games over and over with a script and let it train for a while.</p>
  <p>As I'm quite new to Machine Learning it seems really blurry as of how to tackle this problem and was hoping to get led in some direction on how to start.</p>
  
Tags: <reinforcement-learning><dqn><environment>
Title: Creating DQN Learning Agent without Gym environment for a custom project
UserDisplayName: monkey_ball
ThreadText: # Creating DQN Learning Agent without Gym environment for a custom project
  
  (Asked by: username_0 on 2021-07-29)
  
  In a project for college I created a simple turn based game, with up to 4 players that can either move or attack the opponents. The players are playing over the network, meaning the clients are supposed to be programmed AIs. The client itself is fully functional, meaning it has all the game logic and can simulate complete games.
  
  Now my task is to create a RL-Agent with a Deeq-Q-Network that learns to play the game. However, I don't really find any source to how that should be done. I was able to create an Agent with a DQN for the `CartPole` environment of OpenAI gym with PyTorch. Now my guess would be to create my own environment with the gym framework, but since the game itself is already implemented I was thinking if it was possible to feed data in the DQN without having to create the gym environment. As a `state` it would get the gamestate (which is a 2d grid, with information about the players and their remaining hitpoints) and all the possible moves in the current state as the `action space`. And since the game is network based, it would save the network after each game and reload it when the next starts during the training. For the training I would start the games over and over with a script and let it train for a while.
  
  As I'm quite new to Machine Learning it seems really blurry as of how to tackle this problem and was hoping to get led in some direction on how to start.
  
  **Tags:** reinforcement-learning, dqn, environment
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2021-07-29. Score: 1
  
  Most OpenAI gym environments are thin wrappers around existing games and libraries. You could do the same with your game. See e.g. <https://towardsdatascience.com/beginners-guide-to-custom-environments-in-openai-s-gym-989371673952> for a tutorial. There are many others, you can search "open ai gym custom environment" for more
  
  > **Comments:**
  > **username_0**: Thanks for the reply! I've read it and tried creating my environment but I'm still stuck when it comes to how to model the custom environment as it is somewhat complex.  Would it be possible to use my PyTorch DQN and prepare the data it needs on my own and calculate a reward? And not use the Gym Framework at all? Since my code already does simulate games.  
  > **username_1**: You don't have to use the provided wrappers, or follow Gym's API exactly, but you take more risks with incompatibility or making a mistake. If you know what you are doing, it's fine to connect your environment direct to the DQN agent though.  
  
  ---
  
  