// Change the YUV to RGB, and guarantee all R,G,B values in [-1, 1]. void getYUVtoRGB(bool flag, float Y, float U, float V, GLfloat& R, GLfloat& G, GLfloat& B) { R = (GLfloat)(Y + 1.4075 * (V - 128.0)); G = (GLfloat)(Y - 0.3455 * (U - 128.0) - (0.7169 * (V - 128.0f))); B = (GLfloat)(Y + 1.7790 * (U - 128.0)); if(!flag) R = 255.0f - R, B *= 0.8f; R = (R-127.5f)/255.0f; G = (G-127.5f)/255.0f; B = (B-127.5f)/255.0f; checkLegal(R), checkLegal(G), checkLegal(B); //printf("$(%f %f %f)\n", R, G, B); }
void Player::takeIn(){ // take in the opponent's move, and deal with roll back int i, j; cin >> i >> j; if (i == -1 && j == -1) { rollBack(); cout << "Insert you move again" << endl; takeIn(); } else { lastYou_ = you; you[0] = i; you[1] = j; you[0]--; you[1]--; char c; while (!checkLegal(you) ) { cout << "Are u sure that u input something illegal y/n?" << endl; cin >> c; if (c == 'y') { gameOver = MAX; return; } cin >> i >> j; you[0] = i; you[1] = j; you[0]--; you[1]--; } curState.update(MIN, you); increaseStep(); } }
bool haveMove(int dimension, char board[26][26], char colour){ int i,j; int deltaRow, deltaCol; char row, col; bool haveMove = false; for(i = 0; i<dimension; i++){ for(j = 0; j<dimension; j++){ row = 'a'+i; col = 'a'+j; if (checkLegal(dimension, board, row, col, colour)==true){ haveMove = true; } } } return haveMove; }
int main(void){ int dimension; char board[26][26]; int i,j; int out = 0; char row, col; char colour, diffColour; int deltaRow, deltaCol; int copy[26][26]; printf("Enter the board dimension: "); scanf("%d",&dimension); for (i=0;i<dimension;i++){ for (j=0;j<dimension;j++) board[i][j]='U'; //first set all the elements 'U' } board[dimension/2-1][dimension/2-1] = 'W'; board[dimension/2-1][dimension/2] = 'B'; board[dimension/2][dimension/2-1] = 'B'; board[dimension/2][dimension/2] = 'W'; //define array in the range of dimension for(i=0;i<dimension;i++){ for(j=0;j<dimension;j++){ copy[i][j]=0; } } printf("Computer plays (B/W) : "); scanf(" %c",&colour); printBoard(board, dimension); //print the board out if (colour == 'W') diffColour = 'B'; if (colour == 'B') diffColour = 'W'; if (colour == 'W'){ printf("Enter move for colour %c (RowCol): ", diffColour); scanf(" %c %c", &row, &col); if (checkLegal(dimension, board, row, col, diffColour) == false){ printf("Invalid move.\n%c player wins.",colour); return EXIT_SUCCESS; } else{ board[row-'a'][col-'a']= diffColour; flipAllAfterLegal(dimension, board, diffColour, row, col); printBoard(board, dimension); } } while (out<1) { if (haveMove(dimension, board, colour)==true) changeBestMove(dimension, board, copy, colour); else{ if (haveMove(dimension, board, diffColour)==true){ printf("%c player has no valid move.\n",colour); } else{ finalCompare(dimension, board, colour, diffColour); return EXIT_SUCCESS; } } if (haveMove(dimension, board, diffColour)==true){ printf("Enter move for colour %c (RowCol): ", diffColour); scanf(" %c %c", &row, &col); if (checkLegal(dimension, board, row, col, diffColour) == false){ printf("Invalid move.\n%c player wins.",colour); return EXIT_SUCCESS; } else{ board[row-'a'][col-'a']= diffColour; flipAllAfterLegal(dimension, board, diffColour, row, col); printBoard(board, dimension); } } else{ if (haveMove(dimension, board, colour)==true){ printf("%c player has no valid move.\n", diffColour); } else{ finalCompare(dimension, board, colour, diffColour); return EXIT_SUCCESS; } } } }