<?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[Problem mit Minimax-Algorithmus]]></title><description><![CDATA[<p>Hallo!</p>
<p>Ich bin grade dabei, eine Implementierung eines Fingerspiels zu schreiben. Die Regeln sind folgendermaßen: Zwei Spieler zeigen am Anfang je einen Finger von jeder Hand. Dann tippt abwechselnd einer der Spieler eine der Hände des Gegners an , dabei wird die Zahl der Finger zur Hand des Gegners addiert. Hat einer 5 Finger an einer Hand, ist sie verloren und wer zuerst beide Hände verliert, hat verloren. Das ganze wollte ich mit einem Minimax-Algorithmus machen. Mein Code bisher:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;cstdlib&gt;
#include &lt;cstdio&gt;
#include &lt;conio.h&gt;
#include &lt;ctime&gt;
using std::cout;
using std::cin;
using std::endl;
using std::rand;
using std::min;
using std::max;

int MAX(int,int,int,int,int);

void wait () //Wartet einen Tastendruck ab
{
    FlushConsoleInputBuffer(GetStdHandle(STD_INPUT_HANDLE));
    getch();
}  

void anzeige(int sR, int sL, int cR, int cL) {
    cout&lt;&lt;&quot;Computer linke Hand: &quot;&lt;&lt;cL&lt;&lt;&quot; Computer rechte Hand: &quot;&lt;&lt;cR&lt;&lt;endl&lt;&lt;endl&lt;&lt;
        &quot;Spieler linke Hand: &quot;&lt;&lt;sL&lt;&lt;&quot; Spieler rechte Hand: &quot;&lt;&lt;sR&lt;&lt;endl&lt;&lt;endl;
}

int bewerte(int sR, int sL, int cR, int cL) {
    int wert = 0;
    wert += ((cR+cL) - (sR+sL));
    if(!sR)
        wert += 10;
    if(!sL)
        wert += 10;
    if(!cR)
        wert -= 10;
    if(!cL)
        wert -= 10;
    return wert;
}

int MINI(int sR, int sL, int cR, int cL, int tiefe) {
    if(tiefe==0) 
        return bewerte(sR, sL, cR, cL);
    else {
        int a=10000;
        int b=10000;   
        int c=10000;
        int d=10000;
        int e=10000;
        int f=10000;

        if(cR || sR)
            a=MAX(sR, sL, ((cR+sR)%5), cL, tiefe--);
        if(cR || sL)
            b=MAX(sR, sL, ((cR+sL)%5), cL, tiefe--);
        if(cL || sR)
            c=MAX(sR, sL, cR, ((cL+sR)%5), tiefe--); 
        if(cL || sL)
            d=MAX(sR, sL, cR, ((cL+sL)%5), tiefe--);

        if((sL+sR)%2==0) {
            if(cR) 
                e=MAX((sR+sL)/2, (sR+sL)/2, (cR+(sR+sL)/2)%5, cL, tiefe--);
            if(cL)
                f=MAX((sR+sL)/2, (sR+sL)/2, cR, (cL+(sR+sL)/2)%5, tiefe--);
        }
        return min(min(min(min(min(a,b),c),d),e),f);
    }
}

int MAX(int sR, int sL, int cR, int cL, int tiefe) {
    if(tiefe==0) 
        return bewerte(sR, sL, cR, cL);
    else {
        int a=10000;
        int b=10000;   
        int c=10000;
        int d=10000;
        int e=10000;
        int f=10000;

        if(cR || sR)
            a=MINI((sR+cR)%5, sL, cR, cL, tiefe--);
        if(cR || sL)
            b=MINI(sR, (sL+cR)%5, cR, cL, tiefe--);
        if(cL || sR)
            c=MINI((sR+cL)%5, sL, cR, cL, tiefe--); 
        if(cL || sL)
            d=MINI(sR, (sL+cL)%5, cR, cL, tiefe--);

        if((cL+cR)%2==0) {
            if(sR)
                e=MINI((sR+((cR+cL)/2))%5, sL, (cR+cL)/2, (cR+cL)/2, tiefe--);
            if(sL)
                f=MINI(sR, (sL+((cR+cL)/2))%5, (cR+cL)/2, (cR+cL)/2, tiefe--);
        }
        return max(max(max(max(max(a,b),c),d),e),f);
    }
}

int computerZug(int sR, int sL, int cR, int cL) {
    int a=-10000;
    int b=-10000;   
    int c=-10000;
    int d=-10000;
    int e=-10000;
    int f=-10000;
    int tiefe=6;

    if(cR || sR) 
        a=MINI((sR+cR)%5, sL, cR, cL, tiefe--);
    if(cR || sL)
        b=MINI(sR, (sL+cR)%5, cR, cL, tiefe--);
    if(cL || sR)
        c=MINI((sR+cL)%5, sL, cR, cL, tiefe--); 
    if(cL || sL)
        d=MINI(sR, (sL+cL)%5, cR, cL, tiefe--);

    if((cL+cR)%2==0) {
        if(sR)
            e=MINI((sR+((cR+cL)/2))%5, sL, (cR+cL)/2, (cR+cL)/2, tiefe--);
        if(sL)
            f=MINI(sR, (sL+((cR+cL)/2))%5, (cR+cL)/2, (cR+cL)/2, tiefe--);
    }

    if(a&gt;b &amp;&amp; a&gt;c &amp;&amp; a&gt;d &amp;&amp; a&gt;e &amp;&amp; a&gt;f)
        return 0;
    if(b&gt;a &amp;&amp; b&gt;c &amp;&amp; b&gt;d &amp;&amp; b&gt;e &amp;&amp; b&gt;f)
        return 1;
    if(c&gt;a &amp;&amp; c&gt;b &amp;&amp; c&gt;d &amp;&amp; c&gt;e &amp;&amp; c&gt;f)
        return 2;
    if(d&gt;a &amp;&amp; d&gt;b &amp;&amp; d&gt;c &amp;&amp; d&gt;e &amp;&amp; d&gt;f)
        return 3;
    if(e&gt;a &amp;&amp; e&gt;b &amp;&amp; e&gt;c &amp;&amp; e&gt;d &amp;&amp; e&gt;f)
        return 4;
    if(f&gt;a &amp;&amp; f&gt;b &amp;&amp; f&gt;c &amp;&amp; f&gt;d &amp;&amp; f&gt;e)
        return 5;
    if(a==b &amp;&amp; a==c &amp;&amp; a==d &amp;&amp; a==e &amp;&amp; a==f)
        return rand()%6;
}

int main()  {
    int sR=1; //Spieler rechte Hand
    int sL=1; //Spieler linke Hand
    int cR=1; //Computer rechte Hand
    int cL=1; //Computer linke Hand
    int zugS=0;
    int zugC=0;

    srand(static_cast&lt;unsigned&gt;(time(NULL)));

    while((sR+sL != 0) &amp;&amp; (cR+cL != 0)) {
        anzeige(sR, sL, cR, cL);
        cout&lt;&lt;&quot;Zug eingeben&quot;&lt;&lt;endl;
        cin.ignore(cin.rdbuf()-&gt;in_avail());
        cin&gt;&gt;zugS;

        switch(zugS) { //Zug des Spielers anwenden...
            case 0: 
                if(sR || cR)
                    cR = (sR+cR)%5;
                else {
                    cout&lt;&lt;&quot;Zug nicht erlaubt.&quot;&lt;&lt;endl;
                    continue; 
                }
                break;
            case 1: 
                if(sL || cR)
                    cR = (sL+cR)%5;
                else {
                    cout&lt;&lt;&quot;Zug nicht erlaubt.&quot;&lt;&lt;endl;
                    continue; 
                } 
                break;
            case 2:
                if(sR || cL)
                    cL = (sR+cL)%5;
                else {
                    cout&lt;&lt;&quot;Zug nicht erlaubt.&quot;&lt;&lt;endl;
                    continue; 
                } 
                break;
            case 3: 
                if(sL || cL)
                    cL = (sL+cL)%5;
                else {
                    cout&lt;&lt;&quot;Zug nicht erlaubt.&quot;&lt;&lt;endl;
                    continue; 
                }
                break;
            case 4:
                if((sL + sR)%2 == 0) {
                    sL=(sL + sR)/2;
                    sR=(sL + sR)/2;
                    continue; //Spieler kann nach Fingertausch noch einen normalen Zug machen
                } else {
                    cout&lt;&lt;&quot;Zug nicht erlaubt!&quot;&lt;&lt;endl;
                    continue;
                }
            default: 
                cout&lt;&lt;&quot;Zug nicht erlaubt.&quot;&lt;&lt;endl;
                continue;
            }

            anzeige(sR, sL, cR, cL);
            zugC=computerZug(sR, sL, cR, cL); //Minimax-Algorithmus

            switch(zugC) { //Zug des Computers anwenden...
            case 0: 
                sR = (cR+sR)%5; 
                break;
            case 1: 
                sR = (cL+sR)%5; 
                break;
            case 2:
                sL = (cR+sL)%5; 
                break;
            case 3: 
                sL = (cL+sL)%5; 
                break;
            case 4:                    
                cL=(cL + cR)/2;
                cR=(cL + cR)/2;
                sR=(cR + cL)%5;
                break;
            case 5:
                cL=(cL + cR)/2;
                cR=(cL + cR)/2;
                sL=(cR + cL)%5;
                break;
            default: 
                cout&lt;&lt;&quot;Fehler im Programm&quot;&lt;&lt;endl;
                wait();
                exit(0);
                break;
            }
      }
}
</code></pre>
<p>Das ist jetzt ein Haufen Code, aber ich wollte es vollständig posten, damit ihr den Fehler nachvollziehen könnt. Das ganze wird nämlich fehlerfrei kompiliert, aber bei der Ausführung stürzt es immer beim Computerzug ab und ich finde die Ursache nicht.<br />
Zweite Sache: Ich habe da ja recht viele unelegante Konstruktionen verwendet, habe aber keine Idee, wie man diese Massen von ifs und dergleichen kürzer und einfacher schreiben könnte. Kann mir jemand weiterhelfen?</p>
<p>Gruß phyll.</p>
<p>edit: Ist der Klammernstil so in Ordnung? Will mir grad sauberes Arbeiten mit 1TBS angewöhnen.</p>
<p>edit2: Sourcecode durtch neuere Version ersetzt</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/201225/problem-mit-minimax-algorithmus</link><generator>RSS for Node</generator><lastBuildDate>Mon, 05 Oct 2026 21:52:10 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/201225.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 26 Dec 2007 19:21:18 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Problem mit Minimax-Algorithmus on Thu, 27 Dec 2007 21:58:57 GMT]]></title><description><![CDATA[<p>Hallo!</p>
<p>Ich bin grade dabei, eine Implementierung eines Fingerspiels zu schreiben. Die Regeln sind folgendermaßen: Zwei Spieler zeigen am Anfang je einen Finger von jeder Hand. Dann tippt abwechselnd einer der Spieler eine der Hände des Gegners an , dabei wird die Zahl der Finger zur Hand des Gegners addiert. Hat einer 5 Finger an einer Hand, ist sie verloren und wer zuerst beide Hände verliert, hat verloren. Das ganze wollte ich mit einem Minimax-Algorithmus machen. Mein Code bisher:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;cstdlib&gt;
#include &lt;cstdio&gt;
#include &lt;conio.h&gt;
#include &lt;ctime&gt;
using std::cout;
using std::cin;
using std::endl;
using std::rand;
using std::min;
using std::max;

int MAX(int,int,int,int,int);

void wait () //Wartet einen Tastendruck ab
{
    FlushConsoleInputBuffer(GetStdHandle(STD_INPUT_HANDLE));
    getch();
}  

void anzeige(int sR, int sL, int cR, int cL) {
    cout&lt;&lt;&quot;Computer linke Hand: &quot;&lt;&lt;cL&lt;&lt;&quot; Computer rechte Hand: &quot;&lt;&lt;cR&lt;&lt;endl&lt;&lt;endl&lt;&lt;
        &quot;Spieler linke Hand: &quot;&lt;&lt;sL&lt;&lt;&quot; Spieler rechte Hand: &quot;&lt;&lt;sR&lt;&lt;endl&lt;&lt;endl;
}

int bewerte(int sR, int sL, int cR, int cL) {
    int wert = 0;
    wert += ((cR+cL) - (sR+sL));
    if(!sR)
        wert += 10;
    if(!sL)
        wert += 10;
    if(!cR)
        wert -= 10;
    if(!cL)
        wert -= 10;
    return wert;
}

int MINI(int sR, int sL, int cR, int cL, int tiefe) {
    if(tiefe==0) 
        return bewerte(sR, sL, cR, cL);
    else {
        int a=10000;
        int b=10000;   
        int c=10000;
        int d=10000;
        int e=10000;
        int f=10000;

        if(cR || sR)
            a=MAX(sR, sL, ((cR+sR)%5), cL, tiefe--);
        if(cR || sL)
            b=MAX(sR, sL, ((cR+sL)%5), cL, tiefe--);
        if(cL || sR)
            c=MAX(sR, sL, cR, ((cL+sR)%5), tiefe--); 
        if(cL || sL)
            d=MAX(sR, sL, cR, ((cL+sL)%5), tiefe--);

        if((sL+sR)%2==0) {
            if(cR) 
                e=MAX((sR+sL)/2, (sR+sL)/2, (cR+(sR+sL)/2)%5, cL, tiefe--);
            if(cL)
                f=MAX((sR+sL)/2, (sR+sL)/2, cR, (cL+(sR+sL)/2)%5, tiefe--);
        }
        return min(min(min(min(min(a,b),c),d),e),f);
    }
}

int MAX(int sR, int sL, int cR, int cL, int tiefe) {
    if(tiefe==0) 
        return bewerte(sR, sL, cR, cL);
    else {
        int a=10000;
        int b=10000;   
        int c=10000;
        int d=10000;
        int e=10000;
        int f=10000;

        if(cR || sR)
            a=MINI((sR+cR)%5, sL, cR, cL, tiefe--);
        if(cR || sL)
            b=MINI(sR, (sL+cR)%5, cR, cL, tiefe--);
        if(cL || sR)
            c=MINI((sR+cL)%5, sL, cR, cL, tiefe--); 
        if(cL || sL)
            d=MINI(sR, (sL+cL)%5, cR, cL, tiefe--);

        if((cL+cR)%2==0) {
            if(sR)
                e=MINI((sR+((cR+cL)/2))%5, sL, (cR+cL)/2, (cR+cL)/2, tiefe--);
            if(sL)
                f=MINI(sR, (sL+((cR+cL)/2))%5, (cR+cL)/2, (cR+cL)/2, tiefe--);
        }
        return max(max(max(max(max(a,b),c),d),e),f);
    }
}

int computerZug(int sR, int sL, int cR, int cL) {
    int a=-10000;
    int b=-10000;   
    int c=-10000;
    int d=-10000;
    int e=-10000;
    int f=-10000;
    int tiefe=6;

    if(cR || sR) 
        a=MINI((sR+cR)%5, sL, cR, cL, tiefe--);
    if(cR || sL)
        b=MINI(sR, (sL+cR)%5, cR, cL, tiefe--);
    if(cL || sR)
        c=MINI((sR+cL)%5, sL, cR, cL, tiefe--); 
    if(cL || sL)
        d=MINI(sR, (sL+cL)%5, cR, cL, tiefe--);

    if((cL+cR)%2==0) {
        if(sR)
            e=MINI((sR+((cR+cL)/2))%5, sL, (cR+cL)/2, (cR+cL)/2, tiefe--);
        if(sL)
            f=MINI(sR, (sL+((cR+cL)/2))%5, (cR+cL)/2, (cR+cL)/2, tiefe--);
    }

    if(a&gt;b &amp;&amp; a&gt;c &amp;&amp; a&gt;d &amp;&amp; a&gt;e &amp;&amp; a&gt;f)
        return 0;
    if(b&gt;a &amp;&amp; b&gt;c &amp;&amp; b&gt;d &amp;&amp; b&gt;e &amp;&amp; b&gt;f)
        return 1;
    if(c&gt;a &amp;&amp; c&gt;b &amp;&amp; c&gt;d &amp;&amp; c&gt;e &amp;&amp; c&gt;f)
        return 2;
    if(d&gt;a &amp;&amp; d&gt;b &amp;&amp; d&gt;c &amp;&amp; d&gt;e &amp;&amp; d&gt;f)
        return 3;
    if(e&gt;a &amp;&amp; e&gt;b &amp;&amp; e&gt;c &amp;&amp; e&gt;d &amp;&amp; e&gt;f)
        return 4;
    if(f&gt;a &amp;&amp; f&gt;b &amp;&amp; f&gt;c &amp;&amp; f&gt;d &amp;&amp; f&gt;e)
        return 5;
    if(a==b &amp;&amp; a==c &amp;&amp; a==d &amp;&amp; a==e &amp;&amp; a==f)
        return rand()%6;
}

int main()  {
    int sR=1; //Spieler rechte Hand
    int sL=1; //Spieler linke Hand
    int cR=1; //Computer rechte Hand
    int cL=1; //Computer linke Hand
    int zugS=0;
    int zugC=0;

    srand(static_cast&lt;unsigned&gt;(time(NULL)));

    while((sR+sL != 0) &amp;&amp; (cR+cL != 0)) {
        anzeige(sR, sL, cR, cL);
        cout&lt;&lt;&quot;Zug eingeben&quot;&lt;&lt;endl;
        cin.ignore(cin.rdbuf()-&gt;in_avail());
        cin&gt;&gt;zugS;

        switch(zugS) { //Zug des Spielers anwenden...
            case 0: 
                if(sR || cR)
                    cR = (sR+cR)%5;
                else {
                    cout&lt;&lt;&quot;Zug nicht erlaubt.&quot;&lt;&lt;endl;
                    continue; 
                }
                break;
            case 1: 
                if(sL || cR)
                    cR = (sL+cR)%5;
                else {
                    cout&lt;&lt;&quot;Zug nicht erlaubt.&quot;&lt;&lt;endl;
                    continue; 
                } 
                break;
            case 2:
                if(sR || cL)
                    cL = (sR+cL)%5;
                else {
                    cout&lt;&lt;&quot;Zug nicht erlaubt.&quot;&lt;&lt;endl;
                    continue; 
                } 
                break;
            case 3: 
                if(sL || cL)
                    cL = (sL+cL)%5;
                else {
                    cout&lt;&lt;&quot;Zug nicht erlaubt.&quot;&lt;&lt;endl;
                    continue; 
                }
                break;
            case 4:
                if((sL + sR)%2 == 0) {
                    sL=(sL + sR)/2;
                    sR=(sL + sR)/2;
                    continue; //Spieler kann nach Fingertausch noch einen normalen Zug machen
                } else {
                    cout&lt;&lt;&quot;Zug nicht erlaubt!&quot;&lt;&lt;endl;
                    continue;
                }
            default: 
                cout&lt;&lt;&quot;Zug nicht erlaubt.&quot;&lt;&lt;endl;
                continue;
            }

            anzeige(sR, sL, cR, cL);
            zugC=computerZug(sR, sL, cR, cL); //Minimax-Algorithmus

            switch(zugC) { //Zug des Computers anwenden...
            case 0: 
                sR = (cR+sR)%5; 
                break;
            case 1: 
                sR = (cL+sR)%5; 
                break;
            case 2:
                sL = (cR+sL)%5; 
                break;
            case 3: 
                sL = (cL+sL)%5; 
                break;
            case 4:                    
                cL=(cL + cR)/2;
                cR=(cL + cR)/2;
                sR=(cR + cL)%5;
                break;
            case 5:
                cL=(cL + cR)/2;
                cR=(cL + cR)/2;
                sL=(cR + cL)%5;
                break;
            default: 
                cout&lt;&lt;&quot;Fehler im Programm&quot;&lt;&lt;endl;
                wait();
                exit(0);
                break;
            }
      }
}
</code></pre>
<p>Das ist jetzt ein Haufen Code, aber ich wollte es vollständig posten, damit ihr den Fehler nachvollziehen könnt. Das ganze wird nämlich fehlerfrei kompiliert, aber bei der Ausführung stürzt es immer beim Computerzug ab und ich finde die Ursache nicht.<br />
Zweite Sache: Ich habe da ja recht viele unelegante Konstruktionen verwendet, habe aber keine Idee, wie man diese Massen von ifs und dergleichen kürzer und einfacher schreiben könnte. Kann mir jemand weiterhelfen?</p>
<p>Gruß phyll.</p>
<p>edit: Ist der Klammernstil so in Ordnung? Will mir grad sauberes Arbeiten mit 1TBS angewöhnen.</p>
<p>edit2: Sourcecode durtch neuere Version ersetzt</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1426422</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1426422</guid><dc:creator><![CDATA[phyll]]></dc:creator><pubDate>Thu, 27 Dec 2007 21:58:57 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Minimax-Algorithmus on Thu, 27 Dec 2007 11:46:55 GMT]]></title><description><![CDATA[<p>Zuerst einmal die Fehler:</p>
<p>Du deklarierst mittels</p>
<pre><code class="language-cpp">int a=10000;
if(cR || sR)
   int a=MAX(sR, sL, ((cR+sR)%5), cL, tiefe--);
</code></pre>
<p>zwei Variablen namens a, so daß die obere Variable a immer den Wert 10000 behält.<br />
Entferne also (jeweils) das &quot;int&quot; bei der zweiten Variable (d.h. nur eine neue Zuweisung).</p>
<p>Dann als 2.:<br />
Deine beiden Funktionen MINI und MAX arbeiten jeweils mit dem Minimum (statt mit Minimum und Maximum).</p>
<p>Du solltest dir mal die Verbesserung des Minimax-Algorithmus anschauen: NegaMax (s. <a href="http://de.wikipedia.org/wiki/Minimax-Algorithmus" rel="nofollow">http://de.wikipedia.org/wiki/Minimax-Algorithmus</a>)<br />
Dann benötigst du nur noch eine Funktion.</p>
<p>Außerdem sollte dein Computer-Zug einfach den Minimax (bzw. NegaMax) Algorithmus verwenden (anstatt doppelten Code zu haben).</p>
<p>Den besten Zug (Finger) solltest du dann dir innerhalb des Minimax-Algorithmus merken (wobei ich jetzt noch nicht verstanden habe, was die Möglichkeiten 4 bzw. 5 (beim Computer) sind).</p>
<p>Und dann noch zum Schluß:</p>
<pre><code class="language-cpp">continue;
break;
</code></pre>
<p>Das break dort ist sinnlos, da das continue ja schon eine &quot;Sprunganweisung&quot; darstellt.</p>
<p>Schreib das jetzt mal soweit wie möglich um, und dann kannst du ja noch mal nachfragen, falls es imemr noch nicht richtig funktioniert.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1426734</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1426734</guid><dc:creator><![CDATA[Th]]></dc:creator><pubDate>Thu, 27 Dec 2007 11:46:55 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Minimax-Algorithmus on Thu, 27 Dec 2007 16:33:05 GMT]]></title><description><![CDATA[<p>Servus!</p>
<p>1. Den Fahler mit der doppelten Deklaration habe ich schon gestern abend gefunden und behoben.</p>
<p>2. Eventuell habe ich das Konzept des Minimax-Algorithmus falsch verstanden, meiner Meinung nach ist es doch so, dass jeder Knoten jeweils den kleinsten Wert seiner Unterknoten an seinen Überknoten zurückgibt. Der oberste Knoten ComputerZug() muss ja an meine main() nicht den kleinsten Wert zurückgeben, sondern die ID des sinnvollsten Zuges, daher habe ich dafür ne extra Funktion geschrieben.</p>
<p>3. Das mit dem Negamax habe ich gelesen, verstehe aber nicht, wie es funktionieren soll, denn wenn ich einen Zug des Spielers simuliere, muss ich ja berücksichtigen, dass der Spieler andere Züge mit ganz anderen Wirkungen macht, als der Computer. Wie geht das, wen ich nur eine Funktion habe?</p>
<p>4. Die Möglichkeiten 4 und 5 resulieren daher, dass man, wenn man eine gerade Anzahl Finger hat, so tauschen kann, dass beide Hände gleich viele Finger haben. (Das hatte ich beim Spieler noch vergessen)</p>
<p>5. Das mit break und continue wird gleich behoben, wird aber wohl kaum die Ursache meines Fehlers sein. Der Debugger sagt, es sei ein Segmentation Fault beim Aufruf von MINI()</p>
<p>Gruß und danke, phyll</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1426903</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1426903</guid><dc:creator><![CDATA[phyll]]></dc:creator><pubDate>Thu, 27 Dec 2007 16:33:05 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Minimax-Algorithmus on Fri, 28 Dec 2007 13:11:18 GMT]]></title><description><![CDATA[<p>Einen Fehler habe ich noch:<br />
statt &quot;tiefe--&quot; solltest du &quot;tiefe - 1&quot; beim Aufruf von MINI bzw. MAX nehmen.</p>
<p>Ich nehme an, du hast einen Stack-Overflow produziert, ansonsten steppe einfach mit deinem Debugger durch die Funktionen und schau nach, wo er den Runtime-Fehler verursacht (einen anderen Grund für einen &quot;segmentation error&quot; sehe ich nicht, da du ja keine Zeiger verwendest).</p>
<blockquote>
<p>Der oberste Knoten ComputerZug() muss ja an meine main() nicht den kleinsten Wert zurückgeben, sondern die ID des sinnvollsten Zuges, daher habe ich dafür ne extra Funktion geschrieben.</p>
</blockquote>
<p>Ja, das stimmt schon, aber trotzdem hast du ja den Code dupliziert (d.h. daraus könntest du dann eine eigene Funktion machen).</p>
<p>Der Negamax Algorithmus interpretiert das Ergebnis des gegenerischen Zugs einfach als negativen Wert (je besser der Gegner, desto schlechter für mich und umgekehrt):</p>
<pre><code class="language-cpp">int Negamax(int sR, int sL, int cR, int cL, int tiefe)
{
  ...
  a = -Negamax(sR, sL, ((cR+sR)%5), cL, tiefe-1);
  ...
}
</code></pre>
<p>Wenn du doch deine 2 Funktionen nutzen willst, dann solltest du in MAX aber alle Variablen auf &quot;-10000 setzen&quot; (so wie beim Computer-Zug).</p>
<p>P.S: Ich bin kein Freund des K&amp;R Klammerstils, aber ansonsten sieht es lesbar aus...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1427214</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1427214</guid><dc:creator><![CDATA[Th]]></dc:creator><pubDate>Fri, 28 Dec 2007 13:11:18 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Minimax-Algorithmus on Sat, 29 Dec 2007 12:25:56 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>habe jetzt tiefe-1 statt tiefe-- eingebaut, immer noch das gleiche Problem. Mehr als dass der Speicherfehler beim Aufruf von MINI() auftritt, sagt mir der Debugger nicht. Bin mittlerweile einigermaßen ratlos, hat irgendjemand noch ne Idee?</p>
<p>phyll</p>
<p>edit: Hatte einmal das &quot;tiefe--&quot; übersehen, das war es wohl, was den overflow produzierte. Jetzt ist das Problem behoben, danke!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1427518</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1427518</guid><dc:creator><![CDATA[phyll]]></dc:creator><pubDate>Sat, 29 Dec 2007 12:25:56 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Minimax-Algorithmus on Sat, 29 Dec 2007 12:28:36 GMT]]></title><description><![CDATA[<p>Lerne, den Debugger zu nutzen</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1427580</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1427580</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Sat, 29 Dec 2007 12:28:36 GMT</pubDate></item></channel></rss>