|
Re: The 2056 Streak has ended!
Quote:
Originally Posted by JABot67
You did a great job cranking this out so fast! One quick fact checking thing to do is to search for teams with an OP Number of 1 and see if they have indeed won an event with 2056. In the above quote, the bold teams have confirmed wins with 2056; the rest seem to have been given by the algorithm an OP Number of 1 in error. I'm not sure what the nature of this bug is, but I hope this helps you get to the bottom of the issue!
|
Thanks. It turns out that I mixed up which vector size should end one of the loops which somehow led to a lot of false values. Corrected lists are below, and I checked through all the teams with OP numbers <= 1 and they do match. The corrected code is also below. I didn't check the other numbers, but the new distribution is:
Code:
OP num # of teams
0 1
1 38
2 189
3 462
4 317
5 102
6 13
7 1
Spoiler for Corrected code:
Code:
#include <iostream>
#include <vector>
#include <fstream>
using namespace std;
class Team {
public:
Team(int x) {teamNum = x; matches = 0; opNum = -1;};
void setOpNum(double x) {opNum = x;};
void incMatches() {matches++;};
int getNum() {return teamNum;};
int getMatches() {return matches;};
double getOpNum() {return opNum;};
private:
int teamNum;
int matches; // num of matches played with OP
double opNum; // OP number
};
struct ALLIANCE {
vector<int> team1;
vector<int> team2;
vector<int> team3;
vector<int> team4;
};
void createTeamVector(vector<Team> & v) {
int x;
ifstream file("teamlist.txt");
while(file >> x) {
v.push_back(x);
}
file.close();
}
void createAllianceVector(ALLIANCE & a) {
int x1, x2, x3, x4;
ifstream file("winningalliances.txt");
while(file >> x1 >> x2 >> x3 >> x4) {
a.team1.push_back(x1);
a.team2.push_back(x2);
a.team3.push_back(x3);
a.team4.push_back(x4);
}
file.close();
}
int index(int teamNum, vector<Team> &v) {
for(size_t i = 0; i < v.size(); i++) {
if(teamNum == v[i].getNum())
return i;
}
return 0; // index of team "0"
}
int main() {
vector<Team> teams; // list of all teams + placeholder team "0"
ALLIANCE alliances; // winning alliances for all events
vector< vector<int> > teamsSorted; // vector of vectors of teams sorted by op number
createTeamVector(teams);
createAllianceVector(alliances);
/// set 2056 to op number = 0
vector<int> newColumn;
teamsSorted.push_back(newColumn);
teamsSorted.at(0).push_back(2056);
/// find all teams that 2056 has played with and find the number of times they won together
for(size_t i = 0; i < alliances.team1.size(); i++) {
if(alliances.team1[i] == 2056) {
cout << i << " " << alliances.team2[i] << " " << alliances.team3[i] << " " << alliances.team4[i] << endl;
teams[index(alliances.team2[i], teams)].incMatches();
teams[index(alliances.team3[i], teams)].incMatches();
teams[index(alliances.team4[i], teams)].incMatches();
}
else if(alliances.team2[i] == 2056) {
cout << i << " " << alliances.team1[i] << " " << alliances.team3[i] << " " << alliances.team4[i] << endl;
teams[index(alliances.team1[i], teams)].incMatches();
teams[index(alliances.team3[i], teams)].incMatches();
teams[index(alliances.team4[i], teams)].incMatches();
}
else if(alliances.team3[i] == 2056) {
cout << i << " " << alliances.team1[i] << " " << alliances.team2[i] << " " << alliances.team4[i] << endl;
teams[index(alliances.team1[i], teams)].incMatches();
teams[index(alliances.team2[i], teams)].incMatches();
teams[index(alliances.team4[i], teams)].incMatches();
}
else if(alliances.team4[i] == 2056) {
cout << i << " " << alliances.team1[i] << " " << alliances.team2[i] << " " << alliances.team3[i] << endl;
teams[index(alliances.team1[i], teams)].incMatches();
teams[index(alliances.team2[i], teams)].incMatches();
teams[index(alliances.team3[i], teams)].incMatches();
}
}
/// add those teams to the sorted vector and set their op number
teamsSorted.push_back(newColumn);
for(size_t i = 1; i < teams.size(); i++) { // skip team "0"
if(teams[i].getMatches() > 0) {
teamsSorted.at(1).push_back(teams[i].getNum());
teams[i].setOpNum(1.0/(teams[i].getMatches()));
cout << teams[i].getNum() << " " << teams[i].getMatches() << endl;
}
}
/// find teams with op numbers > 1
int j = 2, temp = 1;
while(temp > 0) { // loop while there are teams with the previous op number
temp = 0;
teamsSorted.push_back(newColumn);
for(size_t i = 0; i < teamsSorted.at(j-1).size(); i++) { // inc through teams in last op number
for(size_t k = 1; k < alliances.team1.size(); k++) { // skip team "0", inc through all teams
if(alliances.team1[k] == teamsSorted[j-1][i]) {
temp++;
if(teams[index(alliances.team2[k], teams)].getOpNum() == -1) {teams[index(alliances.team2[k], teams)].setOpNum(j);}
if(teams[index(alliances.team3[k], teams)].getOpNum() == -1) {teams[index(alliances.team3[k], teams)].setOpNum(j);}
if(teams[index(alliances.team4[k], teams)].getOpNum() == -1) {teams[index(alliances.team4[k], teams)].setOpNum(j);}
}
else if(alliances.team2[k] == teamsSorted[j-1][i]) {
temp++;
if(teams[index(alliances.team1[k], teams)].getOpNum() == -1) {teams[index(alliances.team1[k], teams)].setOpNum(j);}
if(teams[index(alliances.team3[k], teams)].getOpNum() == -1) {teams[index(alliances.team3[k], teams)].setOpNum(j);}
if(teams[index(alliances.team4[k], teams)].getOpNum() == -1) {teams[index(alliances.team4[k], teams)].setOpNum(j);}
}
else if(alliances.team3[k] == teamsSorted[j-1][i]) {
temp++;
if(teams[index(alliances.team1[k], teams)].getOpNum() == -1) {teams[index(alliances.team1[k], teams)].setOpNum(j);}
if(teams[index(alliances.team2[k], teams)].getOpNum() == -1) {teams[index(alliances.team2[k], teams)].setOpNum(j);}
if(teams[index(alliances.team4[k], teams)].getOpNum() == -1) {teams[index(alliances.team4[k], teams)].setOpNum(j);}
}
else if(alliances.team4[k] == teamsSorted[j-1][i]) {
temp++;
if(teams[index(alliances.team1[k], teams)].getOpNum() == -1) {teams[index(alliances.team1[k], teams)].setOpNum(j);}
if(teams[index(alliances.team2[k], teams)].getOpNum() == -1) {teams[index(alliances.team2[k], teams)].setOpNum(j);}
if(teams[index(alliances.team2[k], teams)].getOpNum() == -1) {teams[index(alliances.team3[k], teams)].setOpNum(j);}
}
}
} // end for loop
if(temp > 0) {
for(size_t i = 1; i < teams.size(); i++) { // skip team "0"
if(teams[i].getOpNum() == j) {
teamsSorted.at(j).push_back(teams[i].getNum());
}
}
}
j++;
} // end while loop
teams[index(2056, teams)].setOpNum(0); // reset 2056's op number to 0
/// print number of teams per op number
for(size_t i = 0; i < teamsSorted.size(); i++)
cout << i << " " << teamsSorted.at(i).size() << endl;
/// write data to file, sorted by team number
ofstream file;
file.open("op_numbers.txt");
for(size_t i = 1; i < teams.size(); i++) { // skip team "0"
file << teams[i].getNum() << "\t\t" << teams[i].getOpNum() << "\n";
}
file.close();
/// write data to file, sorted by op number
file.open("op_numbers_2.txt");
// teams with op number < 1 (searched through op_numbers.txt...not a true sort...)
file << 2056 << "\t\t" << 0 << "\n";
file << 1114 << "\t\t" << teams[index(1114, teams)].getOpNum() << "\n";
file << 1547 << "\t\t" << teams[index(1547, teams)].getOpNum() << "\n";
file << 2185 << "\t\t" << teams[index(2185, teams)].getOpNum() << "\n";
// teams with op number between 1 and 6
for(int i = 1; i <= 6; i++) {
for(size_t k = 0; k < teams.size(); k++) {
if(teams[k].getOpNum() == i)
file << teams[k].getNum() << "\t\t" << i << "\n";
}
}
// teams with op number = -1 (no connection to 2056)
for(size_t k = 0; k < teams.size(); k++) {
if(teams[k].getOpNum() == -1)
file << teams[k].getNum() << "\t\t" << -1 << "\n";
}
file.close();
return 0;
}
|