<?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[Bringe Minigame Ki nicht zusammen]]></title><description><![CDATA[<p>Hallo Leute!<br />
önntet ihr mir Bitte bei der Ki meines Computer gegners helfen?<br />
Er soll eine gewisse Anzahl an Münzen intelligent auswählen.<br />
Hier ist der Code:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;windows.h&gt;
#define COINS 80
using namespace std;

int TakeAI(int Count)
{
  if(Count&gt;2&amp;&amp;Count&lt;5)return 3;
  if(Count&gt;4&amp;&amp;Count&lt;7)return 5;
  if(Count&gt;6&amp;&amp;Count&lt;10)return 7;
  if(TakeAI(Count-3)==3)return 3;
  if(TakeAI(Count-5)==5)return 5;
  if(TakeAI(Count-7)==7)return 7;
  else return 3;
}

void SetColor(int color)
{
  HANDLE hcon = GetStdHandle(STD_OUTPUT_HANDLE);
  SetConsoleTextAttribute(hcon, color);
} 

void Rules()
{
  SetColor(4);
  cout &lt;&lt; &quot;Willkommen in meinem Spiel!&quot; &lt;&lt; endl;
  cout &lt;&lt; &quot;Sie spielen gegen den Computer.&quot; &lt;&lt; endl;    
  cout &lt;&lt; &quot;Am Anfang ist eine gewisse Anzahl an Muenzen im Topf.&quot; &lt;&lt; endl;
  cout &lt;&lt; &quot;Jeden Zug nimmt der jeweilige Spieler entweder 3, 5 oder 7 Muenzen.&quot; &lt;&lt; endl;
  cout &lt;&lt; &quot;Der Spieler der keine Muenzen mehr nehmen kann hat verloren!&quot; &lt;&lt; endl;
  cout &lt;&lt; &quot;Viel Spass noch!\n&quot; &lt;&lt; endl;
  SetColor(7);
}

bool Starter()
{
  char starter;
  SetColor(2);
  cout &lt;&lt; &quot;Wollen Sie das Spiel beginnen?(y/n) &quot;; 
  cin &gt;&gt; starter;
  SetColor(7);
  if(starter=='y'||starter=='Y')
  {
    return 1;
  }
  else
  {
    return 0;
  } 
}

int Take()
{
  int choice;
  cin &gt;&gt; choice;
  while(!(choice==3||choice==5||choice==7))
  {
    cout &lt;&lt; &quot;Die Zahl muss entweder 3, 5 oder 7 sein!&quot; &lt;&lt; endl;
    cout &lt;&lt; &quot;Wieviele Muenzen wollen Sie vom Topf nehmen? &quot;;
    cin &gt;&gt; choice;
  }
  return choice;                             
}

int GetCount()
{
  SetColor(3);
  cout &lt;&lt; &quot;Die Anzahl der Muenzen ist: &quot; &lt;&lt; COINS &lt;&lt; &quot;\n&quot;;
  SetColor(7);
}

void Play()
{
  GetCount();
  int Count = COINS;
  bool Turn = Starter();
  int taken = 0;
  while(Count&gt;2)
  {
    if(Turn==1)
    {
      SetColor(6);
      cout &lt;&lt; &quot;\nEs befinden sich noch &quot; &lt;&lt; Count &lt;&lt; &quot; Muenzen im Topf.\n&quot; &lt;&lt; endl;
      SetColor(10);
      cout &lt;&lt; &quot;Sie sind am Zug.&quot; &lt;&lt; endl;
      cout &lt;&lt; &quot;Wie viele Muenzen wollen Sie vom Topf nehmen? &quot;;
      taken = Take();
      Count -= taken;
      Turn=0;
      if(Count&lt;=2)
      {
        SetColor(6);
        cout &lt;&lt; &quot;\nEs befinden sich noch &quot; &lt;&lt; Count &lt;&lt; &quot; Muenzen im Topf.\n&quot; &lt;&lt; endl;
        SetColor(4);
        cout &lt;&lt; &quot;\nSie haben das Spiel gewonnen!\n&quot; &lt;&lt; endl;
        SetColor(7);
        system(&quot;PAUSE&quot;);
      } 
    }
    if(Turn==0)
    {
      SetColor(6);
      cout &lt;&lt; &quot;\nEs befinden sich noch &quot; &lt;&lt; Count &lt;&lt; &quot; Muenzen im Topf.\n&quot; &lt;&lt; endl;
      SetColor(11);
      cout &lt;&lt; &quot;Der Computer ist am Zug.&quot; &lt;&lt; endl;
      cout &lt;&lt; &quot;Wie viele Muenzen wollen Sie vom Topf nehmen? &quot;;
      taken = TakeAI(Count);
      cout &lt;&lt; taken &lt;&lt; endl;
      Count -= taken;
      Turn=1;  
      if(Count&lt;=2)
      {
        SetColor(6);
        cout &lt;&lt; &quot;\nEs befinden sich noch &quot; &lt;&lt; Count &lt;&lt; &quot; Muenzen im Topf.\n&quot; &lt;&lt; endl;
        SetColor(4);
        cout &lt;&lt; &quot;\nSie haben das Spiel verloren!\n&quot; &lt;&lt; endl;
        SetColor(7);
        system(&quot;PAUSE&quot;);
      }       
    }        
  }
}

int main()
{
  Rules();
  Play();
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/182574/bringe-minigame-ki-nicht-zusammen</link><generator>RSS for Node</generator><lastBuildDate>Wed, 23 Sep 2026 00:09:02 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/182574.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 26 May 2007 19:31:19 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Bringe Minigame Ki nicht zusammen on Sat, 26 May 2007 19:31:19 GMT]]></title><description><![CDATA[<p>Hallo Leute!<br />
önntet ihr mir Bitte bei der Ki meines Computer gegners helfen?<br />
Er soll eine gewisse Anzahl an Münzen intelligent auswählen.<br />
Hier ist der Code:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;windows.h&gt;
#define COINS 80
using namespace std;

int TakeAI(int Count)
{
  if(Count&gt;2&amp;&amp;Count&lt;5)return 3;
  if(Count&gt;4&amp;&amp;Count&lt;7)return 5;
  if(Count&gt;6&amp;&amp;Count&lt;10)return 7;
  if(TakeAI(Count-3)==3)return 3;
  if(TakeAI(Count-5)==5)return 5;
  if(TakeAI(Count-7)==7)return 7;
  else return 3;
}

void SetColor(int color)
{
  HANDLE hcon = GetStdHandle(STD_OUTPUT_HANDLE);
  SetConsoleTextAttribute(hcon, color);
} 

void Rules()
{
  SetColor(4);
  cout &lt;&lt; &quot;Willkommen in meinem Spiel!&quot; &lt;&lt; endl;
  cout &lt;&lt; &quot;Sie spielen gegen den Computer.&quot; &lt;&lt; endl;    
  cout &lt;&lt; &quot;Am Anfang ist eine gewisse Anzahl an Muenzen im Topf.&quot; &lt;&lt; endl;
  cout &lt;&lt; &quot;Jeden Zug nimmt der jeweilige Spieler entweder 3, 5 oder 7 Muenzen.&quot; &lt;&lt; endl;
  cout &lt;&lt; &quot;Der Spieler der keine Muenzen mehr nehmen kann hat verloren!&quot; &lt;&lt; endl;
  cout &lt;&lt; &quot;Viel Spass noch!\n&quot; &lt;&lt; endl;
  SetColor(7);
}

bool Starter()
{
  char starter;
  SetColor(2);
  cout &lt;&lt; &quot;Wollen Sie das Spiel beginnen?(y/n) &quot;; 
  cin &gt;&gt; starter;
  SetColor(7);
  if(starter=='y'||starter=='Y')
  {
    return 1;
  }
  else
  {
    return 0;
  } 
}

int Take()
{
  int choice;
  cin &gt;&gt; choice;
  while(!(choice==3||choice==5||choice==7))
  {
    cout &lt;&lt; &quot;Die Zahl muss entweder 3, 5 oder 7 sein!&quot; &lt;&lt; endl;
    cout &lt;&lt; &quot;Wieviele Muenzen wollen Sie vom Topf nehmen? &quot;;
    cin &gt;&gt; choice;
  }
  return choice;                             
}

int GetCount()
{
  SetColor(3);
  cout &lt;&lt; &quot;Die Anzahl der Muenzen ist: &quot; &lt;&lt; COINS &lt;&lt; &quot;\n&quot;;
  SetColor(7);
}

void Play()
{
  GetCount();
  int Count = COINS;
  bool Turn = Starter();
  int taken = 0;
  while(Count&gt;2)
  {
    if(Turn==1)
    {
      SetColor(6);
      cout &lt;&lt; &quot;\nEs befinden sich noch &quot; &lt;&lt; Count &lt;&lt; &quot; Muenzen im Topf.\n&quot; &lt;&lt; endl;
      SetColor(10);
      cout &lt;&lt; &quot;Sie sind am Zug.&quot; &lt;&lt; endl;
      cout &lt;&lt; &quot;Wie viele Muenzen wollen Sie vom Topf nehmen? &quot;;
      taken = Take();
      Count -= taken;
      Turn=0;
      if(Count&lt;=2)
      {
        SetColor(6);
        cout &lt;&lt; &quot;\nEs befinden sich noch &quot; &lt;&lt; Count &lt;&lt; &quot; Muenzen im Topf.\n&quot; &lt;&lt; endl;
        SetColor(4);
        cout &lt;&lt; &quot;\nSie haben das Spiel gewonnen!\n&quot; &lt;&lt; endl;
        SetColor(7);
        system(&quot;PAUSE&quot;);
      } 
    }
    if(Turn==0)
    {
      SetColor(6);
      cout &lt;&lt; &quot;\nEs befinden sich noch &quot; &lt;&lt; Count &lt;&lt; &quot; Muenzen im Topf.\n&quot; &lt;&lt; endl;
      SetColor(11);
      cout &lt;&lt; &quot;Der Computer ist am Zug.&quot; &lt;&lt; endl;
      cout &lt;&lt; &quot;Wie viele Muenzen wollen Sie vom Topf nehmen? &quot;;
      taken = TakeAI(Count);
      cout &lt;&lt; taken &lt;&lt; endl;
      Count -= taken;
      Turn=1;  
      if(Count&lt;=2)
      {
        SetColor(6);
        cout &lt;&lt; &quot;\nEs befinden sich noch &quot; &lt;&lt; Count &lt;&lt; &quot; Muenzen im Topf.\n&quot; &lt;&lt; endl;
        SetColor(4);
        cout &lt;&lt; &quot;\nSie haben das Spiel verloren!\n&quot; &lt;&lt; endl;
        SetColor(7);
        system(&quot;PAUSE&quot;);
      }       
    }        
  }
}

int main()
{
  Rules();
  Play();
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1292817</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1292817</guid><dc:creator><![CDATA[Dr_Gregor]]></dc:creator><pubDate>Sat, 26 May 2007 19:31:19 GMT</pubDate></item><item><title><![CDATA[Reply to Bringe Minigame Ki nicht zusammen on Sat, 26 May 2007 20:34:07 GMT]]></title><description><![CDATA[<p>Was willst du jetzt genau?<br />
Davon abgesehen dass GetCount() nichts zurückliefert schauts eh nicht schlecht aus...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1292850</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1292850</guid><dc:creator><![CDATA[Kuldren]]></dc:creator><pubDate>Sat, 26 May 2007 20:34:07 GMT</pubDate></item><item><title><![CDATA[Reply to Bringe Minigame Ki nicht zusammen on Sat, 26 May 2007 22:31:19 GMT]]></title><description><![CDATA[<p>Um im letzten Zug gewinnen zu können muss man 3 bis 9 Münzen haben:</p>
<p>3: ich nehme 3 -&gt; bleiben 0 -&gt; gewonnen<br />
4: ich nehme 3 -&gt; bleiben 1 -&gt; gewonnen<br />
5: ich nehme 5 -&gt; bleiben 0 -&gt; gewonnen<br />
6: ich nehme 5 -&gt; bleiben 1 -&gt; gewonnen<br />
7: ich nehme 7 -&gt; bleiben 0 -&gt; gewonnen<br />
8: ich nehme 7 -&gt; bleiben 1 -&gt; gewonnen<br />
9: ich nehme 7 -&gt; bleiben 2 -&gt; gewonnen</p>
<p>Um im letzten Zug verlieren zu müssen (wenn der Gegner optimal spielt) muss man 10 bis 12 Münzen haben:<br />
10: ich kann 3-7 Münzen nehmen, führt zu 3-7 für den Gegner -&gt; Gegner kann gewinnen (siehe oben)<br />
11: ich kann 3-7 Münzen nehmen, führt zu 4-8 für den Gegner -&gt; Gegner kann gewinnen<br />
12: ich kann 3-7 Münzen nehmen, führt zu 5-9 für den Gegner -&gt; Gegner kann gewinnen</p>
<p>Ab 13 kann ich wieder fix gewinnen, indem ich 3 nehme, bleiben den Gegner 10 -&gt; er muss verlieren (siehe oben).<br />
14 -&gt; ich nehme 3 -&gt; 11 -&gt; Gegner muss verlieren<br />
15 -&gt; ich nehme 5 -&gt; 10 -&gt; Gegner muss verlieren<br />
16 -&gt; ich nehme 5 -&gt; 11 -&gt; Gegner muss verlieren<br />
17 -&gt; ich nehme 7 -&gt; 10 -&gt; Gegner muss verlieren<br />
18 -&gt; ich nehme 7 -&gt; 11 -&gt; Gegner muss verlieren<br />
19 -&gt; ich nehme 7 -&gt; 12 -&gt; Gegner muss verlieren</p>
<p>Und hier sollte einem jetzt ein Muster auffallen.</p>
<p>Der Trick dabei ist einfach zu sehen dass man dem Gegner eine Anzahl an Münzen hinlegt die mit 0 1 oder 2 aufhört (die Stellen davor sind egal).<br />
Angenommen ich spiele so dass nach meinem Zug 101 Münzen übrig bleiben, dann habe ich schon gewonnen: nimmt der Gegner 3 nehme ich 7, nimmt der Gegner 5 nehme ich auch 5, nimmt der Gegner 7 nehme ich 3. Die Summe beider Züge ist immer 10, und nach meinem nächsten Zug hat der Genger es mit 91 Münzen zu tun. Dann 81, 71, ..... 11, 1 -&gt; Gegner hat verloren.</p>
<p>Daraus lässt sich schnell eine Funktion formulieren:</p>
<pre><code class="language-cpp">int TakeAI(int Count)
{
    assert(Count &gt;= 3);
    switch(Count % 10)
    {
    case 0:
    case 1:
    case 2:
        // Hier ist es im Prinzip egal was wir tun, da wir (wenn der Gegner optimal spielt) schon verloren haben.
        return 3;

    case 3:
    case 4:
        return 3;
    case 5:
    case 6:
        return 5;
    case 7:
    case 8:
    case 9:
        return 7;
    }
}
</code></pre>
<p>Um das ganze etwas weniger transparent und offensichtlich zu machen könnte man bei &quot;case 5&quot; hin und wieder auch nur 3 Münzen nehmen, und bei &quot;case 7&quot; hin und wieder nur 5. Genauso könnte man bei 0-2 zufällig entscheiden.<br />
Gegen menschliche Spieler wäre das sicher sinnvoll, da dadurch wie gesagt die Strategie nicht so schnell offensichtlich wird.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1292907</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1292907</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Sat, 26 May 2007 22:31:19 GMT</pubDate></item><item><title><![CDATA[Reply to Bringe Minigame Ki nicht zusammen on Sun, 27 May 2007 06:32:47 GMT]]></title><description><![CDATA[<p>Vielen Dank für die schnelle Antwort!<br />
Aber eine Frage noch: was bringt die Funktion assert?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1292944</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1292944</guid><dc:creator><![CDATA[Dr_Gregor]]></dc:creator><pubDate>Sun, 27 May 2007 06:32:47 GMT</pubDate></item><item><title><![CDATA[Reply to Bringe Minigame Ki nicht zusammen on Sun, 27 May 2007 07:17:22 GMT]]></title><description><![CDATA[<p>Hallo</p>
<p><a href="http://www.cppreference.com/stdother/assert.html" rel="nofollow">assert</a></p>
<p>bis bald<br />
akari</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1292950</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1292950</guid><dc:creator><![CDATA[akari]]></dc:creator><pubDate>Sun, 27 May 2007 07:17:22 GMT</pubDate></item></channel></rss>