Go Fish/C++: Difference between revisions

m
Fixed syntax highlighting.
(Created page with "=={{header|C++}}== <lang cpp> #include <time.h> #include <map> #include <vector> #include <algorithm> #include <string> #include <iostream> const std::string s = "CDHS", v = ...")
 
m (Fixed syntax highlighting.)
 
(3 intermediate revisions by 2 users not shown)
Line 1:
{{collection|Go_Fish}}
=={{header|C++}}==
AI is really not that clever but it gets its job done (well, pretty much!).
<lang cpp>
 
It follows three simple rules:
* 75% the times it remembers cards asked by its opponent, and asks for the first one it also has.
* ask for a card it fished in the last round, if its different from all its other cards
* cycles thru all its cards, asking for them.
 
As I said, simple...
 
 
<span style='font-family: "Linux Libertine",Georgia,Times,serif;font-size:150%;'>[[C++]]</span><hr>
<syntaxhighlight lang="cpp">
#include <time.h>
#include <map>
Line 161 ⟶ 172:
c = hand[askedIdx].getRank();
if( rand() % 100 > 25 && asked.size() ) {
for( std::vector<char>::iterator dit = asked[rand.begin(); %it != asked.sizeend()]; it++ ) {
if( holds( d*it ) ) c = d;{
c = ( *it );
break;
}
}
}
}
Line 299 ⟶ 314:
return 0;
}
</syntaxhighlight>
</lang>
9,476

edits