🕹️ The Program That Played Pong With Itself: When Code Starts to Game
“At what point does a game stop being fun… and start becoming philosophy?”
🕹️ The Program That Played Pong With Itself: When Code Starts to Game

“At what point does a game stop being fun… and start becoming philosophy?”
Pong. The OG of arcade games. Simple? Sure. But what if I told you that Pong can play itself? No humans. Just code. And no machine learning either.
Just raw logic. AI vs. AI. And somehow… it’s weirdly entertaining to watch.
🧪 The Challenge: Can We Make Pong Self-Playing?
We’ve all seen classic Pong clones: A ball bouncing around, two paddles, player vs. player, or player vs. computer.
But here’s the twist: What if we wrote a Pong game where both paddles are controlled by the program itself?
Not just automatic — but competitive. Two AIs locked in eternal gameplay.
🧬 A Minimal Self-Playing Pong in JavaScript
Let’s peek into the logic behind a self-playing Pong, written in under 100 lines of JavaScript + HTML.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>The Program That Played Pong With Itself</title>
<style>
body {
margin: 0;
background: #000;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
canvas {
background: radial-gradient(circle at center, #111 0%, #000 100%);
box-shadow: 0 0 30px #0ff;
border: 2px solid #0ff;
}
</style>
</head>
<body>
<canvas id="pong" width="600" height="400"></canvas>
<script>
const canvas = document.getElementById("pong");
const ctx = canvas.getContext("2d");
let ball = { x: 300, y: 200, vx: 3, vy: 2, r: 10 };
let left = { y: 160 }, right = { y: 160 };
function draw() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Draw paddles with glow
ctx.fillStyle = "#0ff";
ctx.shadowColor = "#0ff";
ctx.shadowBlur = 20;
ctx.fillRect(20, left.y, 10, 80);
ctx.fillRect(570, right.y, 10, 80);
// Draw ball with glow
ctx.beginPath();
ctx.arc(ball.x, ball.y, ball.r, 0, Math.PI * 2);
ctx.fill();
// Reset shadow for next frame
ctx.shadowBlur = 0;
}
function update() {
ball.x += ball.vx;
ball.y += ball.vy;
// Bounce top/bottom
if (ball.y < ball.r || ball.y > canvas.height - ball.r) ball.vy *= -1;
// AI paddle tracking
left.y += (ball.y - (left.y + 40)) * 0.08;
right.y += (ball.y - (right.y + 40)) * 0.08;
// Collision
if (ball.x < 30 && ball.y > left.y && ball.y < left.y + 80) ball.vx *= -1;
if (ball.x > 560 && ball.y > right.y && ball.y < right.y + 80) ball.vx *= -1;
// Reset if out of bounds
if (ball.x < 0 || ball.x > canvas.width) {
ball.x = canvas.width / 2;
ball.y = canvas.height / 2;
ball.vx *= -1;
}
}
function loop() {
update();
draw();
requestAnimationFrame(loop);
}
loop();
</script>
</body>
</html>
✅ This runs right in the browser. ✅ Both paddles follow the ball. ✅ You watch forever. Hypnotized.
🤖 The AI: Dumb But Smart Enough
The AI here isn’t really “thinking.” It just moves the paddles toward the ball with a delay factor. But it works. It’s…
- Predictable
- Smooth
- Balanced
And that’s the beauty: no ML, no neural nets — just code.
🎭 Why Is This So Fascinating?
- It’s a simulation of competition without players.
- It blurs the line between game and self-contained loop.
- It’s strangely soothing, like digital meditation.
You’re watching logic bounce around inside its own little universe. And somehow, it feels alive.
💡 What You Can Try Next:
- Add a scoreboard to count infinite wins
- Make one paddle smarter than the other
- Introduce chaos (random spin, gravity)
- Convert it to Python using
pygame - Or… let one side slowly learn with reinforcement logic
🚀 Final Thoughts
We often think of code as tools, functions, actions. But sometimes… it’s just existence. This little Pong game doesn’t do anything. It just is. And maybe that’s the point.
Build it. Run it. Let it play. And let it remind you that sometimes, watching is more fun than winning.
👏 Enjoyed this strange but satisfying article? Clap it, share it, and challenge someone to one-up your Pong AI!
메타데이터
- post_id
- c55c8b56ebda
- slug
- ️-the-program-that-played-pong-with-itself-when-code-starts-to-game-c55c8b56ebda
- url
- https://medium.com/@Daiyan-2004/%EF%B8%8F-the-program-that-played-pong-with-itself-when-code-starts-to-game-c55c8b56ebda
- canonical_url
- https://medium.com/@Daiyan-2004/%EF%B8%8F-the-program-that-played-pong-with-itself-when-code-starts-to-game-c55c8b56ebda
- author_url
- https://medium.com/@Daiyan-2004
- status
- ok
- fetched_at
- 2026-07-07 04:24:22