Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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