https://wiki.wesnoth.org/index.php?title=GCI/Recruitment&feed=atom&action=history
GCI/Recruitment - Revision history
2024-03-29T09:09:21Z
Revision history for this page on the wiki
MediaWiki 1.31.16
https://wiki.wesnoth.org/index.php?title=GCI/Recruitment&diff=40534&oldid=prev
Aethaeryn: categorizing
2011-03-06T03:03:58Z
<p>categorizing</p>
<table class="diff diff-contentalign-left" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #222; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #222; text-align: center;">Revision as of 03:03, 6 March 2011</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l116" >Line 116:</td>
<td colspan="2" class="diff-lineno">Line 116:</td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>         return 0;</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>         return 0;</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>  }</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>  }</div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"></ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">[[Category: GCI]]</ins></div></td></tr>
</table>
Aethaeryn
https://wiki.wesnoth.org/index.php?title=GCI/Recruitment&diff=38959&oldid=prev
Crab: Created page with ' #include <string> #include <vector> #include <algorithm> #include <iostream> class potential_recruit { public: potential_recruit(const std::string &name, int cost,…'
2010-11-22T15:36:51Z
<p>Created page with ' #include <string> #include <vector> #include <algorithm> #include <iostream> class potential_recruit { public: potential_recruit(const std::string &name, int cost,…'</p>
<p><b>New page</b></p><div> #include <string><br />
#include <vector><br />
#include <algorithm><br />
#include <iostream><br />
class potential_recruit<br />
{<br />
public:<br />
potential_recruit(const std::string &name, int cost, double quality, int max_qty)<br />
: name_(name), cost_(cost), quality_(quality), max_qty_(max_qty)<br />
{}<br />
const std::string& name() const<br />
{<br />
return name_;<br />
}<br />
int cost() const<br />
{<br />
return cost_;<br />
}<br />
int quality() const<br />
{<br />
return quality_;<br />
}<br />
int max_qty() const<br />
{<br />
return max_qty_;<br />
}<br />
private:<br />
std::string name_;<br />
int cost_;<br />
double quality_;<br />
int max_qty_;<br />
};<br />
class team<br />
{<br />
public:<br />
int gold()<br />
{<br />
return gold_;<br />
}<br />
void set_gold(int gold)<br />
{<br />
gold_ = gold;<br />
}<br />
void add_unit(const std::string &unit)<br />
{<br />
units_.push_back(unit);<br />
}<br />
const std::vector<std::string>& units()<br />
{<br />
return units_;<br />
}<br />
int get_current_qty(const potential_recruit &r) const<br />
{<br />
return get_current_qty(r.name());<br />
}<br />
int get_current_qty(const std::string &name) const<br />
{<br />
return std::count(units_.begin(), units_.end(), name);<br />
}<br />
void spend_gold(int gold)<br />
{<br />
gold_-=gold;<br />
}<br />
private:<br />
int gold_;<br />
std::vector<std::string> units_;<br />
};<br />
/** this is the function to call to do 1 recruit when you've selected it */<br />
static void recruit(team &t, const potential_recruit &r)<br />
{<br />
if (t.gold()<r.cost()) {<br />
std::cerr << "ERROR: cannot recruit "<<r.name()<<", not enough gold"<< std::endl;<br />
exit(-1);<br />
}<br />
if (t.get_current_qty(r)>=r.max_qty()) {<br />
std::cerr << "ERROR: cannot recruit "<<r.name()<<", too many in the field"<< std::endl;<br />
exit(-1);<br />
}<br />
std::cout << " Recruiting [" << r.name() << "]" << std::endl;<br />
t.spend_gold(r.cost());<br />
t.add_unit(r.name());<br />
}<br />
void expect(const team &t, const std::string &name, int qty)<br />
{<br />
int current_qty = t.get_current_qty(name);<br />
if (current_qty != qty) {<br />
std::cerr << "ERROR: wrong number of ["<< name << "], expected "<<qty<<" but got "<< current_qty << std::endl;<br />
exit(-2);<br />
} else {<br />
std::cerr << "OK: count of ["<< name << "] is "<< current_qty<< std::endl;<br />
}<br />
}<br />
static void ai_choose_recruits(team &t, int max_units_to_recruit, double quality_factor, const std::vector<potential_recruit> &recruit_list)<br />
{<br />
/* TODO: code your implementation here */<br />
recruit(t,recruit_list.at(1));//Royal Guard<br />
recruit(t,recruit_list.at(1));//Royal Guard<br />
recruit(t,recruit_list.at(0));//Spearman<br />
recruit(t,recruit_list.at(0));//Spearman<br />
recruit(t,recruit_list.at(0));//Spearman<br />
}<br />
int main()<br />
{<br />
//a small testcase<br />
team t;<br />
t.set_gold(120);<br />
t.add_unit("Spearman");<br />
std::vector<potential_recruit> recruit_list;<br />
recruit_list.push_back(potential_recruit("Spearman", 13, 12.6 ,10));<br />
recruit_list.push_back(potential_recruit("Royal Guard", 30, 40.0, 2));<br />
expect(t,"Spearman", 1);<br />
expect(t,"Royal Guard", 0);<br />
ai_choose_recruits(t, 5, 1.0, recruit_list);<br />
expect(t,"Spearman", 4);<br />
expect(t,"Royal Guard", 2);<br />
return 0;<br />
}</div>
Crab