Beispiel #1
0
BOOL CEditMerkmal :: OnInitDialog()
{
	CComboBox *pBox1, *pBox2;
	CxString eintrag, key, wert, temp;
	POSITION pos;
	char a, b, c;
	BOOL result = CDialog::OnInitDialog();

	pBox1 = (CComboBox*)GetDlgItem( IDC_COMBO1 );
	pBox2 = (CComboBox*)GetDlgItem( IDC_COMBO2 );
	ASSERT( pBox1 );
	ASSERT( pBox2 );

	if ( result )
	{	CopyMap( &TriasIdentMap, m_pTriasIdentMap );
		CopyMap( &TriasXIdentMap, m_pTriasXIdentMap );
		CopyMap( &AttribTexteMap, m_pAttribTexteMap );
		CopyMap( &WertTexteMap, m_pWertTexteMap );

		for ( pos = m_pAttribTexteMap -> GetStartPosition(); pos != NULL; )
		{	m_pAttribTexteMap -> GetNextAssoc( pos, key, wert );
			eintrag = key;
			eintrag += ": ";
			eintrag += wert;
			pBox1 -> AddString( eintrag );
		}

		for ( pos = m_pWertTexteMap -> GetStartPosition(); pos != NULL; )
		{	m_pWertTexteMap -> GetNextAssoc( pos, eintrag, wert );
			eintrag.Teilen( key, eintrag, '=' );
			key.TrimAll();
			eintrag.TrimAll();
			a = b = c = '0';
			wert = key;
			wert += a;
			wert += b;
			wert += c;
			while ( m_pWertTexteMap -> Lookup( wert, temp ))
			{	c++;
				if ( c > '9' ) { c = '0'; b++; }
				if ( b > '9' ) { b = '0'; a++; }
				wert = key;
				wert += a;
				wert += b;
				wert += c;
			}
//			m_pWertMap.SetAt( wert, eintrag );
		}
	}

	return result;
}	// OnInitDialog
Beispiel #2
0
int main(void)
{
    int row, col;
    int selection;
    int ndead;
    int nsecPerDay = 86400;
    int a[nsecPerDay];
    

    Grid map;
    Grid newmap;
    Initialize(map);
    system("/usr/bin/clear");

    printf("press: \n"
            "(1) for glider gun\n"
            "(2) for harvester\n"
            "(3) for cheshire cat\n"
            "(4) for acorn\n"
            " => ");

    scanf("%d", &selection);

    switch( selection ) {
        case 1:
            initGliderGun(map);
        case 2:
            initHarvester(map);
        case 3:
            initCheshireCat(map);
        case 4:
            initAcorn(map);
        break;
    }

    WriteMap(map);
  
    int generations = 0;

    while (generations < nsecPerDay) {    // number of seconds in 24 hours. this won't hold your interest that long.
        WriteMap(map);
        for (row = 1; row <= MAXROW; row++) 
            for (col = 1; col <= MAXCOL; col++) 
                switch(NeighborCount(map, row, col)) {
                case 0:
                case 1:
                    newmap[row][col] = DEAD;
                    ndead = CheckForSurvivors(map);
                    if (ndead == (MAXROW * MAXCOL)) {
                        printf("all cells dead. exiting.\n"); 
                        exit(1);
                    }
                    break;
                case 2:
                    newmap[row][col] = map[row][col];
                    ndead = CheckForSurvivors(map);
                    if (ndead == (MAXROW * MAXCOL)) {
                        printf("all cells dead. exiting.\n"); 
                        exit(1);
                    }
                    break;
                case 3:
                    newmap[row][col] = ALIVE;
                    ndead = CheckForSurvivors(map);
                    if (ndead == (MAXROW * MAXCOL)) {
                        printf("all cells dead. exiting.\n"); 
                        exit(1);
                    }
                    break;
                case 4:
                case 5:
                case 6:
                case 7:
                case 8:
                    newmap[row][col] = DEAD;
                    ndead = CheckForSurvivors(map);
                    if (ndead == (MAXROW * MAXCOL)) {
                        printf("all cells dead. exiting.\n"); 
                        exit(1);
                    }
                    break;
                }

            WriteMap(map);
            a[generations] = CheckForSurvivors(map); 

            if (a[generations] == a[generations-4]) {
                if (selection == 1 || selection == 5) {
                    ;
                } else {
                    printf("grid is stable. exiting.\n"); 
                    exit(1);
                }
            }
          
            CopyMap(map, newmap);
            sleep(1);
            generations++;
    }
        
}