• Townie
    AI
  • Blog
  • Docs
  • Pricing
  • We’re hiring!
Log inSign up
saolsen

saolsen

connect4_ai

Parallel connect4 bot in a webgpu compute shader.
Public
Like
connect4_ai
Home
Code
8
.vtignore
AGENTS.md
README.md
connect4_ai.js
connect4_ai.wgsl
deno.json
index.html
H
server.ts
Branches
1
Pull requests
Remixes
History
Environment variables
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Sign up now
Code
/
Code
/
Search
server.ts
https://saolsen--6cabdbd4b5d511f0a1d50224a6c84d84.web.val.run
README.md

connect4_ai

A parallel connect4 AI player written in a webgpu shader.

Does a minimax evaluation on the current game state, looking 8 moves ahead at all possible game states. Expands the tree out 3 levels which results in 343 game states, those are then each evaluated on a gpu thread to check 5 more moves ahead. All in all it looks at 5,764,801 different game states to make it's decision.

future work

Runs pretty quickly on an M series mac or on a computer with a good gpu. Can be kinda slow if you only have an integrated gpu and probably doesn't work at all on most phones. I basically just wrote it to work well on my computer, I could probably tune it to run better on the device it's loaded on.

I'm pretty new to gpu programming and I don't think this is really the best way to do this. The code is very branchy and it's likely that is slowing things down a lot. Ideally each gpu "thread" should run the same instructions since a thread in a gpu is really more like a simd lane. When the threads diverge I think you lose a lot of the throughput.

HTTP
  • server.ts
    saolsen--6cabdbd4b5d511f0a1d50224a6c84d84.web.val.run
Code
.vtignoreAGENTS.mdREADME.mdconnect4_ai.jsconnect4_ai.wgsldeno.jsonindex.html
H
server.ts
FeaturesVersion controlCode intelligenceCLI
Use cases
TeamsAI agentsSlackGTM
DocsShowcaseTemplatesNewestTrendingAPI examplesNPM packages
PricingNewsletterBlogAboutCareers
We’re hiring!
Brandhi@val.townStatus
X (Twitter)
Discord community
GitHub discussions
YouTube channel
Bluesky
Open Source Pledge
Terms of usePrivacy policyAbuse contact
© 2025 Val Town, Inc.