<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[8 Damen Problem]]></title><description><![CDATA[<p>Aufgabenstellung:<br />
Beim 8-Damen-Problem müssen auf einem Schachbrett 8 Damen so positioniert werden, dass sie sich gegenseitig nicht bedrohen.<br />
Schreiben Sie ein Programm zur Unterstützung bei der Suche nach einer Lösung. Es soll möglich sein, durch Eingabe der Feldkoordinaten in der üblichen Schachnotation Damen auf dem Feld zu positionieren. Falls die gewählte Position bedroht ist, soll das Programm eine Meldung ausgeben. Andernfalls wird eine Dame an diese Position gesetzt. Die Eingabe kann so lange wiederholt werden, bis 8 Damen positioniert wurden.</p>
<p>Ich darf zur Lösung dieser Aufgabe keine Funktionen verwenden.<br />
Mein bisheriger Lösungsansatz sieht bisher so aus:</p>
<pre><code>#include&lt;iostream&gt;
using namespace std;

int main(){
    bool schachbrett[8][8];
    char feldkoordinaten_b;
    int feldkoordinaten_z;

    int position0, position00;
    int position1, position11;

    bool kollision = true;
    int damen = 0;

    for(int i = 0; i &lt; 8; ++i){
        for(int j = 0; j &lt; 8; ++j){
            schachbrett[i][j] = true;
        }
    }

    while(damen &lt; 8){

        while(kollision == true){

            cout &lt;&lt; &quot;Eingabe Feldkoordinaten: &quot;;
            cin &gt;&gt; feldkoordinaten_b &gt;&gt; feldkoordinaten_z;

            //Aus Feldkoordinaten Indexposition im Array ermitteln
            position0 = feldkoordinaten_b - 64  -1;
            position1 = feldkoordinaten_z  -1;

            //Kollision prüfen
            for(int k = 0; k &lt; 8; ++k){
                for(int l = 0; l &lt; 8; ++l){
                    if(schachbrett[k][l] == false &amp;&amp; k == position0 &amp;&amp; l == position1){
                        kollision = true;
                    }else {
                        kollision = false;
                    }
                }
            }
        }

        cout &lt;&lt; &quot;Kollision&quot; &lt;&lt; kollision &lt;&lt; endl;

        position00 = position0;
        position11 = position1;

        //Spalte
        for(int j = 0; j &lt; 8; ++j){
            schachbrett[j][position11] = false;
        }

        //Zeile
        for(int i = 0; i &lt; 8; ++i){
            schachbrett[position00][i] = false;
        }

        //Diagnale nach links oben
        position00 = position0;
        position11 = position1;

        for(int i = position00-1; i &gt;= 0; --i){
            for(int j = position11-1; j &gt;= 0; --j){
                schachbrett[position00][position11] = false;
                position00--;
                position11--;
            }
        }

        //Diagonale nach rechts unten
        position00 = position0;
        position11 = position1;

        for(int i = position00+1; i &lt;= 8; ++i){
            for(int j = position11+1; j &lt;= 8; ++j){
                schachbrett[position00][position11] = false;
                position00++;
                position11++;
            }
        }

        //Diagonale nach rechts oben
        position00 = position0;
        position11 = position1;

        cout &lt;&lt; position00 &lt;&lt; position11 &lt;&lt; endl;

        for(int i = position00-1; i &gt;= 0; --i){
            for(int j = position11+1; j &gt;= 0; --j){
                schachbrett[position00][position11] = false;
                position00--;
                position11++;
            }
        }

        //Diagonale nach links unten
        position00 = position0;
        position11 = position1;

        cout &lt;&lt; position00 &lt;&lt; position11 &lt;&lt; endl;

        for(int i = position00+1; i &lt;= 8; ++i){
            for(int j = position11; j &gt;=0; --j){
                schachbrett[position00][position11] = false;
                position00++;
                position11--;
            }
        }

        for(int i = 0; i &lt; 8; ++i){
            for(int j = 0; j &lt; 8; ++j){
                cout &lt;&lt; schachbrett[i][j];
            }
            cout &lt;&lt; endl;
        }

        damen++;

    }

    return 0;

}
</code></pre>
<p>Mein Problem ist, dass meine Kollisionsprüfung noch nicht nach meinen Vorstellungen funktioniert.<br />
Vielleicht könnte mir jemand weiterhelfen.</p>
<p>Freue mich über jede Unterstützung</p>
<p>Vielen lieben Dank</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/327563/8-damen-problem</link><generator>RSS for Node</generator><lastBuildDate>Thu, 09 Jul 2026 15:33:59 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/327563.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 19 Aug 2014 15:59:28 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to 8 Damen Problem on Tue, 19 Aug 2014 15:59:28 GMT]]></title><description><![CDATA[<p>Aufgabenstellung:<br />
Beim 8-Damen-Problem müssen auf einem Schachbrett 8 Damen so positioniert werden, dass sie sich gegenseitig nicht bedrohen.<br />
Schreiben Sie ein Programm zur Unterstützung bei der Suche nach einer Lösung. Es soll möglich sein, durch Eingabe der Feldkoordinaten in der üblichen Schachnotation Damen auf dem Feld zu positionieren. Falls die gewählte Position bedroht ist, soll das Programm eine Meldung ausgeben. Andernfalls wird eine Dame an diese Position gesetzt. Die Eingabe kann so lange wiederholt werden, bis 8 Damen positioniert wurden.</p>
<p>Ich darf zur Lösung dieser Aufgabe keine Funktionen verwenden.<br />
Mein bisheriger Lösungsansatz sieht bisher so aus:</p>
<pre><code>#include&lt;iostream&gt;
using namespace std;

int main(){
    bool schachbrett[8][8];
    char feldkoordinaten_b;
    int feldkoordinaten_z;

    int position0, position00;
    int position1, position11;

    bool kollision = true;
    int damen = 0;

    for(int i = 0; i &lt; 8; ++i){
        for(int j = 0; j &lt; 8; ++j){
            schachbrett[i][j] = true;
        }
    }

    while(damen &lt; 8){

        while(kollision == true){

            cout &lt;&lt; &quot;Eingabe Feldkoordinaten: &quot;;
            cin &gt;&gt; feldkoordinaten_b &gt;&gt; feldkoordinaten_z;

            //Aus Feldkoordinaten Indexposition im Array ermitteln
            position0 = feldkoordinaten_b - 64  -1;
            position1 = feldkoordinaten_z  -1;

            //Kollision prüfen
            for(int k = 0; k &lt; 8; ++k){
                for(int l = 0; l &lt; 8; ++l){
                    if(schachbrett[k][l] == false &amp;&amp; k == position0 &amp;&amp; l == position1){
                        kollision = true;
                    }else {
                        kollision = false;
                    }
                }
            }
        }

        cout &lt;&lt; &quot;Kollision&quot; &lt;&lt; kollision &lt;&lt; endl;

        position00 = position0;
        position11 = position1;

        //Spalte
        for(int j = 0; j &lt; 8; ++j){
            schachbrett[j][position11] = false;
        }

        //Zeile
        for(int i = 0; i &lt; 8; ++i){
            schachbrett[position00][i] = false;
        }

        //Diagnale nach links oben
        position00 = position0;
        position11 = position1;

        for(int i = position00-1; i &gt;= 0; --i){
            for(int j = position11-1; j &gt;= 0; --j){
                schachbrett[position00][position11] = false;
                position00--;
                position11--;
            }
        }

        //Diagonale nach rechts unten
        position00 = position0;
        position11 = position1;

        for(int i = position00+1; i &lt;= 8; ++i){
            for(int j = position11+1; j &lt;= 8; ++j){
                schachbrett[position00][position11] = false;
                position00++;
                position11++;
            }
        }

        //Diagonale nach rechts oben
        position00 = position0;
        position11 = position1;

        cout &lt;&lt; position00 &lt;&lt; position11 &lt;&lt; endl;

        for(int i = position00-1; i &gt;= 0; --i){
            for(int j = position11+1; j &gt;= 0; --j){
                schachbrett[position00][position11] = false;
                position00--;
                position11++;
            }
        }

        //Diagonale nach links unten
        position00 = position0;
        position11 = position1;

        cout &lt;&lt; position00 &lt;&lt; position11 &lt;&lt; endl;

        for(int i = position00+1; i &lt;= 8; ++i){
            for(int j = position11; j &gt;=0; --j){
                schachbrett[position00][position11] = false;
                position00++;
                position11--;
            }
        }

        for(int i = 0; i &lt; 8; ++i){
            for(int j = 0; j &lt; 8; ++j){
                cout &lt;&lt; schachbrett[i][j];
            }
            cout &lt;&lt; endl;
        }

        damen++;

    }

    return 0;

}
</code></pre>
<p>Mein Problem ist, dass meine Kollisionsprüfung noch nicht nach meinen Vorstellungen funktioniert.<br />
Vielleicht könnte mir jemand weiterhelfen.</p>
<p>Freue mich über jede Unterstützung</p>
<p>Vielen lieben Dank</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2414169</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2414169</guid><dc:creator><![CDATA[estrella]]></dc:creator><pubDate>Tue, 19 Aug 2014 15:59:28 GMT</pubDate></item><item><title><![CDATA[Reply to 8 Damen Problem on Tue, 19 Aug 2014 16:13:44 GMT]]></title><description><![CDATA[<p>kollission muss für einen neuen versuch zurückgestellt werden.</p>
<pre><code>while(damen &lt; 8){
        bool kollision = true;
        while(kollision == true){
</code></pre>
<p>oder besser dort eine do-schleife nehmen.</p>
<p>Und darfst es in der prüfung nicht wieder auf false setzen.</p>
<pre><code>//Kollision prüfen
            kollision = false;
            for(int k = 0; k &lt; 8; ++k){
                for(int l = 0; l &lt; 8; ++l){
                    if(schachbrett[k][l] == false &amp;&amp; k == position0 &amp;&amp; l == position1){
                        kollision = true;
                    }
                }
            }
</code></pre>
<p>oder besser einfach nur</p>
<pre><code>//Kollision prüfen
            kollision = false;
            if(schachbrett[k][l] == false){
                kollision = true;
            }
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2414170</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2414170</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Tue, 19 Aug 2014 16:13:44 GMT</pubDate></item><item><title><![CDATA[Reply to 8 Damen Problem on Tue, 19 Aug 2014 17:19:53 GMT]]></title><description><![CDATA[<p>Danke für den Tipp mit der do while Schleife.<br />
Natürlich muss nach jedem Durchlauf Kollision wieder false sein.<br />
Das habe ich jetzt in meinem Programm beachtet.</p>
<p>Auch deine verkürzte Form der Kollision war sehr hilfreich.</p>
<p>Vielen lieben Dank</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2414185</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2414185</guid><dc:creator><![CDATA[estrella]]></dc:creator><pubDate>Tue, 19 Aug 2014 17:19:53 GMT</pubDate></item><item><title><![CDATA[Reply to 8 Damen Problem on Tue, 19 Aug 2014 18:12:50 GMT]]></title><description><![CDATA[<p>estrella schrieb:</p>
<blockquote>
<pre><code>char feldkoordinaten_b;
    int feldkoordinaten_z;
            //Aus Feldkoordinaten Indexposition im Array ermitteln
            position0 = feldkoordinaten_b - 64  -1;
            position1 = feldkoordinaten_z  -1;
</code></pre>
</blockquote>
<p>würde ich noch machen zu</p>
<pre><code>char feldkoordinaten_b;
    char feldkoordinaten_z;
            position0 = feldkoordinaten_b - 'A';
            position1 = feldkoordinaten_z - '0';
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2414197</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2414197</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Tue, 19 Aug 2014 18:12:50 GMT</pubDate></item><item><title><![CDATA[Reply to 8 Damen Problem on Tue, 19 Aug 2014 18:45:34 GMT]]></title><description><![CDATA[<p>Danke für den weiteren Tipp.<br />
Ich habe diesen im meinem Programm beherzigt.<br />
Leider funktioniert es noch nicht wirklich.</p>
<p>Mein Code sieht jetzt so aus:</p>
<pre><code>#include&lt;iostream&gt;
using namespace std;

int main(){
    bool schachbrett[8][8];
    char feldkoordinaten_b;
    char feldkoordinaten_z;

    int position0, position00;
    int position1, position11;

    bool kollision = true;
    int damen = 0;

    for(int i = 0; i &lt; 8; ++i){
        for(int j = 0; j &lt; 8; ++j){
            schachbrett[i][j] = true;
        }
    }

    while(damen &lt; 8){

        do{
            cout &lt;&lt; &quot;Eingabe Feldkoordinaten: &quot;;
            cin &gt;&gt; feldkoordinaten_b &gt;&gt; feldkoordinaten_z;

            //Aus Feldkoordinaten Indexposition im Array ermitteln
            position0 = feldkoordinaten_b - 'A';
            position1 = feldkoordinaten_z - '0';
            // -1 um richtigen Index im Array zu erhalten
            position1 = position1-1;

            //position0 = feldkoordinaten_b - 64  -1;
            //position1 = feldkoordinaten_z  -1;

            //Kollision prüfen
            for(int k = 0; k &lt; 8; ++k){
                for(int l = 0; l &lt; 8; ++l){

                    kollision = false;
                    if(schachbrett[k][l] == false){
                        kollision = true;
                    }

                }
            }

        }while(kollision == true);

        position00 = position0;
        position11 = position1;

        //Spalte
        for(int j = 0; j &lt; 8; ++j){
            schachbrett[j][position11] = false;
        }

        //Zeile
        for(int i = 0; i &lt; 8; ++i){
            schachbrett[position00][i] = false;
        }

        //Diagnale nach links oben
        position00 = position0;
        position11 = position1;

        for(int i = position00-1; i &gt;= 0; --i){
            for(int j = position11-1; j &gt;= 0; --j){
                schachbrett[position00][position11] = false;
                position00--;
                position11--;
            }
        }

        //Diagonale nach rechts unten
        position00 = position0;
        position11 = position1;

        for(int i = position00+1; i &lt;= 8; ++i){
            for(int j = position11+1; j &lt;= 8; ++j){
                schachbrett[position00][position11] = false;
                position00++;
                position11++;
            }
        }

        //Diagonale nach rechts oben
        position00 = position0;
        position11 = position1;

        cout &lt;&lt; position00 &lt;&lt; position11 &lt;&lt; endl;

        for(int i = position00-1; i &gt;= 0; --i){
            for(int j = position11+1; j &gt;= 0; --j){
                schachbrett[position00][position11] = false;
                position00--;
                position11++;
            }
        }

        //Diagonale nach links unten
        position00 = position0;
        position11 = position1;

        cout &lt;&lt; position00 &lt;&lt; position11 &lt;&lt; endl;

        for(int i = position00+1; i &lt;= 8; ++i){
            for(int j = position11; j &gt;=0; --j){
                schachbrett[position00][position11] = false;
                position00++;
                position11--;
            }
        }

        for(int i = 0; i &lt; 8; ++i){
            for(int j = 0; j &lt; 8; ++j){
                cout &lt;&lt; schachbrett[i][j];
            }
            cout &lt;&lt; endl;
        }

        damen++;

        }

    return 0;

}
</code></pre>
<p>Es gibt mehrere Probleme mit den ich Schwierigkeiten habe.<br />
Zum einen wenn ich als erstes C4 eingebe, erhalte ich hier:</p>
<pre><code>//Diagonale nach rechts oben
        position00 = position0;
        position11 = position1;

        cout &lt;&lt; position00 &lt;&lt; position11 &lt;&lt; endl;

        for(int i = position00-1; i &gt;= 0; --i){
            for(int j = position11+1; j &gt;= 0; --j){
                schachbrett[position00][position11] = false;
                position00--;
                position11++;
            }
        }
</code></pre>
<p>in dieser Zeile:<br />
schachbrett[position00][position11] = false;<br />
den Fehler<br />
Thread 1: EXC_BAD_ACCESS(code=1, address=0x7fff67bff790)</p>
<p>Teste ich andere Werte wie zum Beispiel A1<br />
00000000<br />
00111111<br />
01011111<br />
01101111<br />
01110111<br />
01111011<br />
01111101<br />
01111110<br />
erster Durchlauf vollkommen in Ordnung.<br />
Zweiter Durchlauf mit B3 geht nicht bzw. mein Programm denkt es würde zu einer Kollision führen.</p>
<p>Ich habe auch noch weitere Fälle gefunden die nicht funktionieren.</p>
<p>Vielleicht sieht jemand den Fehler in meinem Programm?<br />
Danke</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2414207</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2414207</guid><dc:creator><![CDATA[estrella]]></dc:creator><pubDate>Tue, 19 Aug 2014 18:45:34 GMT</pubDate></item><item><title><![CDATA[Reply to 8 Damen Problem on Tue, 19 Aug 2014 19:29:00 GMT]]></title><description><![CDATA[<p>Mir scheint, position00 und position11 können aus dem gültigen Bereich 0-7 rauslaufen.</p>
<p>ich dächte daran, gleich auf schachbrett[i][j] zu arbeiten und position00 und position11 ganz wegzulassen.</p>
<p>edit: halt! die schleife soll gar nicht verschachtelt sein.</p>
<p>kannst position00 und position11 nehmen und nur eine i-schleife drum. und abbrechen (mit break), wenn position00 oder position11 rauslaufen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2414216</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2414216</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Tue, 19 Aug 2014 19:29:00 GMT</pubDate></item><item><title><![CDATA[Reply to 8 Damen Problem on Tue, 19 Aug 2014 20:23:38 GMT]]></title><description><![CDATA[<p>Ich habe mittlerweile meinen Fehler gefunden.</p>
<pre><code>for(int i = position00-1; i &gt;= 0; --i){
    for(int j = position11+1; j &gt;= 0; --j){
          schachbrett[position00][position11] = false;
          position00--;
          position11++;
    }
}
</code></pre>
<p>meine innere for Schleife läuft aus dem Bereich.<br />
Sollte so aussehen:</p>
<pre><code>for(int i = position00-1; i &gt;= 0; --i){
    for(int j = position11+1; j &lt; 8; ++j){
          schachbrett[position00][position11] = false;
          position00--;
          position11++;
    }
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2414228</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2414228</guid><dc:creator><![CDATA[estrella]]></dc:creator><pubDate>Tue, 19 Aug 2014 20:23:38 GMT</pubDate></item></channel></rss>