1010 for Arduboy
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

new_shapes: bias random shape picking away from long boyes and 3x3 squares

These pieces are really hard to work with and sometimes the random
function will choose 3 of them at a time.

+39 -24
+39 -24
arduboy-1010.ino
··· 108 108 109 109 /* tile shapes */ 110 110 typedef struct { 111 - const byte width, height; 111 + const byte width, height, weight; 112 112 const byte tiles[9]; 113 113 } shape; 114 114 115 115 const shape shapes[] = { 116 - { 0, 0, { // empty 116 + { 0, 0, 0, { // empty 117 117 0, 118 118 } 119 119 }, 120 - { 1, 1, { // dot 120 + { 1, 1, 10, { // dot 121 121 1, 122 122 } 123 123 }, 124 - { 2, 2, { // 2x2 square 124 + { 2, 2, 10, { // 2x2 square 125 125 1, 1, 126 126 1, 1, 127 127 } 128 128 }, 129 - { 3, 3, { // 3x3 square 129 + { 3, 3, 1, { // 3x3 square 130 130 1, 1, 1, 131 131 1, 1, 1, 132 132 1, 1, 1, 133 133 } 134 134 }, 135 - { 2, 1, { // 2x1 horizontal 135 + { 2, 1, 10, { // 2x1 horizontal 136 136 1, 1, 137 137 } 138 138 }, 139 - { 3, 1, { // 3x1 horizontal 139 + { 3, 1, 10, { // 3x1 horizontal 140 140 1, 1, 1, 141 141 } 142 142 }, 143 - { 4, 1, { // 4x1 horizontal 143 + { 4, 1, 10, { // 4x1 horizontal 144 144 1, 1, 1, 1, 145 145 } 146 146 }, 147 - { 5, 1, { // 5x1 horizontal 147 + { 5, 1, 1, { // 5x1 horizontal 148 148 1, 1, 1, 1, 1, 149 149 } 150 150 }, 151 - { 1, 2, { // 1x2 vertical 151 + { 1, 2, 10, { // 1x2 vertical 152 152 1, 153 153 1, 154 154 } 155 155 }, 156 - { 1, 3, { // 1x3 vertical 156 + { 1, 3, 10, { // 1x3 vertical 157 157 1, 158 158 1, 159 159 1, 160 160 } 161 161 }, 162 - { 1, 4, { // 1x4 vertical 162 + { 1, 4, 10, { // 1x4 vertical 163 163 1, 164 164 1, 165 165 1, 166 166 1, 167 167 } 168 168 }, 169 - { 1, 5, { // 1x5 vertical 169 + { 1, 5, 1, { // 1x5 vertical 170 170 1, 171 171 1, 172 172 1, ··· 174 174 1, 175 175 } 176 176 }, 177 - { 2, 2, { // 2x2 elbow 177 + { 2, 2, 10, { // 2x2 elbow 178 178 1, 1, 179 179 0, 1, 180 180 } 181 181 }, 182 - { 2, 2, { // 2x2 elbow 182 + { 2, 2, 10, { // 2x2 elbow 183 183 1, 0, 184 184 1, 1, 185 185 } 186 186 }, 187 - { 2, 2, { // 2x2 elbow 187 + { 2, 2, 10, { // 2x2 elbow 188 188 1, 1, 189 189 1, 0, 190 190 } 191 191 }, 192 - { 2, 2, { // 2x2 elbow 192 + { 2, 2, 10, { // 2x2 elbow 193 193 0, 1, 194 194 1, 1, 195 195 } 196 196 }, 197 - { 3, 3, { // 3x3 elbow 197 + { 3, 3, 10, { // 3x3 elbow 198 198 1, 1, 1, 199 199 0, 0, 1, 200 200 0, 0, 1, 201 201 } 202 202 }, 203 - { 3, 3, { // 3x3 elbow 203 + { 3, 3, 10, { // 3x3 elbow 204 204 1, 0, 0, 205 205 1, 0, 0, 206 206 1, 1, 1, 207 207 } 208 208 }, 209 - { 3, 3, { // 3x3 elbow 209 + { 3, 3, 10, { // 3x3 elbow 210 210 1, 1, 1, 211 211 1, 0, 0, 212 212 1, 0, 0, 213 213 } 214 214 }, 215 - { 3, 3, { // 3x3 elbow 215 + { 3, 3, 10, { // 3x3 elbow 216 216 0, 0, 1, 217 217 0, 0, 1, 218 218 1, 1, 1, ··· 242 242 static unsigned long dpad_millis_next = 0; 243 243 static bool dpad_repeatn = false; 244 244 static int screen_backlight = SCREEN_MAX; 245 + static int shape_weights = 0; 245 246 246 247 void 247 248 setup(void) ··· 601 602 void 602 603 new_shapes(void) 603 604 { 604 - byte x; 605 + byte x, j, r; 605 606 606 607 if (left_ondeck()) 607 608 return; 608 609 609 - for (x = 0; x < ONDECK; x++) 610 - game.ondeck[x] = random(1, sizeof(shapes) / sizeof(shape)); 610 + if (!shape_weights) { 611 + for (x = 0; x < sizeof(shapes) / sizeof(shape); x++) 612 + shape_weights += shapes[x].weight; 613 + } 614 + 615 + for (j = 0; j < ONDECK; j++) { 616 + r = random(1, shape_weights); 617 + 618 + for (x = 0; x < sizeof(shapes) / sizeof(shape); x++) { 619 + if (r < shapes[x].weight) { 620 + game.ondeck[j] = x; 621 + break; 622 + } 623 + r -= shapes[x].weight; 624 + } 625 + } 611 626 } 612 627 613 628 bool