[KongchangAI]
· 3 min read· 1,657 words

Local DQN Learns Super Mario Bros in Real Time from Pixels: A Deep Reinforcement Learning Practice from Pixels to Level Completion

Local DQN Learns Super Mario Bros in Real Time from Pixels: A Deep Reinforcement Learning Practice from Pixels to Level Completion

Developer runs DQN locally, learning Super Mario from pixels with real-time livestreaming, showing RL practice and challenges.

A developer shared a locally running DQN project on Reddit, where the agent learns to play Super Mario Bros from raw game pixels, trained entirely on a single machine and livestreamed in real time. The project uses two stacked 112×128 grayscale images as input, directly outputs button actions, and combines forward progress, score, stagnation/backward/death penalties, and level-completion bonuses in its reward function, which was recently sharpened. Training is still early, and the agent has not yet consistently cleared 1-1. The project illustrates challenges such as high-dimensional input, sparse rewards, and long-horizon decision-making in learning from pixels, and demonstrates the value of livestreaming for observing the learning process, providing a reference practice framework for reinforcement learning enthusiasts.

A developer shared a locally running DQN (Deep Q-Network) project on Reddit, where the agent is learning to play Super Mario Bros from raw game pixels, with the entire training process livestreamed on YouTube in real time. The whole process runs on a single machine without any paid API calls. This project demonstrates a pure, transparent practice of deep reinforcement learning in a classic game environment, and has sparked discussions about training efficiency, reward design, and the challenges of "learning from pixels."

reddit source: Local DQN learning Super Mario Bros from pixels, livestreamed in real time

System Architecture: Single-Machine Operation, from Pixels to Actions

According to the author, the entire learning system runs on a local machine. The agent receives two stacked grayscale frames as input, with a resolution of 112×128 and a frame rate of approximately 30 per second. It must directly select button actions from these pixels — a typical setup for "learning from pixels": with no handcrafted game state features, the agent must understand Mario's position, enemies, terrain, and other information from the raw screen on its own.

This setup places high demands on computational resources and algorithm efficiency. The author emphasizes "no paid API calls," meaning all training and inference are done on local hardware, which reduces costs and makes the entire learning process more controllable and reproducible. The two-frame stacking design is intended to let the agent perceive motion information, such as Mario's movement direction and the approaching speed of enemies — a common approach for handling partially observable environments.

