CSC112 Spring 2016 Examples
// The alpaca arena!1// It goes without saying, you are not allowed to modify anything in this file.2#include <vector>3#include <iostream>4#include <iomanip>5#include <cstdlib>6#include <time.h>7#include <functional>8#include <unistd.h>9#include "randPack.h"10#include "fracas.h"11#include "alpaca.h"12#include "termmanip.h"13#include "swiss.h"14#include "cwillis/fracasPack.h"15#include "ischomer/ischomer.h"16#include "jmetcalf/superPack.h"17#include "mcharles/fracasPack.h"18#include "mtaylor/FracasPack.h"192021using namespace std;2223class SwissFracasPack : public SwissTournament<AlpacaFracasPack>::Contestant24{25public:26SwissFracasPack(function<AlpacaFracasPack*()> genFunc)27{28//create the first pack29this->genFunc = genFunc;30pack = genFunc();31nameStr = pack->name();32}333435virtual string name() {36return nameStr;37}383940virtual AlpacaFracasPack * player()41{42if(pack) {43AlpacaFracasPack *res;44res = pack;45pack = nullptr;46return res;47}4849return genFunc();50}5152private:53function<AlpacaFracasPack*()> genFunc;54AlpacaFracasPack *pack;55string nameStr;56};575859int main(int argc, char** argv) {60//Make our two packs61[] ()->AlpacaFracasPack* {return new randPack::FracasPack();};62vector<SwissTournament<AlpacaFracasPack>::Contestant *> players;63pair<SwissTournament<AlpacaFracasPack>::Contestant*, SwissTournament<AlpacaFracasPack>::Contestant*> match;64SwissTournament<AlpacaFracasPack> *tournament;65AlpacaFracasPack *p1, *p2;6667srand(time(0));6869//init players70players.push_back(new SwissFracasPack([] ()->AlpacaFracasPack* {return new cwillis::FracasPack();}));71players.push_back(new SwissFracasPack([] ()->AlpacaFracasPack* {return new ischomer::FracasPack();}));72players.push_back(new SwissFracasPack([] ()->AlpacaFracasPack* {return new jmetcalf::FracasPack();}));73players.push_back(new SwissFracasPack([] ()->AlpacaFracasPack* {return new mcharles::FracasPack();}));74players.push_back(new SwissFracasPack([] ()->AlpacaFracasPack* {return new mtaylor::FracasPack();}));7576777879//create the tournament80tournament = new SwissTournament<AlpacaFracasPack>(players);81while(!tournament->tournamentDone())82{83cout << clearScreen << cursorOff << cursorPosition(1,1);84cout.flush();85tournament->printLeader();86cout << endl << endl;87tournament->printPairings();88sleep(5);89while(!tournament->roundDone()) {90//get the match and the players91match = tournament->getMatch();92p1 = match.first->player();93if(match.second==nullptr) {94//bye95tournament->report(match.first);96continue;97}98p2 = match.second->player();99100cout << clearScreen << cursorPosition(10, 20)101<< match.first->name() << " vs " << match.second->name();102cout.flush();103sleep(1);104105//Create the fracas106Fracas *f = new Fracas(p1, p2);107cout << clearScreen << cursorOff << cursorPosition(1,1);108cout.flush();109110//do the fracas!111if(f->go() == p1) {112sleep(5);113tournament->report(match.first);114cout << clearScreen << cursorPosition(10, 20)115<< match.first->name() << " wins!";116} else {117sleep(5);118tournament->report(match.second);119cout << clearScreen << cursorPosition(10, 20)120<< match.second->name() << " wins!";121}122cout.flush();123sleep(1);124}125tournament->nextRound();126}127128129//print the final outcome130cout << cursorOn << clearScreen << cursorPosition(1,1) << "Final Outcome" << endl;131tournament->printLeader();132cout.flush();133134return 0;135}136137138