Color-blind-friendly colors in a one-button PSO game
I made a one-button game that teaches particle swarm optimization (PSO, a search method in which a group of agents shares its best position). Each step, the game draws three colored arrows next to the player's bird. These arrows show the PSO rule: the next move is the sum of "keep going", "my best spot" and "flock's best spot". The other birds follow this rule exactly, and the whole flock sometimes gets stuck at a trap, which is a local maximum of the smell. The player can then leave the flock, search other places and lead it to the real food.
The 10,000-character limit restricts the design, but I still wanted the game to work for color-blind players. Red-green color blindness is the most common type, and it affects up to 1 in 12 men (8 %) and 1 in 200 women (0.5 %) [Wikipedia]. People with this type often confuse red, brown, green and yellow. In my first version, the green "PSO says" target and the orange "flock's best" arrow could therefore look alike.
I followed three simple ideas from the same article:
- Avoid red-green pairs. The arrows now use light gray, sky blue and orange, and the "PSO says" target is white.
- Do not use color alone. Each marker also has its own shape: a ring, a star or a diamond.
- Use brightness. On the smell map, a brighter spot always means a stronger smell.
The smell map is one line:
set(ax,'Colormap',(.55:.01:1)'.^[2 1 4],'CLim',[0 1]) % green -> white
These changes cost almost no characters, because they mostly replace color values. I would welcome feedback from color-blind players.

*How different people may see the game (approximate views, made with the color-blindness model of Machado et al., IEEE Transactions on Visualization and Computer Graphics, 2009).*
2 Comments
Time DescendingWhat I really like about the implementation of your code is the PSO implementation, especially the velocity calculation in ps(). The three components combine inertia, personal best attraction, and global best attraction. The precision of subsequent magnitude constraint by calculating the resultant vector, deriving a scaling factor that caps its norm at 14, and apply that factor before assigning the updated velocity. This preserves the direction of the combined PSO movement while limiting its magnitude. Together with the fitness evaluation in sm() and the personal/global best updates, the code provides a clear, technically grounded demonstration of particle swarm optimization. Well done, Mohammad.
Sign in to participate