<?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[declaration of &#96;taktiken&#x27; as array of functions]]></title><description><![CDATA[<p>Das gab er mir als Fehler zurück, dabei wollte ich doch gerade das erreichen.<br />
Code:</p>
<pre><code class="language-cpp">bool taktiken[]() = {taktik1,taktik2,taktik3,taktik4};
  srand(time(NULL));
  long guthaben[] = {0,0,0,0};
  int MSchlecht,MGut,Verlust,Gewinn;

  for(int i=0;i&lt;10000;++i) {
    MSchlecht=rand();
    MGut     =rand();
    Verlust  =rand();
    Gewinn   =rand();
    for(char spieler=0;i&lt;4;++spieler) {
      if(taktiken[spieler](Verlust,Gewinn,MSchlecht,MGut)) {
        if gewonnen(MSchlecht,MGut) {
          guthaben[spieler] += Gewinn;
        } else {
          guthaben[spieler] -= Verlust;
        }
      }
    }
  }
</code></pre>
<p>...</p>
<pre><code class="language-cpp">bool taktik1(int Verlust, int Gewinn, int MoeglSchlecht, int MoeglGut) {
  //draufgänger
  return true;
};

bool taktik2(int Verlust, int Gewinn, int MoeglSchlecht, int MoeglGut) {
  //Angsthase:
  return false;
};

//...
</code></pre>
<p>Wie kann man ein Array aus Funktionen machen?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/171623/declaration-of-taktiken-as-array-of-functions</link><generator>RSS for Node</generator><lastBuildDate>Thu, 17 Sep 2026 12:17:13 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/171623.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 27 Jan 2007 15:59:51 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to declaration of &#96;taktiken&#x27; as array of functions on Sat, 27 Jan 2007 16:13:33 GMT]]></title><description><![CDATA[<p>Das gab er mir als Fehler zurück, dabei wollte ich doch gerade das erreichen.<br />
Code:</p>
<pre><code class="language-cpp">bool taktiken[]() = {taktik1,taktik2,taktik3,taktik4};
  srand(time(NULL));
  long guthaben[] = {0,0,0,0};
  int MSchlecht,MGut,Verlust,Gewinn;

  for(int i=0;i&lt;10000;++i) {
    MSchlecht=rand();
    MGut     =rand();
    Verlust  =rand();
    Gewinn   =rand();
    for(char spieler=0;i&lt;4;++spieler) {
      if(taktiken[spieler](Verlust,Gewinn,MSchlecht,MGut)) {
        if gewonnen(MSchlecht,MGut) {
          guthaben[spieler] += Gewinn;
        } else {
          guthaben[spieler] -= Verlust;
        }
      }
    }
  }
</code></pre>
<p>...</p>
<pre><code class="language-cpp">bool taktik1(int Verlust, int Gewinn, int MoeglSchlecht, int MoeglGut) {
  //draufgänger
  return true;
};

bool taktik2(int Verlust, int Gewinn, int MoeglSchlecht, int MoeglGut) {
  //Angsthase:
  return false;
};

//...
</code></pre>
<p>Wie kann man ein Array aus Funktionen machen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1218121</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1218121</guid><dc:creator><![CDATA[obbba]]></dc:creator><pubDate>Sat, 27 Jan 2007 16:13:33 GMT</pubDate></item><item><title><![CDATA[Reply to declaration of &#96;taktiken&#x27; as array of functions on Sat, 27 Jan 2007 17:00:27 GMT]]></title><description><![CDATA[<p>probiers mal mit</p>
<pre><code class="language-cpp">typdef (bool(*TAKTIK))(int Verlust, int Gewinn, int MoeglSchlecht, int MoeglGut);
TAKTIKEN[] = {taktik1,taktik2,taktik3,....,taktikn};
</code></pre>
<p>Der Code ist nicht getestet im grunde ist das ein array aus zeigern auf boolfunktionen mit eben dem aussehen was du dur wünschst.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1218171</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1218171</guid><dc:creator><![CDATA[Fedaykin]]></dc:creator><pubDate>Sat, 27 Jan 2007 17:00:27 GMT</pubDate></item><item><title><![CDATA[Reply to declaration of &#96;taktiken&#x27; as array of functions on Sat, 27 Jan 2007 23:35:39 GMT]]></title><description><![CDATA[<p>Es funktioniert weder, noch verstehe ich es.</p>
<p>Wenn ich es so mache:</p>
<pre><code class="language-cpp">int main(int argc, char *argv[]) {
  void* taktiken[] = {(void*)taktik1,(void*)taktik2,(void*)taktik3,(void*)taktik4};
  /*typdef (bool(*))(int Verlust, int Gewinn, int MoeglSchlecht, int MoeglGut); 
  taktiken[] = {taktik1,taktik2,taktik3}; */
  srand(time(NULL));
  int guthaben[] = {0,0,0,0};
  unsigned int MSchlecht,MGut,Verlust,Gewinn;

  for(int i=0;i&lt;10000;++i) {
    MSchlecht=rand();
    MGut     =rand();
    Verlust  =rand();
    Gewinn   =rand();
    for(char spieler=0;i&lt;4;++spieler) {
      if((taktiken[spieler])(Verlust,Gewinn,MSchlecht,MGut)) {
        if gewonnen(MSchlecht,MGut) {
          guthaben[spieler] += Gewinn;

//...
</code></pre>
<p>Sagt er, dass er taktiken[] nicht als Funktion benutzen kann.</p>
<blockquote>
<p>`taktiken[((int)spieler)]' cannot be used as a function</p>
</blockquote>
<p><strong>Was ist denn der Typ von einer Funktion?</strong><br />
Wahrscheinlich irgend eine Art von Zeiger, aber welche?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1218407</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1218407</guid><dc:creator><![CDATA[obbba]]></dc:creator><pubDate>Sat, 27 Jan 2007 23:35:39 GMT</pubDate></item><item><title><![CDATA[Reply to declaration of &#96;taktiken&#x27; as array of functions on Sat, 27 Jan 2007 23:16:11 GMT]]></title><description><![CDATA[<p>Probier es so:</p>
<pre><code class="language-cpp">typedef bool (*Taktik)(int, int, int, int);
Taktik taktiken[] = {taktik1,taktik2,taktik3,taktik4};
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1218408</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1218408</guid><dc:creator><![CDATA[LordJaxom]]></dc:creator><pubDate>Sat, 27 Jan 2007 23:16:11 GMT</pubDate></item><item><title><![CDATA[Reply to declaration of &#96;taktiken&#x27; as array of functions on Sat, 27 Jan 2007 23:32:58 GMT]]></title><description><![CDATA[<p>OK. Danke, das klappt.<br />
Jetzt habe ich ein anderes Problem:</p>
<p>Projekt1.exe schrieb:</p>
<blockquote>
<p>Projekt1.exe hat ein Problem festgestellt und muss beendet werden.</p>
</blockquote>
<p>Ich denke, das hat was mit zeigern zu tun.<br />
Oder mit der falschen Benutzung von den Zufallsfunktionen.</p>
<p>Ich hab mal gehört, das, wenn man rand() mit Modulo aufruft, die Ergebnisse nicht gleichmäßig verteilt sind, und das leuchtet mir auch ein. Deshalb die große &quot;Ergebnis-Spanne&quot;.</p>
<p>Kompletter Code:</p>
<pre><code class="language-cpp">#include &lt;cstdlib&gt;
#include &lt;iostream&gt;

using namespace std;

//geht der Spieler das Risiko ein?
bool taktik1(int Verlust, int Gewinn, int MoeglSchlecht, int MoeglGut);
bool taktik2(int Verlust, int Gewinn, int MoeglSchlecht, int MoeglGut);
bool taktik3(int Verlust, int Gewinn, int MoeglSchlecht, int MoeglGut);
bool taktik4(int Verlust, int Gewinn, int MoeglSchlecht, int MoeglGut);

//kommt ein positives Ergebnis raus?
bool gewonnen(int MoeglSchlecht, int MoeglGut);

int main(int argc, char *argv[]) {
  //void* taktiken[] = {(void*)taktik1,(void*)taktik2,(void*)taktik3,(void*)taktik4};
  typedef bool (*Taktik)(int, int, int, int); 
  Taktik taktiken[] = {taktik1,taktik2,taktik3,taktik4};
  srand(time(NULL));
  int guthaben[] = {0,0,0,0};
  int MSchlecht,MGut,Verlust,Gewinn;

  for(int i=0;i&lt;100;++i) {
    MSchlecht=rand();
    MGut     =rand();
    Verlust  =rand();
    Gewinn   =rand();
    for(char spieler=0;i&lt;4;++spieler) {
      if((taktiken[spieler])(Verlust,Gewinn,MSchlecht,MGut)) {
        if (gewonnen(MSchlecht,MGut)) {
          guthaben[spieler] += Gewinn;
        } else {
          guthaben[spieler] -= Verlust;
        }
      }
    }
  }      
  for(char sp=1;sp&lt;4;++sp)
    cout&lt;&lt;&quot;Nr.&quot;&lt;&lt;sp&lt;&lt;&quot; hat &quot;&lt;&lt;guthaben[sp]&lt;&lt;endl;

  system(&quot;PAUSE&quot;);
  return EXIT_SUCCESS;
};

bool gewonnen(int MoeglSchlecht, int MoeglGut) {
  long Moegl = MoeglSchlecht+MoeglGut;
  double faktor = 4294967296/Moegl;
  if((rand()*faktor)&lt;MoeglSchlecht)
    return true;
  return false;
};

bool taktik1(int Verlust, int Gewinn, int MoeglSchlecht, int MoeglGut) {
  return true;
};

bool taktik2(int Verlust, int Gewinn, int MoeglSchlecht, int MoeglGut) {
  return true;
};
bool taktik3(int Verlust, int Gewinn, int MoeglSchlecht, int MoeglGut) {
  return true;
};

bool taktik4(int Verlust, int Gewinn, int MoeglSchlecht, int MoeglGut) {
  return true;
};
</code></pre>
<p>Später will ich damit testen, mit welcher Taktik man am erfolgreichsten ist. Im Moment sind noch alle Spieler &quot;Draufgänger&quot;.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1218409</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1218409</guid><dc:creator><![CDATA[obbba]]></dc:creator><pubDate>Sat, 27 Jan 2007 23:32:58 GMT</pubDate></item><item><title><![CDATA[Reply to declaration of &#96;taktiken&#x27; as array of functions on Sat, 27 Jan 2007 23:44:27 GMT]]></title><description><![CDATA[<p>Vergesst es...<br />
Mit den Zufallszahlen muss ich mich nochmal selbst näher befassen.<br />
<img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /></p>
<p>Ich muss den Bereich kleiner kriegen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1218415</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1218415</guid><dc:creator><![CDATA[obbba]]></dc:creator><pubDate>Sat, 27 Jan 2007 23:44:27 GMT</pubDate></item><item><title><![CDATA[Reply to declaration of &#96;taktiken&#x27; as array of functions on Sun, 28 Jan 2007 07:45:29 GMT]]></title><description><![CDATA[<p>Gerade Zufaellig aufgrund eines Hinweises von CStoll mir mal die Signatur von TactX genauer angesehen. bez. der Zufallszahlen kann dir das vielleicht helfen: <a href="http://eternallyconfuzzled.com/arts/jsw_art_rand.aspx" rel="nofollow">http://eternallyconfuzzled.com/arts/jsw_art_rand.aspx</a> .</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1218451</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1218451</guid><dc:creator><![CDATA[Shinja]]></dc:creator><pubDate>Sun, 28 Jan 2007 07:45:29 GMT</pubDate></item></channel></rss>