Red Blob Games

RSS: https://www.redblobgames.com/blog/posts.xml
数学和算法的交互式教程

英语里 a 和 an 到底怎么选

Red Blob Games 从程序生成文本的实际需求出发,讨论英语不定冠词 a/an 的判定规则:关键不是首字母是否是元音字母,而是发音是否以元音音素开头。 例如 unicorn 虽是 u 开头却读 Y 音应用 a,hour 虽是 h 开头却读 OW 音应用 an。作者花一天时间分析数据并做可视化,发现 32455 个词里只有 129 个需要特殊处理,结果比他预想的简单很多。 文中还附了一段对 LLM 写代码的反思:这类一次性问题其实更适合直接用 LLM 写正确但不追求可维护性的代码,自己在解析 cmudict 和重学 D3.js 上花了太多时间。 属于偏语言处理/编程趣味的个人向短文,信息密度中等,适合 HN 风格读者轻读并展开讨论“程序生成文本里这类语言规则怎么做”。
评论点赞收藏10 天前

十年磨一剑:我终于讲清楚了差分启发式算法

Google Maps 2007年就用了差分启发式算法实现拖拽路线实时重算,但这项技术的清晰解释一直找不到。Red Blob Games作者花了十年尝试写教程,最终用双向箭头可视化+交互式图表讲清楚了:启发式方向与正确方向越一致,A*搜索越快。 新教程页已上线。
评论点赞收藏51 天前

Improving Heuristics

用"地标节点+三角不等式"优化A寻路启发函数,可大幅减少搜索节点数。预计算各点到地标的距离后,A每次查询时用多个地标给出更紧的下界估计,从而跳过大量无效探索。 作者在Dragon Age、Cogmind等真实游戏地图上实测,搜索节点数从数千降至数百甚至十几。代码改动极小,只需改启发函数,A*核心逻辑不变。
评论点赞收藏52 天前

Differential heuristics: learning about a way to optimize the A* heuristic

Google Maps 2007年就用了差分启发式算法实现拖拽路线实时重算,但这项技术的清晰解释一直找不到。Red Blob Games作者花了十年尝试写教程,最终用双向箭头可视化+交互式图表讲清楚了:启发式方向与正确方向越一致,A*搜索越快。 新教程页已上线。
评论点赞收藏52 天前

用"地标法"优化A*寻路:三角不等式启发函数实战

用"地标节点+三角不等式"优化A寻路启发函数,可大幅减少搜索节点数。预计算各点到地标的距离后,A每次查询时用多个地标给出更紧的下界估计,从而跳过大量无效探索。 作者在Dragon Age、Cogmind等真实游戏地图上实测,搜索节点数从数千降至数百甚至十几。代码改动极小,只需改启发函数,A*核心逻辑不变。
评论点赞收藏64 天前

Responsive Design Calculator

A few weeks ago I got distracted when I discovered — to my horror — that occasionally the font size on my site was 1.24924375rem instead of the desired 1.25rem. Of course nobody would notice this. But...
评论点赞收藏78 天前

Academic citations

Although my site isn't designed to fit into the academic world, occasionally an academic paper will cite one of my pages. Everyone uses a different format. That got me wondering if there are is a prop...
评论点赞收藏150 天前

Highlighting Interactive Code Blocks

I have sample code on some of my pages. I try to use syntax highlighting when I can, but I don't use it everywhere. In particular, Hexagons guide and Terrain from Noise don't have syntax highlighting....
评论点赞收藏162 天前

Optimizing Page Size

When I started my web site, we didn't have static site generators or WordPress or GitHub Pages or much else. People wrote HTML1 by hand. Over the years, I've built my own setup to manage my site. My c...
评论点赞收藏181 天前

Writing a Guide to SDF Fonts

(TL;DR: this is a blog post about the process of writing my guide to SDF fonts.) Back in 2024 I learned about SDF (signed distance field) rendering of fonts. I was trying to implement outlines and sha...
评论点赞收藏214 天前

URLs with Trailing Punctuation

When a url is posted on a forum/chat, it's often automatically made linkable. But sometimes the regexp that grabs the url also grabs a trailing punctuation mark. For example, if the text is "visit red...
评论点赞收藏229 天前

What I Did in 2025

It's time for my annual self review. In last year's review I said I wanted to spend time learning things for myself, and less time writing for other people. The main themes for 2025 were: playing with...
评论点赞收藏272 天前

Goodbye SASS

My “site” is spread across five different servers. I use slightly different CSS on each one. Since 2013 I’ve been using Sass (SCSS) to manage the variants, using these features: Variables → available ...
评论点赞收藏276 天前

Rotmg Map Seeds

I had just wrapped up a project and wanted to do something small/fun before I started the next one. The Flash runtime is being reimplemented in Rust, and I've enjoyed re-enabling the Flash on my site....
评论点赞收藏283 天前

Mapgen4's Use of WebGL2

I try to avoid big software rewrites. But sometimes the rewrites are just an excuse to re-familiarize myself with the code. I rationalized rewriting Mapgen4's renderer by saying I wanted to use WebGL2...
评论点赞收藏348 天前

Mapgen4 River Shader

Back in 2018 I had the idea to prerender short segments of river bends and confluences into a texture, and then use that texture to draw the rivers to the screen. I was trying to have draw exactly one...
评论点赞收藏360 天前

Mapgen4 Renderer

It's been a while since I've worked on mapgen4 features. In 2018 I declared it finished. I then put it away and worked on other projects. Over the years I have updated the code (es6 modules, typescrip...
评论点赞收藏363 天前

Harnessing ChatGPT Hallucinations

The web server I use (nginx) logs errors to a file. I check this occasionally to make sure nothing's going wrong with my server. I typically get these kinds of 404 requests: typosthe url /pathfinding/...
评论点赞收藏372 天前

登录芦苇

登录后关注作者、收藏内容和参与讨论。