Frame Stacking is a common technique in deep reinforcement learning for handling partially observable environments. In games like Super Mario Bros, a single frame cannot provide motion information (such as Mario's movement direction or the approaching speed of enemies), because a static image only contains position information. By stacking consecutive frames (e.g., two or four) of grayscale images as input, the agent can implicitly perceive temporal differences and thus infer dynamic features such as velocity and acceleration. This approach was first adopted in the original DQN Atari experiments (which stacked 4 frames) and has been proven crucial for learning performance. The cost of frame stacking is an increase in input dimensionality and computation, so a trade-off between information and efficiency is needed.

Reward Design: The Key to Shaping Behavior

The reward function is the core of reinforcement learning. In this project, the author designed a composite reward: forward progress and score serve as positive signals, while stagnation, backward movement, and death incur penalties, and completing a level grants an additional bonus. This design attempts to guide the agent toward the basic strategy of "move right and avoid death" while encouraging it to complete levels.

Reward shaping is especially important in games like Super Mario Bros. Relying solely on game score is often too sparse, and the agent struggles to discover effective behaviors through early exploration. Introducing forward progress as a dense reward can accelerate learning. However, reward design can also introduce unintended behaviors — for example, the agent might learn to repeatedly farm points in one area without progressing, or become overly conservative to avoid death penalties. The author did not disclose the specific reward weights but stated that "the visuals and rewards were recently sharpened," meaning the reward function was adjusted to make signals clearer, and learning was therefore restarted.

Reward Shaping is a technique in reinforcement learning that guides agent learning by designing intermediate reward signals. In sparse-reward environments (where game scores are only given at specific events), the agent struggles to obtain effective feedback through random exploration. Reward shaping accelerates learning by introducing dense auxiliary rewards (such as forward distance or survival time), but it can also introduce bias, causing the agent to optimize auxiliary rewards rather than the final objective. Theoretically, reward shaping must guarantee that the optimal policy is unchanged (i.e., potential-based shaping), but this is often difficult to satisfy strictly in practice. The author's use of composite rewards with adjusted weights is precisely an attempt to find a balance between guiding learning and avoiding unintended behaviors.

Training Status: Not Yet Consistently Clearing 1-1

The author candidly states that this run is still in an early stage, and the agent "has not yet consistently cleared 1-1." This is not surprising — learning Mario directly from pixels is a challenging task for DQN. When handling high-dimensional visual input, DQN requires a large number of interaction samples and careful hyperparameter tuning. In addition, the author recently adjusted the visuals and rewards, causing learning to "restart," which also explains why current performance is not yet ideal.

The livestreaming format lets viewers directly observe the agent's progression from random actions to gradually learning to move forward. This transparency is valuable for reinforcement learning research and education, because people often only see the final successful results and overlook the many intermediate failures and adjustments. In the post, the author invites viewers to ask questions, showing a willingness to share technical details and helping the community discuss problems together.

Technical Challenges and Potential Improvement Directions

The main difficulties of learning Mario from pixels include sparse rewards, long-horizon decision-making, and the complexity of visual input. DQN itself suffers from overestimation, which is usually mitigated through variants such as Double DQN and Dueling DQN. In addition, the stability of experience replay and the target network is crucial for training. The author did not mention whether these improvements were used, but given that this is a local project, a standard DQN implementation is likely.

Another noteworthy point is training efficiency. Training DQN from pixels on a single machine may take hours or even days before noticeable progress appears. Livestreaming lets viewers observe the learning curve, but it may also expose training instability. The author mentions that "the visuals and rewards were recently sharpened," suggesting possible adjustments to preprocessing steps (such as grayscaling, downsampling, and frame stacking) and reward scaling, all of which affect learning speed and final performance.

DQN's overestimation problem stems from the maximization operation in Q-learning: using the max operation when computing target Q-values leads to overestimated Q-values, which in turn affects policy stability. Double DQN mitigates this by decoupling action selection from action evaluation — using the current network to select actions and the target network to evaluate their values. Dueling DQN improves learning efficiency by decomposing Q-values into state value V and advantage function A. In addition, Prioritized Experience Replay improves sample utilization by sampling transitions with high TD error more frequently. These improvements are often combined in practice (e.g., Rainbow), but they increase implementation complexity. If the author did not adopt these techniques, standard DQN may converge slowly on complex visual tasks.

Multi-Source Perspectives: Community Feedback and Similar Projects

Although this project mainly comes from a single Reddit post, similar attempts at "learning Mario from pixels" are not uncommon in the reinforcement learning community. According to analyses from some YouTube channels and Bilibili creators, many enthusiasts reproduce Mario agents locally using algorithms such as DQN and PPO and encounter similar challenges: in the early stages of training, the agent tends to stand still or jump repeatedly, requiring carefully designed rewards and exploration strategies. Experiences from these independent sources corroborate the author's description, indicating that learning Mario from pixels is a process requiring patience and iteration.

Some also believe that more advanced algorithms (such as Rainbow DQN or distributed reinforcement learning) can significantly improve sample efficiency, but at the cost of higher implementation complexity. The author's choice of standard DQN may be motivated by simplicity and interpretability. In any case, the livestreaming format provides a unique window into observing the learning process.

Rainbow DQN is an algorithm proposed by DeepMind in 2017 that integrates multiple DQN improvements, combining Double DQN, Dueling DQN, prioritized experience replay, multi-step returns, distributed Q-learning (C51), and noisy networks. On the Atari benchmark, Rainbow significantly surpasses the original DQN in sample efficiency and final performance. However, its implementation complexity is higher, with more components requiring tuning, and it may not be lightweight enough for a local single-machine project. Distributed reinforcement learning (such as C51) provides richer learning signals by modeling the return distribution rather than the expected value, but with greater computational overhead. The author's choice of standard DQN may be a trade-off among simplicity, interpretability, and training efficiency.

Conclusion and Outlook

This local DQN project is a solid reinforcement learning practice that fully exposes the training process to viewers, reflecting the spirit of open source and sharing. Although the agent has not yet consistently cleared 1-1, the author's adjustments to rewards and visuals show active iteration. For developers wanting to get started with deep reinforcement learning, this project provides a reference framework: from pixel input, frame stacking, and reward design to real-time monitoring, every step offers something to learn. In the future, if the author introduces techniques such as Double DQN and prioritized experience replay, or increases training time, the agent's performance is expected to improve further.

You can watch the real-time learning process via the YouTube link provided by the author and ask questions directly in the post.

One-line Summary

A developer runs DQN locally, learning to play Super Mario from pixels with real-time livestreaming, demonstrating RL practice and challenges.

Paragraph Summary

A developer shared a locally running DQN project on Reddit, where the agent learns to play Super Mario Bros from raw game pixels, trained entirely on a single machine and livestreamed in real time. The project uses two stacked 112×128 grayscale images as input, directly outputs button actions, and combines forward progress, score, stagnation/backward/death penalties, and level-completion bonuses in its reward function, which was recently sharpened. Training is still early, and the agent has not yet consistently cleared 1-1. The project illustrates challenges such as high-dimensional input, sparse rewards, and long-horizon decision-making in learning from pixels, and demonstrates the value of livestreaming for observing the learning process, providing a reference practice framework for reinforcement learning enthusiasts.

#DQN#Super Mario Bros#deep reinforcement learning#learning from pixels#livestream training
Share:

Related articles