Created
April 11, 2010 10:46
-
-
Save anonymous/362648 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <vector> | |
| using namespace std; | |
| int check(vector<int>); | |
| int win(vector<int>[]); | |
| int lose(vector<int>); | |
| int draw(vector< vector<int> >, vector<int>, vector<int>*); | |
| vector<int> store(vector<int>, vector<int>*); | |
| int main() | |
| { | |
| vector< vector<int> > tbl; | |
| vector<int> pile[7]; | |
| vector<int> deck; | |
| int tmp; | |
| int empty[7]; | |
| while (cin >> tmp && tmp) | |
| { | |
| tbl.clear(); | |
| deck.clear(); | |
| memset(empty, 0, sizeof(empty)); | |
| for (int i = 0; i < 7; i++) | |
| { | |
| pile[i].clear(); | |
| } | |
| deck.push_back(tmp); | |
| for (int i = 1; i < 52; i++) | |
| { | |
| cin >> tmp; | |
| deck.push_back(tmp); | |
| } | |
| tbl.push_back(store(deck, pile)); | |
| int p = -1, done = 0, cnt = 0;; | |
| while (!done) | |
| { | |
| /* cout << "cnt: " << cnt+1 << endl; | |
| for (int i = 0; i < deck.size(); i++) | |
| { | |
| cout << deck[i] << " "; | |
| } | |
| cout << endl; | |
| for (int k = 0; k < 7; k++) | |
| { | |
| cout << "pile[" << k << "]: "; | |
| for (int i = 0; i < pile[k].size(); i++) | |
| { | |
| cout << pile[k][i] << " "; | |
| } | |
| cout << endl; | |
| } | |
| cout << endl; | |
| system("pause"); | |
| system("cls");*/ | |
| do { | |
| p++; | |
| p %= 7; | |
| } while (empty[p] == 1); | |
| cnt++; | |
| tbl.push_back(store(deck, pile)); | |
| pile[p].push_back(deck[0]); | |
| deck.erase(deck.begin()); | |
| int loop = 1; | |
| while (loop) | |
| { | |
| switch (check(pile[p])) | |
| { | |
| case 1: | |
| deck.push_back(pile[p][0]); | |
| deck.push_back(pile[p][1]); | |
| deck.push_back(pile[p][pile[p].size() - 1]); | |
| pile[p].erase(pile[p].begin()); | |
| pile[p].erase(pile[p].begin()); | |
| pile[p].pop_back(); | |
| break; | |
| case 2: | |
| deck.push_back(pile[p][0]); | |
| deck.push_back(pile[p][pile[p].size() - 2]); | |
| deck.push_back(pile[p][pile[p].size() - 1]); | |
| pile[p].erase(pile[p].begin()); | |
| pile[p].pop_back(); | |
| pile[p].pop_back(); | |
| break; | |
| case 3: | |
| deck.push_back(pile[p][pile[p].size() - 3]); | |
| deck.push_back(pile[p][pile[p].size() - 2]); | |
| deck.push_back(pile[p][pile[p].size() - 1]); | |
| pile[p].pop_back(); | |
| pile[p].pop_back(); | |
| pile[p].pop_back(); | |
| break; | |
| default: | |
| loop = 0; | |
| break; | |
| } | |
| if (pile[p].size() == 0) | |
| { | |
| empty[p] = 1; | |
| } | |
| } | |
| if (win(pile)) | |
| { | |
| cout << "Win : " << cnt << endl; | |
| done = 1; | |
| } | |
| if (lose(deck)) | |
| { | |
| cout << "Loss: " << cnt << endl; | |
| done = 1; | |
| } | |
| if (draw(tbl, deck, pile)) | |
| { | |
| cout << "Draw: " << cnt << endl; | |
| done = 1; | |
| } | |
| } | |
| } | |
| return 0; | |
| } | |
| int check(vector<int> pile) | |
| { | |
| if (pile.size() >= 3) | |
| { | |
| if ((pile[0] + pile[1] + pile[pile.size() - 1]) % 10 == 0) | |
| { | |
| return 1; | |
| } | |
| if ((pile[0] + pile[pile.size() - 2] + pile[pile.size() - 1]) % 10 == 0) | |
| { | |
| return 2; | |
| } | |
| if ((pile[pile.size() - 3] + pile[pile.size() - 2] + pile[pile.size() - 1]) % 10 == 0) | |
| { | |
| return 3; | |
| } | |
| } | |
| return 0; | |
| } | |
| int win(vector<int> pile[]) | |
| { | |
| int card = 0; | |
| for (int i = 0; i < 7; i++) | |
| { | |
| card += pile[i].size(); | |
| } | |
| return (card == 0); | |
| } | |
| int lose(vector<int> deck) | |
| { | |
| return (deck.size() == 0); | |
| } | |
| int draw(vector< vector<int> > tbl, vector<int> deck, vector<int>* pile) | |
| { | |
| vector<int> state = store(deck, pile); | |
| for (int i = 0; i < tbl.size() - 1; i++) | |
| { | |
| int same = 1; | |
| for (int j = 0; j < state.size(); j++) | |
| { | |
| if (tbl[i][j] != state[j]) | |
| { | |
| same = 0; | |
| break; | |
| } | |
| } | |
| if (same) | |
| { | |
| return 1; | |
| } | |
| } | |
| return 0; | |
| } | |
| vector<int> store(vector<int> deck, vector<int>* pile) | |
| { | |
| vector<int> state = deck; | |
| for (int i = 0; i < 7; i++) | |
| { | |
| for (int j = 0; j < pile[i].size(); j++) | |
| { | |
| state.push_back(pile[i][j]); | |
| } | |
| state.push_back(0); | |
| } | |
| return state; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment