void LED_board::flash_panel(){ static bool on_off = true; if(on_off) set_panel(true); else set_panel(false); on_off = !on_off; }
void LED_board::sys_rst(){ /*//initialization of shifter set_panel(false); SRCLRnot = 1; //don't reset (this value is 0 by default) //initialization of decade counter RESET_DEC1; //reset it RESET_DEC2; CEnot = 0; //enable counting clear_shifter(); PANEL_ON; //turn panel off at first*/ //initialization of shifter set_panel(false); SRCLRnot = 1; //initialization of decade counter RESET_DEC2; CEnot = 1; //disable counter1 CEnot2 = 0; //enable counter2 //increment counter2 to 7 for(int i = 0; i < 7; i++){ DEC_INC; } CEnot2 = 1; //disable counter2 CEnot = 0; //enable counter1 RESET_DEC1; //reset counter1 clear_shifter(); }
/** * @brief set 8cell uncovered cell to covered if use number cell is definitely * judged its value. * * @param panel[PANEL_HEIGHT][PANEL_WIDTH] panel. * @param cell number cell. */ void set_8cell_with_num_cell(CELL panel[PANEL_HEIGHT][PANEL_WIDTH], POS cell) { int num = panel[cell.x][cell.y], i = 0; int uncovered_count = 0, coveredmine_count = 0; POS* uncovereds = get_uncovered_cells(panel, cell, &uncovered_count); POS* coveredmines = get_covered_mine_cells(panel, cell, &coveredmine_count); do { if (num == coveredmine_count) { for (i = 0; i < uncovered_count; i ++) { set_panel(panel, uncovereds[i], 0); } } else if (num == uncovered_count + coveredmine_count) { for (i = 0; i < uncovered_count; i ++) { set_panel(panel, uncovereds[i], 9); } } } while(0); free(uncovereds); free(coveredmines); }
/** * @brief judge has invalid situation or not. * * @param tmppanel[PANEL_HEIGHT][PANEL_WIDTH] tmp panel. * @param cell center cell. * @param mineornot hasmine is 1, otherwise no mine is 0. * * @return return 1 means has invalid situation, otherwise return 0 means not * has invalid situation. */ int judge_hasinvalid(CELL tmppanel[PANEL_HEIGHT][PANEL_WIDTH], POS cell, CELL mineornot) { int i = 0, numcount = 0, rflag = 0; set_panel(tmppanel, cell, mineornot ? 9 : 0); POS* num_cells = get_number_cells(tmppanel, cell, &numcount); for (i = 0; i < numcount; i ++) { if (!is_8cell_valid(tmppanel, num_cells[i])) { rflag = 1; break; } } free(num_cells); return rflag; }
/** * @brief judge cell has mine or not use recursion method. * * @param panel[PANEL_HEIGHT][PANEL_WIDTH] panel. * @param cell current cell. * @param nearbys[PANEL_HEIGHT][PANEL_WIDTH] nearbys state array. * * @return return -1 means unknow, 0 means definitely no mine, 9 means definitely * has mine, or -9 means invalid minesweeper cells. */ int judge_cell_mine_or_not(CELL panel[PANEL_HEIGHT][PANEL_WIDTH], POS cell, CELL nearbys[PANEL_HEIGHT][PANEL_WIDTH]) { int i = 0; int valid[2] = {0}; // valid[0] for no mine, valid[1] for has mine for (i = 0; i < 2; i ++) { CELL tmppanel[PANEL_HEIGHT][PANEL_WIDTH] = {{0}}; memcpy(tmppanel, panel, sizeof(CELL)*PANEL_HEIGHT*PANEL_WIDTH); valid[i] = judge_hasinvalid(tmppanel, cell, i) ? 0 : 1; } if (valid[0] && valid[1]) { return -1; // unknown } else if (!valid[0] && valid[1]) { set_panel(panel, cell, 9); return 9; // valid } else if (valid[0] && !valid[1]) { set_panel(panel, cell, 0); return 0; // nomine } else { printf("[ERR] -- find invalid minesweeper cells!\n"); return -9; // error invalid } }