Reinforcement learning (RL) trains an agent through interaction: it observes a current environment state, chooses an action, receives a reward, and repeats. Actions that tend to yield higher accumulated rewards for a state become more valuable. Early behavior is often random exploration, making RL a trial-and-error approach rather than learning from labeled answers. section 11.1
The agent–environment loop makes the core units visible: state enters the agent, an action affects the environment, and reward evaluates that action. section 11.1.1
A common first implementation is Q-learning. A Q-table stores an estimated quality for every state–action pair. During training, the agent sometimes selects the table’s best action and sometimes samples a random action; after each environment step, it updates the selected table entry using the immediate reward and the best estimated value of the next state. Exploration decreases over episodes through epsilon decay. section 11.1.1
Frozen lake Q-learning agent
In a 4-by-4 frozen-lake environment, an agent moves up, down, left, or right. Reaching the bottom-right goal earns a reward; falling through a hole ends the episode with a negative reward. A runnable setup creates the Gym environment, initializes a zero Q-table, sets episode, learning-rate, discount, and epsilon parameters, trains over episodes, then plays using each state’s highest-valued action. section 11.1.1
A practical RL workflow is:
- Inspect the environment’s observation/state space and action space before defining the agent. section 11.1.1 section 11.2.1
- Run episodes that reset the environment, choose an action, step the environment, collect reward, and stop when done. section 11.1.1
- Evaluate the learned policy separately by selecting the highest-valued action rather than random exploration. section 11.1.1
- Experiment with other Gym environments, beginning with random play to understand their behavior. section 11.2.1
Rewards can also evaluate agents without being the mechanism that learns from them. In a NEAT setup, a network receives an observation and outputs action scores; accumulated rewards become genome fitness, and evolution selects higher-fitness genomes. That uses RL-style environments and reward-based evaluation, but the underlying optimizer is evolution rather than RL. Deep Q-learning is another extension, replacing a Q-table or policy with deep learning for more complex environments such as lunar lander. section 11.3 section 11.6
Trial-and-error exploration can be costly: solving a problem may require millions of actions. This limitation motivates looking beyond derived reward equations toward approaches such as evolutionary learning, while retaining environments as controlled places to test decision-making agents. section 11.1 section 11.2.1

















