Skip to content

Instantly share code, notes, and snippets.

@citrus610
Last active July 21, 2025 19:50
Show Gist options
  • Select an option

  • Save citrus610/83b0dd4d35b35a81505b609e9a536841 to your computer and use it in GitHub Desktop.

Select an option

Save citrus610/83b0dd4d35b35a81505b609e9a536841 to your computer and use it in GitHub Desktop.
Modern puyo games' queue generator (Confirmed on Puyo Puyo Champions and Puyo Puyo Tetris 2)
std::vector<Cell::Type> get_queue(u32 seed)
{
// Modern puyo games' internal random number generator
auto rng = [&] () -> u32 {
seed = (seed * u32(0x5D588B65) + u32(0x269EC3)) & u32(0xFFFFFFFF);
return seed;
};
// Choose which colors to use
// We only care about the number of time that the rng() function is called, since the color orientation isn't important
// TLDR: Don't care about this, it's just here
for (i32 i = 0; i < 5; ++i) {
rng();
}
// Initialize queue
// There are 3 modes of queue: 3 colors, 4 colors and 5 colors
u8 queue[3][256] = { 0 };
for (i32 mode = 0; mode < 3; ++mode) {
for (i32 i = 0; i < 256; ++i) {
queue[mode][i] = i % (mode + 3);
}
}
// Shuffle the queues (all 3 modes)
for (i32 mode = 0; mode < 3; ++mode) {
// 1st shuffle
for (i32 col = 0; col < 15; ++col) {
for (i32 i = 0; i < 8; ++i) {
i32 n1 = (rng() >> 28) + col * 16;
i32 n2 = (rng() >> 28) + (col + 1) * 16;
std::swap(queue[mode][n1], queue[mode][n2]);
}
}
// 2nd shuffle
for (i32 col = 0; col < 7; ++col) {
for (i32 i = 0; i < 16; ++i) {
i32 n1 = (rng() >> 27) + col * 32;
i32 n2 = (rng() >> 27) + (col + 1) * 32;
std::swap(queue[mode][n1], queue[mode][n2]);
}
}
// 3rd shuffle
for (i32 col = 0; col < 3; ++col) {
for (i32 i = 0; i < 32; ++i) {
i32 n1 = (rng() >> 26) + col * 64;
i32 n2 = (rng() >> 26) + (col + 1) * 64;
std::swap(queue[mode][n1], queue[mode][n2]);
}
}
}
// Copy the first 4 puyos (or the first 2 pairs) of the 3-color queue to the 4-color queue and 5-color queue
// This will ensure that the first 2 pairs of the puyo queue always contain only 3 colors
for (i32 i = 0; i < 4; ++i) {
queue[1][i] = queue[0][i];
queue[2][i] = queue[0][i];
}
// Since only the 4-color queue is used in battles, we will only return it
std::vector<Cell::Type> result;
for (i32 i = 0; i < 256; ++i) {
result.push_back(Cell::Type(queue[1][i]));
}
return result;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment