예제 #1
0
	/*
	 * check for chains of pills+virii and remove them
	 */
	void game_logic_system::handle_state_check_for_chains(void)
	{
		marked_for_removal.clear();
		
		check_vertical();
		check_horizontal();
		
		hs::entity *current_entity;
		
		//kill them! KILL EM ALL!
		std::vector<hs::entity *>::const_iterator it = marked_for_removal.begin();
		while (it != marked_for_removal.end())
		{
			current_entity = *it;
			++it;
			
			//entities can be marked double - dont add component if it exists already;
			if (!current_entity->get<hs::comp::mark_of_death>())
			{	
				global::g_state.score += (100 + 100 * global::g_state.combo);
				current_entity->add<hs::comp::mark_of_death>();	
				if (current_entity->get<game_board_element>()->type == e_gbo_type_virus)
					global::g_state.virii_left--;
				
				game_board_element *gbo = current_entity->get<game_board_element>();
				hs::entity *shading = em->get_entity_by_guid(gbo->shading_guid);
				if (shading)
				{	
					shading->add<hs::comp::mark_of_death>();
					gbo->shading_guid = 0;
				}
				
				if (gbo->connected_to_guid > 0)
				{
					hs::entity *e = em->get_entity_by_guid(gbo->connected_to_guid);
					disconnect_pill(e);
				}
			}
		}
		
		if (marked_for_removal.size() > 0)
		{
			global::g_state.current_state = global::e_gs_chains_marked;	
			global::g_state.combo++;
			hs::audio_system::play_sound("pill_weg.m4a");
		}
		else
		{
			global::g_state.current_state = global::e_gs_no_chains;	
		}
	}
예제 #2
0
파일: sudoku.c 프로젝트: cit/sudoku-solver
static void solve(unsigned char (*field)[9]) {
    int y, x, nr, found, number;

    for (y=0; y<9; ++y) {
        for (x=0; x<9; ++x) {

            if(field[y][x] == 0) {

                found=0;
                
                for(nr=1; nr<10; ++nr) {

                    if(check_horizontal(field, y, nr) == FALSE) {
                        if(check_vertical(field, x, nr) == FALSE) {
                            if(check_box(field, y, x, nr) == FALSE) {

                                if(ADVANCED_MODE == TRUE) {
                                    if (advanced_algo(field, y, x, nr) == TRUE){
                                        field[y][x] = nr;
                                        solve(field);
                                    }
                                }

                                found++;
                                number = nr;
                                
                            }
                        }
                    }
                    
                }

                if(found == 1) {
                    field[y][x] = number;
                    solve(field);
                }
                
            }
            
        }
    }
}
예제 #3
0
파일: sudoku.c 프로젝트: cit/sudoku-solver
int advanced_algo(unsigned char (*field)[9], int row, int column, int nr) {
    int row_start    = (row / 3) * 3;
    int column_start = (column / 3) * 3;
    int vertical[2], horizontal[2], i, y;

    unsigned char bit[9][9] = {{0,0,0,0,0,0,0,0,0,},
                               {0,0,0,0,0,0,0,0,0,},
                               {0,0,0,0,0,0,0,0,0,},
                               {0,0,0,0,0,0,0,0,0,},
                               {0,0,0,0,0,0,0,0,0,},
                               {0,0,0,0,0,0,0,0,0,},
                               {0,0,0,0,0,0,0,0,0,},
                               {0,0,0,0,0,0,0,0,0,},
                               {0,0,0,0,0,0,0,0,0,}}; 
    
    // Umwandlung in Bitmuster
    for(i=row_start; i<row_start+3; ++i) {
        for(y=column_start; y<column_start+3; ++y) {
            if (field[i][y] != 0)
                bit[i][y] = 1;
        }
    }

    // Herausfinden der 4 Linien
    if (row == 0 || row == 3 || row == 6) {
        vertical[0] = row +1;
        vertical[1] = vertical[0] + 1;
    }
    else if (row == 1 || row == 4 || row == 7) {
        vertical[0] = row + 1;
        vertical[1] = row - 1;
    }
    else {
        vertical[0] = row - 1;
        vertical[1] = vertical[0] - 1;
    }

    if (column == 0 || column == 3 || column == 6) {
        horizontal[0] = column +1;
        horizontal[1] = horizontal[0] + 1;
    }
    else if (column == 1 || column == 4 || column == 7) {
        horizontal[0] = column + 1;
        horizontal[1] = column - 1;
    }
    else {
        horizontal[0] = column - 1;
        horizontal[1] = horizontal[0] - 1;
    }

    for (y=0; y<2; ++y) {
        if ( check_vertical(field, horizontal[y], nr) == TRUE ) {
            for (i=0; i<9; ++i) {
                bit[i][horizontal[y]] = 1;
            }
        }
    }
    
    for (y=0; y<2; ++y) {
        if ( check_horizontal(field, vertical[y], nr) == TRUE ) {
            for (i=0; i<9; ++i) {
                bit[vertical[y]][i] = 1;
            }
        }
    }

    int cnt=0;
    for(i=row_start; i<row_start+3; ++i) {
        for(y=column_start; y<column_start+3; ++y) {
            if (bit[i][y] == 1)
                cnt++;
        }
        
    }

    return (cnt == 8 ? TRUE : FALSE);
}