int checkCell(char** tik, int x, int y) { int ok; if (x == 0 && y == 0) { ok = checkLine(tik,x,y); if (ok == 0) return ok; ok = checkCol(tik,x,y); if (ok == 0) return ok; ok = checkDiag1(tik,x,y); if (ok == 0) return ok; } if (x == 0 && y != 0) { ok = checkLine(tik,x,y); if (ok == 0) return ok; } if (x != 0 && y == 0) { ok = checkCol(tik,x,y); if (ok == 0) return ok; } if ( x == 3 && y == 0) { ok = checkDiag2(tik,x,y); if (ok == 0) return ok; } return ok; }
bool Node::assign(const std::string &line1, const std::string &line2, bool forceParsing) { // Check checksums ErrorCode error = checkLine(line1); if (error != NoError) { m_lastError = error; return false; } error = checkLine(line2); if (error != NoError) { m_lastError = error; return false; } // Assign free(); m_line2 = new std::string(line1); m_line3 = new std::string(line2); m_fileType = TwoLines; // Parse if (forceParsing) parseAll(); return (m_lastError == NoError); }
/* * Checks to see whether the specified player identified by mark * ('X' or 'O') has won the game. To reduce the number of special * cases, this implementation uses the helper function CheckLine. */ bool checkForWin(Grid<char> & board, char mark) { for (int i = 0; i < 3; i++) { if (checkLine(board, mark, i, 0, 0, 1)) return true; if (checkLine(board, mark, 0, i, 1, 0)) return true; } if (checkLine(board, mark, 0, 0, 1, 1)) return true; return checkLine(board, mark, 2, 0, -1, 1); }
int isGameOver(void) { int WhiteWins = false, BlackWins = false; if (current.gameOver != NOPLAYER) return current.gameOver; if (current.numOfTiles < 4) { current.gameOver = NOPLAYER; return current.gameOver; } /* check loop wins */ int i, j; for (i = 1; i < BOARD_SIZE; i++) { for (j = 1; j < BOARD_SIZE; j++) { switch (getAt(i, j)) { case NW: if (checkLine(i, j, 'u', 'l')) BlackWins = true; break; case SE: if (checkLine(i, j, 'u', 'l')) WhiteWins = true; break; case EMPTY: case NS: case WE: case NE: case WS: break; default: break; /* This should never happen */ } } } if (WhiteWins && BlackWins) { current.gameOver = whoDidLastMove(); return current.gameOver; } if (WhiteWins) { current.gameOver = WHITE; return current.gameOver; } if (BlackWins) { current.gameOver = BLACK; return current.gameOver; } return NOPLAYER; }
void checkChars(t_asm *asM) { t_token *ptr; ptr = asM->tokens; while (ptr) { if (ptr->token) checkLine(ptr->token, ptr->line, asM); if (ptr->arg) checkLine(ptr->arg, ptr->line, asM); ptr = ptr->next; } }
int main(){ Line l = createLine(1,2,1,4); assert(checkLine(l)==1); l = createLine(2,4,1,4); assert(checkLine(l)==2); l = createLine(2,3,1,4); assert(checkLine(l)==3); /*l = createLine(4,4,4,4);// this will abort */ return 0; }
QStringList MainWindow::checkElements(QDomElement element){ QDomNode child = element.firstChild(); QStringList errors; while (!child.isNull()) { QString tagName = child.toElement().tagName(); if(tagName == "label") { errors << checkLabel(child.toElement()); } else if (tagName == "line") { errors << checkLine(child.toElement()); } else if (tagName == "button") { errors << checkButton(child.toElement()); } else if (tagName == "lineEdit") { errors << checkLineEdit(child.toElement()); } else if (tagName == "spinBox") { errors << checkSpinBox(child.toElement()); } else if (tagName == "checkBox") { errors << checkCheckBox(child.toElement()); } else if (tagName == "radioGroup") { errors << checkRadioGroup(child.toElement()); } else if (tagName == "tweet") { errors << checkTweetWidget(child.toElement()); } else if (tagName == "tabSet") { errors << checkTabLayout(child.toElement()); } else if (tagName == "challongeMatch") { errors << checkChallongeWidget(child.toElement()); } else if (tagName == "cli") { //errors << checkCLI(child.toElement()); } child = child.nextSibling(); } return errors; }
//---------------------------------------------------------------------- uchar chkOutSymbol(char c) { if ( !checkLine(1)) return(1 ); ++outcnt; out_symbol(c); return(0); }
//---------------------------------------------------------------------- uchar chkOutChar(char c) { if ( !checkLine(1)) return(1 ); ++outcnt; OutChar(c); return(0); }
static void extract( FILE *arg_file, char arg_flag ) /* * Recursive procedure to allow for nested files. */ { FILE *next_file; char next_flag; while (status == EXIT_SUCCESS) { nchar = getLine(line); /* obtain input line */ code = checkLine(line,nchar,&next_flag,&name); /* classify line */ switch (code) { case NEXTLINE: writeLine(arg_file,arg_flag,line); /* line in current file */ break; case ENDFILE: closeFile(arg_file); /* end of current file */ return; case NEXTFILE: next_file = openFile(name); /* new file */ extract(next_file,next_flag); /* recursive call */ break; default: fprintf(stderr,"Xfile -- internal error\n"); status = EXIT_FAILURE; } } }
//---------------------------------------------------------------------- bool chkOutKeyword(const char *str, uint len) { if ( !checkLine(len) ) return true; OutKeyword(str, len); return false; }
//---------------------------------------------------------------------- uchar chkOutLine(const char *str, size_t len) { if ( !checkLine(len)) return(1 ); outcnt += len; OutLine(str); return(0); }
//---------------------------------------------------------------------- bool chkOutChar(char c) { if ( !checkLine(1) ) return true; ++outcnt; OutChar(c); return false; }
//---------------------------------------------------------------------- uchar chkOutSymSpace(char c) { if ( !checkLine(2)) return(1 ); out_symbol(c); OutChar(' '); outcnt += 2; return(0); }
//---------------------------------------------------------------------- bool chkOutSymbol(char c) { if ( !checkLine(1) ) return true; ++outcnt; out_symbol(c); return false; }
//---------------------------------------------------------------------- bool chkOutLine(const char *str, size_t len) { if ( !checkLine(len) ) return true; outcnt += len; OutLine(str); return false; }
// Verifica após a troca bool Tela::checkAfter(int maxX, int * v, int n) { bool flag = false; for (int i = 0; i <= maxX; ++i) if(checkLine(i)) flag = true; for (int i = 0; i < n; ++i) if(checkColumn(v[i])) flag = true; return flag; }
//old fallback Line *getLineFilterFB(Node *origin, Node *destination, int filter){ long i; for(i=0; i<numLines; i++){ if(checkLine(origin, destination, lines[i]) && (lines[i]->mine == 0||!filter)) return lines[i]; } return NULL; }
void cekSimpang(Queue *Q) { if(checkLine(right)) { int heuristic = check_color(); node n = {right,heuristic}; addToQueue(Q,right); } if(checkLine(left)) { int heuristic = check_color(); node n = {right,heuristic}; addToQueue(Q,straight); } if(checkLine(left)) { int heuristic = check_color(); node n = {right,heuristic}; addToQueue(Q,left); } turn(right,90); }
//---------------------------------------------------------------------- bool chkOutSymSpace(char c) { if ( !checkLine(2) ) return true; out_symbol(c); OutChar(' '); outcnt += 2; return false; }
/* Function Name: load * Purpose: Driver function. Opens an input file, loads the machine code, * performs a memory dump, then exits. * * Parameters: argc - amount of arguments passed * args[] - input file name * Returns: TRUE if program loaded successfully * FALSE if program failed to load */ bool load(int argc, char * args[]) { if((argc > 1) && (validFileName(args[1]))){ //check for valid file name and # of arguments FILE* f = fopen(args[1], "r"); //open the file unsigned char addrCounter = 0; //counter used to check for overlapping addresses char line[80]; unsigned int addr; int i; //Address parser count unsigned int lineCount = 0; int len; //Length of instruction unsigned char dataByte; //Temporary storage of info bool loadErr = FALSE; int check; while(fgets(line,80,f)) //While we haven't reached the end of the file... { lineCount++; check = checkLine(line); //Check the line if(check == 1) //If the line is valid... { addr = grabAddress(line); //Grab the address if(addr < addrCounter){ //Check for errors with the address printError(lineCount, line); loadErr = TRUE; break; } len = lenInst(line); //Find the length of the instruction int i = 0; unsigned int byteNo = 0; while(byteNo < len) //And load the data byte by byte { dataByte = grabDataByte(line, 9+i); putByte(addr, dataByte, &loadErr); addr++; byteNo++; addrCounter = addr; i += 2; } } else if(check == 0) //If the line is invalid... { //Halt loading and give an error message printError(lineCount, line); loadErr = TRUE; break; } discardRest(line, f); //If the line or instructions are just spaces, do nothing } return loadErr; //return TRUE if program was successfully loaded } printf("file opening failed\n usage: yess <filename>.yo\n"); //error message return TRUE; //return if invalid filename }
string checkDirection(string* board, DIRECTION dir, bool& has_empty){ char boardLine[BOARD_LINE_SIZE]; if(dir == HORIZONTAL || dir == VERTICAL){ for(int i = 0; i < 4; ++i){ if(dir == HORIZONTAL){ boardLine[0] = board[i][0]; boardLine[1] = board[i][1]; boardLine[2] = board[i][2]; boardLine[3] = board[i][3]; }else{ boardLine[0] = board[0][i]; boardLine[1] = board[1][i]; boardLine[2] = board[2][i]; boardLine[3] = board[3][i]; } string ret = checkLine(boardLine, has_empty); if(!ret.empty()){ return ret; } } } if(dir == DIAGONAL || dir == DIAGONAL_INV) { if(dir == DIAGONAL){ boardLine[0] = board[0][0]; boardLine[1] = board[1][1]; boardLine[2] = board[2][2]; boardLine[3] = board[3][3]; }else{ boardLine[0] = board[0][3]; boardLine[1] = board[1][2]; boardLine[2] = board[2][1]; boardLine[3] = board[3][0]; } return checkLine(boardLine, has_empty); } return ""; }
//--------------------------------------------------------------------------- static char putMethodLabel(ushort off) { char str[32]; int len = qsnprintf(str, sizeof(str), "met%03u_%s", curSeg.id.Number, off ? "end" : "begin"); if ( !checkLine(len)) return(1 ); out_tagon(COLOR_CODNAME); outLine(str, len); out_tagoff(COLOR_CODNAME); return(0); }
void Queen::updatePossibleMoves() { possible_move_.clear(); int x = move_history_.back().first; int y = move_history_.back().second; checkLine(x,y, -1,-1); checkLine(x,y, -1, 0); checkLine(x,y, -1, 1); checkLine(x,y, 0,-1); checkLine(x,y, 0, 1); checkLine(x,y, 1,-1); checkLine(x,y, 1, 0); checkLine(x,y, 1, 1); }
// Verifica a troca void Tela::checkSwitch(int x1, int y1, int x2, int y2) { fillUndo(); // guarda as telas em um pilha para uso da função Undo bool flag = false; char pontVetor[6]; switchElements(x1, y1, x2, y2); apply_surface(x1, y1, gems, screen); SDL_UpdateRect(screen, matriz[x1][y1].celula.x, matriz[x1][y1].celula.y, matriz[x1][y1].celula.w, matriz[x1][y1].celula.h); apply_surface(x2, y2, gems, screen); SDL_UpdateRect(screen, matriz[x2][y2].celula.x, matriz[x2][y2].celula.y, matriz[x2][y2].celula.w, matriz[x2][y2].celula.h); SDL_Delay(1000); if(checkLine(x1)) flag = true; if(checkColumn(y1)) flag = true; if(x1 != x2 && checkLine(x2)) flag = true; if(y1 != y2 && checkColumn(y2)) flag = true; if(flag) { int novosPontos = point(); user->setPontuacao(user->getPontuacao()+novosPontos); sprintf(pontVetor,"%d",user->getPontuacao()); pontosJogador = TTF_RenderText_Solid( font, pontVetor, textColor ); showPontuacao(); return; } switchElements(x2, y2, x1, y1); apply_surface(x2, y2, gems, screen); SDL_UpdateRect(screen, matriz[x2][y2].celula.x, matriz[x2][y2].celula.y, matriz[x2][y2].celula.w, matriz[x2][y2].celula.h); apply_surface(x1, y1, gems, screen); SDL_UpdateRect(screen, matriz[x1][y1].celula.x, matriz[x1][y1].celula.y, matriz[x1][y1].celula.w, matriz[x1][y1].celula.h); SDL_Delay(250); }
int winner(char** tab, int nbLines, int nbColumns,struct Coord* Coord) { int win1=0,win2=0,win3=0,win4=0; win1=checkColumn(tab,nbLines,nbColumns,Coord); win2=checkLine(tab,nbLines,nbColumns,Coord); win3=checkDiagonalL(tab,nbLines,nbColumns,Coord); win4=checkDiagonalR(tab,nbLines,nbColumns,Coord); if(Coord->y==0) if(draw(tab,nbLines,nbColumns)) { return -1; } return (win1|win2|win3|win4); }
int EEmcDbHVIO<T>::read(FILE *f) { int i=0; char line[MaxLine]; memset(bytePtr,0x00,bytes); while(fgets(line,MaxLine,f) != NULL && i<getSize()) { if( ! checkLine(line) ) continue; //if(strlen(line)<=MinLine) continue; if(! scan(line,i) ) break; if(comment && data(i)->comment[0]==0) strncpy(data(i)->comment,comment,EEMCDbMaxComment-1); i++; } return i; }
int checkWinner() { int result = 0; int i,j; for (i = 0; i < ROW; i++) { for (j = 0; j < COLUMN; j++) { if (grid[i][j] != 0) { // Check line if (checkLine(i,j) != 0) { result = checkLine(i,j); break; // Check Diagonal }else if (checkDiagonal(i,j) != 0) { result = checkDiagonal(i,j); break; } } } } return result; }
bool fixProblem(unsigned index, unsigned fix_type, MapEditor* editor) { if (index >= invalid_refs.size()) return false; if (fix_type == 0) { editor->beginUndoRecord("Correct Line Sector"); // Set sector sector_ref_t ref = invalid_refs[index]; if (ref.sector) map->setLineSector(ref.line->getIndex(), ref.sector->getIndex(), ref.front); else { // Remove side if no sector if (ref.front && ref.line->s1()) map->removeSide(ref.line->s1()); else if (!ref.front && ref.line->s2()) map->removeSide(ref.line->s2()); } // Flip line if needed if (!ref.line->s1() && ref.line->s2()) ref.line->flip(); editor->endUndoRecord(); // Remove problem (and any others for the line) for (unsigned a = 0; a < invalid_refs.size(); a++) { if (invalid_refs[a].line == ref.line) { invalid_refs.erase(invalid_refs.begin() + a); a--; } } // Re-check line checkLine(ref.line); editor->updateDisplay(); return true; } return false; }
bool canConquerDR(int c, int r,int p, int** board){ bool check = false; // impossible to conquer if space is less than 2 if (c < 6 && r < 6 ) { // impossible enclose upwards if adjacent upwards chip is not // opponent if (board[c+1][r+1] == op(p)) { int value = checkLine(op(p), (c+1), (r+1) ,1, 1, board); check = value ==p; } } return check; };