Update Wires and Tetris time
This commit is contained in:
parent
06dbb8155e
commit
a4cf115bd6
@ -12,7 +12,7 @@ void init_sd() {
|
|||||||
// If format_if_mount_failed is set to true, SD card will be partitioned and
|
// If format_if_mount_failed is set to true, SD card will be partitioned and
|
||||||
// formatted in case when mounting fails.
|
// formatted in case when mounting fails.
|
||||||
esp_vfs_fat_sdmmc_mount_config_t mount_config = {
|
esp_vfs_fat_sdmmc_mount_config_t mount_config = {
|
||||||
.format_if_mount_failed = false,
|
.format_if_mount_failed = true,
|
||||||
.max_files = 5,
|
.max_files = 5,
|
||||||
.allocation_unit_size = 16 * 1024,
|
.allocation_unit_size = 16 * 1024,
|
||||||
.disk_status_check_enable = false,
|
.disk_status_check_enable = false,
|
||||||
|
|||||||
@ -342,7 +342,7 @@ void step4(void) {
|
|||||||
complete();
|
complete();
|
||||||
while (!play_game(4*60*1000, 4)) fail();
|
while (!play_game(4*60*1000, 4)) fail();
|
||||||
complete();
|
complete();
|
||||||
while (!play_game(6*60*1000, 8)) fail();
|
while (!play_game(7*60*1000, 8)) fail();
|
||||||
complete();
|
complete();
|
||||||
// vTaskDelay(pdMS_TO_TICKS(3000));
|
// vTaskDelay(pdMS_TO_TICKS(3000));
|
||||||
|
|
||||||
|
|||||||
@ -122,6 +122,8 @@ void generate_new_wires(WireColor* wires) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void solve_wires(WireColor* wires, bool* out_cut) {
|
void solve_wires(WireColor* wires, bool* out_cut) {
|
||||||
|
bool debug = false;
|
||||||
|
|
||||||
// by default, don't cut any wires
|
// by default, don't cut any wires
|
||||||
for (int i = 0; i < NUM_WIRES; i++) {
|
for (int i = 0; i < NUM_WIRES; i++) {
|
||||||
out_cut[i] = false;
|
out_cut[i] = false;
|
||||||
@ -183,7 +185,9 @@ void solve_wires(WireColor* wires, bool* out_cut) {
|
|||||||
if (list_pos_len[i] == max_len) {
|
if (list_pos_len[i] == max_len) {
|
||||||
int idx = list_pos[i][1];
|
int idx = list_pos[i][1];
|
||||||
out_cut[idx] = true;
|
out_cut[idx] = true;
|
||||||
// ESP_LOGI(TAG, "1. cutting %d", idx);
|
if (debug) {
|
||||||
|
printf("C1. cutting %d\n", idx);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -191,14 +195,18 @@ void solve_wires(WireColor* wires, bool* out_cut) {
|
|||||||
// 2. cut the first wire if it is green or white
|
// 2. cut the first wire if it is green or white
|
||||||
if (wires[0] == WireColor::green || wires[0] == WireColor::white) {
|
if (wires[0] == WireColor::green || wires[0] == WireColor::white) {
|
||||||
out_cut[0] = true;
|
out_cut[0] = true;
|
||||||
// ESP_LOGI(TAG, "2. cutting %d", 0);
|
if (debug) {
|
||||||
|
printf("C2. cutting %d\n", 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. cut blue wires in even positions (odd indexes)
|
// 3. cut blue wires in even positions (odd indexes)
|
||||||
for (int i = 1; i < NUM_WIRES; i += 2) {
|
for (int i = 1; i < NUM_WIRES; i += 2) {
|
||||||
if (wires[i] == WireColor::blue) {
|
if (wires[i] == WireColor::blue) {
|
||||||
out_cut[i] = true;
|
out_cut[i] = true;
|
||||||
// ESP_LOGI(TAG, "3. cutting %d", i);
|
if (debug) {
|
||||||
|
printf("C3. cutting %d\n", i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -210,7 +218,9 @@ void solve_wires(WireColor* wires, bool* out_cut) {
|
|||||||
) {
|
) {
|
||||||
out_cut[i] = true;
|
out_cut[i] = true;
|
||||||
out_cut[i+1] = true;
|
out_cut[i+1] = true;
|
||||||
// ESP_LOGI(TAG, "4. cutting %d, %d", i, i+1);
|
if (debug) {
|
||||||
|
printf("C4. cutting %d, %d\n", i, i+1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -224,7 +234,9 @@ void solve_wires(WireColor* wires, bool* out_cut) {
|
|||||||
wires[pos+1] == WireColor::white
|
wires[pos+1] == WireColor::white
|
||||||
) {
|
) {
|
||||||
out_cut[pos] = true;
|
out_cut[pos] = true;
|
||||||
// ESP_LOGI(TAG, "5. cutting %d", pos);
|
if (debug) {
|
||||||
|
printf("C5. cutting %d\n", pos);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -233,14 +245,18 @@ void solve_wires(WireColor* wires, bool* out_cut) {
|
|||||||
if (wires[4] == WireColor::red) {
|
if (wires[4] == WireColor::red) {
|
||||||
for (int white_idx = 0; white_idx < white_pos_len; white_idx++) {
|
for (int white_idx = 0; white_idx < white_pos_len; white_idx++) {
|
||||||
out_cut[white_pos[white_idx]] = true;
|
out_cut[white_pos[white_idx]] = true;
|
||||||
// ESP_LOGI(TAG, "6. cutting %d", white_pos[white_idx]);
|
if (debug) {
|
||||||
|
printf("C6. cutting %d\n", white_pos[white_idx]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 7. cut the first black wire if there are more white wires than green wires
|
// 7. cut the first black wire if there are more white wires than green wires
|
||||||
if (white_pos_len > green_pos_len && black_pos_len > 0) {
|
if (white_pos_len > green_pos_len && black_pos_len > 0) {
|
||||||
out_cut[black_pos[0]] = true;
|
out_cut[black_pos[0]] = true;
|
||||||
// ESP_LOGI(TAG, "7. cutting %d", black_pos[0]);
|
if (debug) {
|
||||||
|
printf("C7. cutting %d\n", black_pos[0]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 8. cut all wires in an alternating pattern of 2 colors at least 4 wires long
|
// 8. cut all wires in an alternating pattern of 2 colors at least 4 wires long
|
||||||
@ -254,7 +270,9 @@ void solve_wires(WireColor* wires, bool* out_cut) {
|
|||||||
out_cut[i+1] = true;
|
out_cut[i+1] = true;
|
||||||
out_cut[i+2] = true;
|
out_cut[i+2] = true;
|
||||||
out_cut[i+3] = true;
|
out_cut[i+3] = true;
|
||||||
// ESP_LOGI(TAG, "8. cutting %d, %d, %d, %d", i, i+1, i+2, i+3);
|
if (debug) {
|
||||||
|
printf("C8. cutting %d, %d, %d, %d\n", i, i+1, i+2, i+3);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -262,7 +280,9 @@ void solve_wires(WireColor* wires, bool* out_cut) {
|
|||||||
for (int i = 0; i < NUM_WIRES; i++) {
|
for (int i = 0; i < NUM_WIRES; i++) {
|
||||||
if (color_name_len[wires[i]] == i+1) {
|
if (color_name_len[wires[i]] == i+1) {
|
||||||
out_cut[i] = true;
|
out_cut[i] = true;
|
||||||
// ESP_LOGI(TAG, "9. cutting %d", i);
|
if (debug) {
|
||||||
|
printf("C9. cutting %d\n", i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -270,30 +290,36 @@ void solve_wires(WireColor* wires, bool* out_cut) {
|
|||||||
if (max_len <= 2) {
|
if (max_len <= 2) {
|
||||||
for (int i = 0; i < red_pos_len; i++) {
|
for (int i = 0; i < red_pos_len; i++) {
|
||||||
out_cut[red_pos[i]] = true;
|
out_cut[red_pos[i]] = true;
|
||||||
// ESP_LOGI(TAG, "10. cutting %d", red_pos[i]);
|
if (debug) {
|
||||||
|
printf("C10. cutting %d\n", red_pos[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 11. cut the last wire if it is the same color as the first wire
|
// 11. cut the last wire if it is the same color as the first wire
|
||||||
if (wires[0] == wires[NUM_WIRES-1]) {
|
if (wires[0] == wires[NUM_WIRES-1]) {
|
||||||
out_cut[NUM_WIRES-1] = true;
|
out_cut[NUM_WIRES-1] = true;
|
||||||
// ESP_LOGI(TAG, "11. cutting %d", NUM_WIRES-1);
|
if (debug) {
|
||||||
|
printf("C11. cutting %d\n", NUM_WIRES-1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 12. cut any wire adjacent to both a yellow and blue wire
|
// 12. cut any wire adjacent to both a yellow and blue wire
|
||||||
for (int i = 0; i < NUM_WIRES-2; i++) {
|
for (int i = 0; i < NUM_WIRES-2; i++) {
|
||||||
if (
|
if (
|
||||||
(wires[i] == WireColor::yellow && wires[i+2] == WireColor::blue) ||
|
(wires[i] == WireColor::yellow && wires[i+2] == WireColor::blue) ||
|
||||||
(wires[i] == WireColor::blue && wires[i+2] == WireColor::white)
|
(wires[i] == WireColor::blue && wires[i+2] == WireColor::yellow)
|
||||||
) {
|
) {
|
||||||
out_cut[i+1] = true;
|
out_cut[i+1] = true;
|
||||||
// ESP_LOGI(TAG, "12. cutting %d", i+1);
|
if (debug) {
|
||||||
|
printf("C12. cutting %d\n", i+1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NEVER CUT
|
// NEVER CUT
|
||||||
|
|
||||||
// never cut blue wires next to red or green wires
|
// 1. never cut blue wires next to red or green wires
|
||||||
for (int i = 0; i < blue_pos_len; i++) {
|
for (int i = 0; i < blue_pos_len; i++) {
|
||||||
int pos = blue_pos[i];
|
int pos = blue_pos[i];
|
||||||
if (
|
if (
|
||||||
@ -303,50 +329,80 @@ void solve_wires(WireColor* wires, bool* out_cut) {
|
|||||||
wires[pos+1] == WireColor::green
|
wires[pos+1] == WireColor::green
|
||||||
) {
|
) {
|
||||||
out_cut[pos] = false;
|
out_cut[pos] = false;
|
||||||
|
if (debug) {
|
||||||
|
printf("N1. Never cutting %d\n", pos);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// never cut white wires if there is at least one red, black and green wire
|
// 2. never cut white wires if there is at least one red, black and green wire
|
||||||
if (red_pos_len > 0 && green_pos_len > 0 && black_pos_len > 0) {
|
if (red_pos_len > 0 && green_pos_len > 0 && black_pos_len > 0) {
|
||||||
for (int i = 0; i < white_pos_len; i++) {
|
for (int i = 0; i < white_pos_len; i++) {
|
||||||
out_cut[white_pos[i]] = false;
|
out_cut[white_pos[i]] = false;
|
||||||
|
if (debug) {
|
||||||
|
printf("N2. Never cutting %d\n", white_pos[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// never cut red or black wires in the 4th or 7th positions
|
// 3. never cut red or black wires in the 4th or 7th positions
|
||||||
if (wires[3] == WireColor::red || wires[3] == WireColor::black) {
|
if (wires[3] == WireColor::red || wires[3] == WireColor::black) {
|
||||||
out_cut[3] = false;
|
out_cut[3] = false;
|
||||||
|
if (debug) {
|
||||||
|
printf("N3. Never cutting %d\n", 3);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (wires[6] == WireColor::red || wires[6] == WireColor::black) {
|
if (wires[6] == WireColor::red || wires[6] == WireColor::black) {
|
||||||
out_cut[6] = false;
|
out_cut[6] = false;
|
||||||
}
|
if (debug) {
|
||||||
|
printf("N3. Never cutting %d\n", 6);
|
||||||
// never cut wires that have the same color on both sides of it
|
|
||||||
for (int i = 0; i < NUM_WIRES-2; i++) {
|
|
||||||
if (wires[i] == wires[i+2]) {
|
|
||||||
out_cut[i+1] = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// never cut a wire in the 1st, 2nd, or 3rd position if it is the same color as the wire in the 4th position.
|
// 4. never cut wires that have the same color on both sides of it
|
||||||
|
for (int i = 0; i < NUM_WIRES-2; i++) {
|
||||||
|
if (wires[i] == wires[i+2]) {
|
||||||
|
out_cut[i+1] = false;
|
||||||
|
if (debug) {
|
||||||
|
printf("N4. Never cutting %d\n", i+1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 5. never cut a wire in the 1st, 2nd, or 3rd position if it is the same color as the wire in the 4th position.
|
||||||
if (wires[0] == wires[3]) {
|
if (wires[0] == wires[3]) {
|
||||||
out_cut[0] = false;
|
out_cut[0] = false;
|
||||||
|
if (debug) {
|
||||||
|
printf("N5. Never cutting %d\n", 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (wires[1] == wires[3]) {
|
if (wires[1] == wires[3]) {
|
||||||
out_cut[1] = false;
|
out_cut[1] = false;
|
||||||
|
if (debug) {
|
||||||
|
printf("N5. Never cutting %d\n", 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (wires[2] == wires[3]) {
|
if (wires[2] == wires[3]) {
|
||||||
out_cut[2] = false;
|
out_cut[2] = false;
|
||||||
|
if (debug) {
|
||||||
|
printf("N5. Never cutting %d\n", 2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// never cut a blue or green wire in the 8th postion
|
// 6. never cut a blue or green wire in the 8th postion
|
||||||
if (wires[7] == WireColor::blue || wires[7] == WireColor::green) {
|
if (wires[7] == WireColor::blue || wires[7] == WireColor::green) {
|
||||||
out_cut[7] = false;
|
out_cut[7] = false;
|
||||||
|
if (debug) {
|
||||||
|
printf("N6. Never cutting %d\n", 7);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// never cut a wire in the 5th position if there are no yellow wires
|
// 7. never cut a wire in the 5th position if there are no yellow wires
|
||||||
if (yellow_pos_len == 0) {
|
if (yellow_pos_len == 0) {
|
||||||
out_cut[4] = false;
|
out_cut[4] = false;
|
||||||
|
if (debug) {
|
||||||
|
printf("N7 Never cutting %d\n", 4);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user