Skip to content

Instantly share code, notes, and snippets.

@tabatkins
Created May 21, 2021 01:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tabatkins/e85eb4d01f6c68547b0191e6e8035f14 to your computer and use it in GitHub Desktop.
Save tabatkins/e85eb4d01f6c68547b0191e6e8035f14 to your computer and use it in GitHub Desktop.
Unobfuscated version of HATETRIS's default AI
function construct(getNextStates) {
return function ai(currentState) {
const pieces = [
{name:"S", annoyance:7},
{name:"Z", annoyance:6},
{name:"O", annoyance:5},
{name:"I", annoyance:4},
{name:"L", annoyance:3},
{name:"J", annoyance:2},
{name:"T", annoyance:1},
];
for(const piece of pieces) {
const wellHeights = getNextStates(piece.name, currentState)
.map(getWellHeight);
piece.bestWellHeight = Math.min(...wellHeights);
}
// Find the piece that, at best, still gives the highest well height.
// Tie-break by selecting the most annoying piece.
pieces.sort((a,b)=>a.bestWellHeight - b.bestWellHeight || a.annoyance - b.annoyance);
return pieces[0].name;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment