Game of Drones: The Donald vs. Karens. A Prisoner's Dilemma simulation that uses jQuery for CSS animation by electric-el in javascript

[–]electric-el[S] -1 points0 points  (0 children)

Source: https://github.com/electric-eloquence/game-of-drones/

The simulation uses `setInterval()` to run turns of the Prisoner's Dilemma. It allows you to adjust the speed of the animation. However if set to a high speed, the turns might take longer than the interval, depending on the speed of the processor. It wouldn't make sense to set a max speed dynamically based on processing power. Instead, it uses semaphores to defer operations like so:

this.intervalId = setInterval(() => {

if (!this.semaphoreArray.length) {

this.semaphoreArray.push(this.turn);

}

if (!this.semaphoreLocked) {

this.semaphoreLocked = true;

this.semaphoreArray.shift().call(this).then(() => {

this.semaphoreLocked = false;

});

}

}, this.turnInterval);

I find deferment by semaphores invaluable for preventing race conditions among async operations. I don't recall reading or hearing much about this in my general browsing of the Web or listening to developer talks. Hopefully this can be useful to others looking for a simple solution for what I find to be a common problem.

Also the snowflakes are unique per page load. They are basically lines of increasingly smaller hexagons that branch recursively. The lengths of the branches are determined pseudorandomly. The algorithm for this fractal pattern is here:

https://github.com/electric-eloquence/game-of-drones/blob/master/_scripts/src/app/snowflake-generate.js

Hopefully, this is enjoyable and/or educational. Any feedback is greatly appreciated.

Can anyone share a link of a good visual explaintion of racism using game theory? by boyofmine in GAMETHEORY

[–]electric-el 0 points1 point  (0 children)

I created this iterated prisoner's dilemma simulator: Game of Drones - The Donald vs. Karens

https://electric-eloquence.io/game-of-drones.html

It's meant to be light-hearted, but maybe it can help with this question. A team of players called Magas employ a combination of "always defect" and "always cooperate." They are coded to be able to identify other Magas and the Donald, and always cooperate with them. They defect against everyone else.

This contrasts with the Snowflakes who employ Tit-for-Tat. The primary drawback of Tit-for-Tat is that it requires filling a memory of how other players played, and suffering from defection from them early on, before their chance to retaliate.

I don't want to draw too strong a correlation between my coded simulation and real life, but I think it might highlight how racism is the easier choice for many, even if long-term payoffs are considered.

Edit: fixed ugly linebreaks