├── flip.cpp └── judge.cpp /flip.cpp: -------------------------------------------------------------------------------- 1 | #define row 8 2 | #define column 8 3 | 4 | /////////////////////////////////////////////////////////////////////////// 5 | /////////////////////// Valid Moves Function ////////////////////////////// 6 | int abs(int num){ 7 | return num>=0 ? num : -num; 8 | } 9 | 10 | int isInTable(int x,int y){ 11 | if(x < 8 && x>=0 && y<8 && y>=0) return 1; 12 | else return 0; 13 | } 14 | 15 | int validNorth(int x0,int y0 ,int x ,int y, const int table[row][column],int player){ //// 16 | if(table[y0][x0]!=0) return-1; 17 | y-=1; 18 | if(!isInTable(x,y)) return -1; 19 | 20 | if(table[y][x]== 0) return -1; 21 | else if(table[y][x]== player){ 22 | if (abs(x-x0)==1 || abs(y-y0)==1 ) return -1; 23 | else return x0+y0*8; 24 | } 25 | else return validNorth(x0,y0,x,y,table,player); 26 | } 27 | 28 | int validSouth(int x0,int y0 ,int x ,int y, const int table[row][column],int player){ //// 29 | if(table[y0][x0]!=0) return-1; 30 | y+=1; 31 | if(!isInTable(x,y)) return -1; 32 | 33 | if(table[y][x]== 0) return -1; 34 | else if(table[y][x]== player){ 35 | if (abs(x-x0)==1 || abs(y-y0)==1 ) return -1; 36 | else return x0+y0*8; 37 | } 38 | else return validSouth(x0,y0,x,y,table,player); 39 | } 40 | 41 | int validWest(int x0,int y0 ,int x ,int y, const int table[row][column],int player){ //// 42 | if(table[y0][x0]!=0) return-1; 43 | x-=1; 44 | if(!isInTable(x,y)) return -1; 45 | 46 | if(table[y][x]== 0) return -1; 47 | else if(table[y][x]== player){ 48 | if (abs(x-x0)==1 || abs(y-y0)==1 ) return -1; 49 | else return x0+y0*8; 50 | } 51 | else return validWest(x0,y0,x,y,table,player); 52 | } 53 | 54 | int validEast(int x0,int y0 ,int x ,int y, const int table[row][column],int player){ //// 55 | if(table[y0][x0]!=0) return-1; 56 | x+=1; 57 | if(!isInTable(x,y)) return -1; 58 | 59 | if(table[y][x]== 0) return -1; 60 | else if(table[y][x]== player){ 61 | if (abs(x-x0)==1 || abs(y-y0)==1 ) return -1; 62 | else return x0+y0*8; 63 | } 64 | else return validEast(x0,y0,x,y,table,player); 65 | } 66 | 67 | int validNW(int x0,int y0 ,int x ,int y, const int table[row][column],int player){ //// 68 | if(table[y0][x0]!=0) return-1; 69 | y-=1; x-=1; 70 | if(!isInTable(x,y)) return -1; 71 | 72 | if(table[y][x]== 0) return -1; 73 | else if(table[y][x]== player){ 74 | if (abs(x-x0)==1 || abs(y-y0)==1 ) return -1; 75 | else return x0+y0*8; 76 | } 77 | else return validNW(x0,y0,x,y,table,player); 78 | } 79 | 80 | int validNE(int x0,int y0 ,int x ,int y, const int table[row][column],int player){ 81 | if(table[y0][x0]!=0) return-1; 82 | y-=1; x+=1; 83 | if(!isInTable(x,y)) return -1; 84 | 85 | if(table[y][x]== 0) return -1; 86 | else if(table[y][x]== player){ 87 | if (abs(x-x0)==1 || abs(y-y0)==1 ) return -1; 88 | else return x0+y0*8; 89 | } 90 | else return validNE(x0,y0,x,y,table,player); 91 | } 92 | 93 | int validSW(int x0,int y0 ,int x ,int y, const int table[row][column],int player){ 94 | if(table[y0][x0]!=0) return-1; 95 | y+=1; x-=1; 96 | if(!isInTable(x,y)) return -1; 97 | 98 | if(table[y][x]== 0) return -1; 99 | else if(table[y][x]== player){ 100 | if (abs(x-x0)==1 || abs(y-y0)==1 ) return -1; 101 | else return x0+y0*8; 102 | } 103 | else return validSW(x0,y0,x,y,table,player); 104 | } 105 | 106 | int validSE(int x0,int y0 ,int x ,int y, const int table[row][column],int player){ 107 | if(table[y0][x0]!=0) return-1; 108 | y+=1; x+=1; 109 | if(!isInTable(x,y)) return -1; 110 | 111 | if(table[y][x]== 0) return -1; 112 | else if(table[y][x]== player){ 113 | if (abs(x-x0)==1 || abs(y-y0)==1 ) return -1; 114 | else return x0+y0*8; 115 | } 116 | else return validSE(x0,y0,x,y,table,player); 117 | } 118 | 119 | /////////////////////////////// Flip ////////////////////////////////////// 120 | 121 | int flipNorth(int x ,int y, int table[row][column],int player){ //// 122 | if (validNorth(x,y,x,y,table,player)== -1) return 1; 123 | table[y][x] =player; 124 | y-=1; 125 | while(table[y][x] == 3 - player){ 126 | table[y][x]= player; 127 | y-=1; 128 | } 129 | return 0; 130 | } 131 | 132 | int flipSouth(int x ,int y, int table[row][column],int player){ //// 133 | if (validSouth(x,y,x,y,table,player)== -1) return 1; 134 | table[y][x] =player; 135 | y+=1; 136 | while(table[y][x] == 3 - player){ 137 | table[y][x]= player; 138 | y+=1; 139 | } 140 | return 0; 141 | } 142 | 143 | int flipWest(int x ,int y, int table[row][column],int player){ //// 144 | if (validWest(x,y,x,y,table,player)== -1) return 1; 145 | table[y][x] = player; 146 | x-=1; 147 | while(table[y][x] == 3 - player){ 148 | table[y][x]= player; 149 | x-=1; 150 | } 151 | return 0; 152 | } 153 | 154 | int flipEast(int x ,int y, int table[row][column],int player){ //// 155 | if (validEast(x,y,x,y,table,player)== -1) return 1; 156 | table[y][x] = player; 157 | x+=1; 158 | while(table[y][x] == 3 - player){ 159 | table[y][x]=player; 160 | x+=1; 161 | } 162 | return 0; 163 | } 164 | 165 | int flipNW(int x ,int y, int table[row][column],int player){ //// 166 | if (validNW(x,y,x,y,table,player)== -1) return 1; 167 | table[y][x] = player; 168 | y-=1; x-=1; 169 | while(table[y][x] == 3 - player){ 170 | table[y][x]= player; 171 | y-=1; x-=1; 172 | } 173 | return 0; 174 | } 175 | 176 | int flipNE(int x ,int y, int table[row][column],int player){ 177 | if (validNE(x,y,x,y,table,player)== -1) return 1; 178 | table[y][x] = player; 179 | y-=1; x+=1; 180 | while(table[y][x] == 3 - player){ 181 | table[y][x]= player; 182 | y-=1; x+=1; 183 | } 184 | return 0; 185 | } 186 | 187 | int flipSW(int x ,int y, int table[row][column],int player){ 188 | if (validSW(x,y,x,y,table,player)== -1) return 1; 189 | table[y][x] = player; 190 | y+=1; x-=1; 191 | while(table[y][x] == 3 - player){ 192 | table[y][x]= player; 193 | y+=1; x-=1; 194 | } 195 | return 0; 196 | } 197 | 198 | int flipSE(int x ,int y, int table[row][column],int player){ 199 | if (validSE(x,y,x,y,table,player)== -1) return 1; 200 | table[y][x] = player; 201 | y+=1; x+=1; 202 | while(table[y][x] == 3 - player){ 203 | table[y][x]= player; 204 | y+=1; x+=1; 205 | } 206 | return 0; 207 | } 208 | 209 | int doFlip(int x ,int y, int table[row][column],int player){ 210 | int result = 1; 211 | result *=flipNorth(x ,y,table,player); 212 | result *=flipSouth(x ,y,table,player); 213 | result *=flipEast(x ,y,table,player); 214 | result *=flipWest(x ,y,table,player); 215 | result *=flipNE(x ,y,table,player); 216 | result *=flipNW(x ,y,table,player); 217 | result *=flipSE(x ,y,table,player); 218 | result *=flipSW(x ,y,table,player); 219 | return 1-result; 220 | } -------------------------------------------------------------------------------- /judge.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "flip.cpp" 9 | 10 | #define NoTeams 3 11 | 12 | using namespace std; 13 | 14 | string intArrayToString(int int_array[], int size_of_array) { 15 | string returnstring = ""; 16 | for (int temp = 0; temp < size_of_array; temp++) 17 | returnstring += int_array[temp]+'0'; 18 | return returnstring; 19 | } 20 | 21 | string exec(string str) { 22 | char cmd[str.size() + 1]; 23 | strcpy(cmd, str.c_str()); 24 | char buffer[128]; 25 | string result = ""; 26 | FILE* pipe = popen(cmd, "r"); 27 | if (!pipe) throw runtime_error("popen() failed!"); 28 | try { 29 | while (fgets(buffer, sizeof buffer, pipe) != NULL) { 30 | result += buffer; 31 | } 32 | } catch (...) { 33 | pclose(pipe); 34 | throw; 35 | } 36 | pclose(pipe); 37 | return result; 38 | } 39 | 40 | string boardToArgv(int board[][column]){ 41 | string str[column]; 42 | for(int i=0;ip2) return 1; 89 | if(p1==p2) return 0; 90 | if(p2>p1) return 2; 91 | } 92 | 93 | void printBoardToFile(const int board[row][column],FILE *fptr){ 94 | fprintf(fptr,"%s"," 0 1 2 3 4 5 6 7\n"); 95 | string str[column]; 96 | for(int i=0;i " + white+"\n"; 180 | char stri[str.size() + 1]; 181 | strcpy(stri, str.c_str()); 182 | fprintf(fgame,"%s",stri); 183 | 184 | cout << black << " > " << white; 185 | return 1; 186 | }else if(winner(board)==2){ 187 | string str = black + " > " + white+"\n"; 188 | char stri[str.size() + 1]; 189 | strcpy(stri, str.c_str()); 190 | fprintf(fgame,"%s",stri); 191 | 192 | cout << black << " < " << white; 193 | return 2; 194 | }else if(winner(board)==0){ 195 | string str = black + " > " + white+"\n"; 196 | char stri[str.size() + 1]; 197 | strcpy(stri, str.c_str()); 198 | fprintf(fgame,"%s",stri); 199 | 200 | cout << black << " = " << white; 201 | return 0; 202 | } 203 | fclose(fgame); 204 | } 205 | 206 | int main(){ 207 | const string Team[]={ 208 | "Force", 209 | "LQ", 210 | // "iran16", 211 | // "Magic_world", 212 | // "SSDEBF", 213 | // "MONOLITH", 214 | // "Loser", 215 | // "NumOne01", 216 | // "flipper_the_dolphin", 217 | // "Oftaadegaan", 218 | // "shift", 219 | "Boro_dame_khoontoon_bazi_kon", 220 | // "EH" 221 | }; 222 | int table[NoTeams][3]={0}; 223 | 224 | int board[8][8]={ 225 | {0, 0 ,0 ,0 ,0 ,0 ,0 ,0}, 226 | 227 | {0 ,0 ,0 ,0 ,0 ,0 ,0 ,0}, 228 | 229 | {0, 0 ,0 ,0 ,0 ,0 ,0 ,0}, 230 | 231 | {0 ,0 ,0 ,2 ,1 ,0 ,0 ,0}, 232 | 233 | {0 ,0 ,0 ,1 ,2 ,0 ,0 ,0}, 234 | 235 | {0 ,0 ,0 ,0 ,0 ,0 ,0 ,0}, 236 | 237 | {0 ,0 ,0 ,0 ,0 ,0 ,0 ,0}, 238 | 239 | {0 ,0 ,0 ,0 ,0 ,0 ,0 ,0} 240 | }; 241 | int result; 242 | for(int i =0;i