Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- char table[3][3][3];
- struct Field{
- int index;
- int x(){
- return index %3;
- }
- int y(){
- return (index/3)%3;
- }
- int z(){
- return index/3;
- }
- int Value(){
- switch(table[x()][y()][z()]){
- case 'o' : return 2;
- case 'x' : return 1;
- default : return 0;
- }
- }
- void setValue(char c){
- table[x()][y()][z()] =c;
- }
- };
- vector <Field> fields(27);
- struct Triple{
- Field first;
- Field second;
- Field Third(){
- Field f;
- f.index = (second.index+first.index)/2;
- }
- int AdaPoints(){
- int a = 0;
- if (first.Value()==1) a++;
- if (second.Value()==1) a++;
- if (Third().Value()==1) a++;
- return a;
- }
- int VinitPoints(){
- int a = 0;
- if (first.Value()==2) a++;
- if (second.Value()==2) a++;
- if (Third().Value()==2) a++;
- return a;
- }
- bool Finished(){
- if (AdaPoints()+VinitPoints()==3)
- return true;
- return false;
- }
- int Winner(){
- if (Finished()) return 0;
- if (AdaPoints()==2) return 1;
- if (VinitPoints()==2) return 2;
- return 0;
- }
- void toString(){
- cout << "(" << first.index << " " << second.index << " )";
- }
- int findEmpty(){
- if (first.Value()=='.')
- return first.index;
- if (second.Value()=='.')
- return second.index;
- return Third().index;
- }
- };
- vector <Triple> allTriples;
- vector <vector <Triple> > triplesContainingField(27);
- bool makingTriple(int a, int b){
- return ((fields[a].x()+fields[b].x())%2==0 && (fields[a].y()+fields[b].y())%2==0 && (fields[a].z()+fields[b].z())%2 == 0);
- }
- void showGame(){
- for (int i=0; i<3; i++)
- for (int j = 0; j<3; j++){
- for (int k = 0; k<3; k++)
- cout << table[i][j][k] << " ";
- cout << endl;
- }
- }
- void FirstTurn(bool AdasTurn, int * criticalField){
- if (AdasTurn){
- for (int i=0; i<allTriples.size(); i++)
- if (allTriples[i].Winner()==1){
- cout << "Ada" << endl;
- return;
- }
- int minInd = 27;
- int maxInd = -1;
- for (int i=0; i<allTriples.size(); i++){
- if (allTriples[i].Winner()==2){
- int i = allTriples[i].findEmpty();
- if (i>maxInd) maxInd = i;
- if (i<minInd) minInd = i;
- }
- }
- if (maxInd == minInd){
- fields[maxInd].setValue('x');
- *criticalField = maxInd;
- }
- else if (maxInd < 27 && maxInd!=minInd){
- cout << "Vinit" << endl;
- return;
- }
- }
- else{
- for (int i=0; i<allTriples.size(); i++)
- if (allTriples[i].Winner()==2){
- cout << "Vinit" << endl;
- return;
- }
- int minInd = 27;
- int maxInd = -1;
- for (int i=0; i<allTriples.size(); i++){
- if (allTriples[i].Winner()==1){
- int i = allTriples[i].findEmpty();
- if (i>maxInd) maxInd = i;
- if (i<minInd) minInd = i;
- }
- }
- if (maxInd == minInd){
- fields[maxInd].setValue('o');
- *criticalField = maxInd;
- }
- else if (maxInd < 27 && maxInd!=minInd){
- cout << "Ada" << endl;
- return;
- }
- }
- }
- void Game(){
- int dif = 0;
- int fieldsLeft = 0;
- for (int i=0; i<3; i++)
- for (int j = 0; j<3; j++)
- for (int k = 0; k<3; k++){
- cin >> table[i][j][k];
- if (table[i][j][k] =='x') dif++;
- if (table[i][j][k]=='o') dif--;
- if (table[i][j][k] =='.') fieldsLeft++;
- }
- bool AdasTurn;
- if (dif==0)
- AdasTurn = true;
- else
- AdasTurn = false;
- int criticalField = -1;
- FirstTurn(AdasTurn, &criticalField);
- if (criticalField ==-1)
- return;
- }
- int main(){
- /* for (int i=0; i<27; i++)
- fields[i].index = i;
- Triple t;
- for (int i=0; i<27; i++)
- for (int j = i+1; j<27; j++){
- if (makingTriple(i,j)){
- t = {fields[i], fields[j]};
- allTriples.push_back(t);
- triplesContainingField[i].push_back(t);
- triplesContainingField[(i+j)/2].push_back(t);
- triplesContainingField[j].push_back(t);
- }
- Game();
- showGame();*/
- cout << "Hello world";
- return 0;
- }
- for (int i=0; i<s.size(); i++)
- if (s[i].Winner()==1){
- cout << "Ada" << endl;
- return;
- }
- int minInd = 27;
- int maxInd = -1;
- for (int i=0; i<s.size(); i++){
- if (s[i].Winner()==2){
- int i = s[i].findEmpty();
- if (i>maxInd) maxInd = i;
- if (i<minInd) minInd = i;
- }
- }
- if (maxInd == minInd){
- fields[maxInd].setValue('x');
- s = triplesContainingField[maxInd];
- }
- else if (maxInd < 27 && maxInd!=minInd){
- cout << "Vinit" << endl;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement