void push(stack *stackP, stackElementT element) { if (checkFull(stackP)) { fprintf(stderr, "Can't push element on stack: stack is full.\n"); exit(1); /* Exit, returning error code. */ } // top gets incremented before it is used as an index for the array stackP->contents[++stackP->top] = element; }
void OrientationIntervals::addOrientation(int orientation) { assert(orientation >= minOrientation && orientation <= maxOrientation); OrientationInterval newInt; newInt.lower = orientation; newInt.upper = orientation; if(intervals.empty()){ intervals.push_back(newInt); } else { //check if already contained in an interval, at the same time, search for right position to insert std::vector<OrientationInterval>::iterator it = intervals.begin(); std::vector<OrientationInterval>::iterator end = intervals.end(); while(it!=end && it->lower <= orientation){ if(it->upper >= orientation){ std::cerr<<"orientation "<<orientation<<" already contained in "<<print()<<std::endl; return; } ++it; } // if(intervals.back().upper < intervals.back().lower && orientation < intervals.back().upper){ // std::cerr<<"orientation "<<orientation<<" already contained in "<<print()<<std::endl; // return; // } it = intervals.insert(it, newInt); std::vector<OrientationInterval>::iterator previous = it; if(previous != intervals.begin()){ previous --; } else { previous = intervals.end() - 1; } //std::cerr<<"previous "<<previous->lower<<" current "<<it->lower<<std::endl; it = checkMergeIntervalPrevious(previous, it); std::vector<OrientationInterval>::iterator next = it; if(it+1 != intervals.end()){ next = it+1; } else { next = intervals.begin(); } //std::cerr<<"current "<<it->lower<<" next "<<next->lower<<std::endl; it = checkMergeIntervalNext(it, next); checkFull(); } }
/*Соединение к столу*/ void connectTable(void *buf) { struct newPlayer_t newPlayer; struct selectRequest_t *request = (struct selectRequest_t *) buf; struct selectResponce_t responce; int check, id; /*Проверка id стола*/ if ((check = checkTable(request->tableID)) == -1) { responce.status = STATUS_BAD; strcpy(responce.error, "Incorrectly table id"); printf("[logic]User send incorrectly table id\n"); send_message(CURRENT, 0, CONNECT_TO_TABLE, sizeof(struct selectResponce_t), &responce); return; } /*Проверка колличества игроков на столе*/ if (checkFull(check) == -1) { responce.status = STATUS_BAD; strcpy(responce.error, "Table full"); printf("[logic]User try connect to full table\n"); send_message(CURRENT, 0, CONNECT_TO_TABLE, sizeof(struct selectResponce_t), &responce); return; } id = getIDtoName(request->name); /*Нет id*/ if (id == -1) { responce.status = STATUS_BAD; strcpy(responce.error, "Incorrectly id"); printf("[logic]User with incorrectly id\n"); send_message(CURRENT, 0, CREATE_TABLE, sizeof(struct selectResponce_t), &responce); return; } ++countCurrentTables; int newSessison = getSession(); newPlayer.session = newSessison; newPlayer.money = 1000; strncpy(newPlayer.name, request->name, MAX_NAME_LENGTH); responce.status = STATUS_OK; responce.session = newSessison; responce.port = inofList[check].port; send_message(GAME_SERVER, tableID, INTERNAL_NEW_PLAYER, sizeof(struct newPlayer_t), (void *) &newPlayer); send_message(CURRENT, 0, CONNECT_TO_TABLE, sizeof(struct selectResponce_t), (void *) &responce); close_current_client_connection(); printf("[Logic]User connect o table\n"); }
void T2::checkMove(int dir_guester) { if(dir_guester== DIR_RIGHT){ //≈ì√ö‚Äù‚Ä? if (move_state == MOVE_YD1) //¬µ‚ÅÑ‚Äú¬™‚⧌©‚Äú‚àÜ‚àÇ√? { for (int i=0;i<MAX_ROW;i++) { for (int j = MAX_COL-2; j >=0 ; --j) { int index = -1; int count = 0; if(arr_Num[i][j]>-1&&arr_Num[i][j+1]==-1)//¬ª√ÅœÄÀö‚Äù‚Äú¬±Ô¨Ç¬†¬´√∏‚Äô¬µ∆? { bemoved_yd1 = true; index = j+1; while (arr_Num[i][index]==-1) { count++; if(index<MAX_COL-1) index++; else break; } nodeMove(dir_guester,i,j,count); change2number(arr_Num[i][j],arr_Num[i][j+count]); } } } logcat_chessArr("move-yd1"); if(bemoved_yd1){ CCLog("can move yd1"); move_state = MOVE_NONE; }else{ CCLog("can not move yd1"); move_state = MOVE_HETI; } } else if(move_state == MOVE_HETI)//¬µ‚Å?‚⧌©‚à´≈ì‚â•‚Ä? { CCLog("rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"); update_moveyd1(); for (int i=0;i<MAX_ROW;i++) { for (int j=MAX_COL-1;j>0;j--) { if(arr_Num[i][j]>=0&&arr_Num[i][j]==arr_Num[i][j-1]&&arr_Num[i][j]==arr_Num[i][j-2]&&arr_Num[i][j]==arr_Num[i][j-3]) { CCLog("ppppppppppppppp"); becomposed = true; arr_Num[i][j]++; arr_Num[i][j-1]= -1; addScore(arr_Num[i][j]); change(dir_guester,i,j,arr_Num[i][j]); removeChessnode(dir_guester,i,j-1); MyCCLog::verbose("score---"); break; } else if(arr_Num[i][j]>=0&&arr_Num[i][j]==arr_Num[i][j-1]) { CCLog("qqqqqqqqqqqqqq"); becomposed = true; arr_Num[i][j]++; arr_Num[i][j-1]= -1; addScore(arr_Num[i][j]); change(dir_guester,i,j,arr_Num[i][j]); removeChessnode(dir_guester,i,j-1); } } } CCLog("tttttttttttttttttttttttttttttttttttttttttttttttttttttttt"); logcat_chessArr("right-move-heti1"); if(bemoved_yd1&&!becomposed) { CCLog("can move and can not heti"); move_state = MOVE_OVER; return; } move_state = MOVE_NONE; } else if(move_state == MOVE_YD2) { CCLog("MOVE_YD2MOVE_YD2"); for (int i=0;i<MAX_ROW;i++) { for (int j = MAX_COL-2; j >=0 ; --j) { int index = -1; int count = 0; if(arr_Num[i][j]>-1&&arr_Num[i][j+1]==-1)//¬ª√ÅœÄÀö‚Äù‚Äú¬±Ô¨Ç¬†¬´√∏‚Äô¬µ∆? { index = j+1; while (arr_Num[i][index]==-1) { count++; if(index<MAX_COL-1) index++; else break; } nodeMove(dir_guester,i,j,count); change2number(arr_Num[i][j],arr_Num[i][j+count]); } } } logcat_chessArr("move-yd2"); move_state = MOVE_OVER; } else if(move_state == MOVE_OVER) { CCLog("right-----------move-over---over"); addNewChess(); move_state = MOVE_NONE; if(checkFull()) { bool rightover = checkGameOver(); CCLog("rightover = %d",rightover); } } } else if(dir_guester== DIR_LEFT){ //≈ì√ö‚Äù‚Ä? if (move_state == MOVE_YD1) //¬µ‚ÅÑ‚Äú¬™‚⧌©‚Äú‚àÜ‚àÇ√? { for (int i=0;i<MAX_ROW;i++) { for (int j =1; j < MAX_COL ; j++) { int index = -1; int count = 0; if(arr_Num[i][j]>-1&&arr_Num[i][j-1]==-1)//¬ª√ÅœÄÀö‚Äù‚Äú¬±Ô¨Ç¬†¬´√∏‚Äô¬µ∆? { bemoved_yd1 = true; index = j-1; while (arr_Num[i][index]==-1) { count++; if(index>0) index--; else break; } nodeMove(dir_guester,i,j,count); change2number(arr_Num[i][j],arr_Num[i][j-count]); } } } logcat_chessArr("left-move-yd1"); if(bemoved_yd1){ CCLog("can move left yd1"); move_state = MOVE_NONE; }else{ CCLog("can not move left yd1"); move_state = MOVE_HETI; } } else if(move_state == MOVE_HETI)//¬µ‚Å?‚⧌©‚à´≈ì‚â•‚Ä? { update_moveyd1(); for (int i=0;i<MAX_ROW;i++) { for (int j=0;j<MAX_COL-1;j++) { if(arr_Num[i][j]>=0&&arr_Num[i][j]==arr_Num[i][j+1]&&arr_Num[i][j]==arr_Num[i][j+2]&&arr_Num[i][j]==arr_Num[i][j+3]) { CCLog("wdddddddsssssss"); becomposed = true; arr_Num[i][j]++; arr_Num[i][j+1]= -1; addScore(arr_Num[i][j]); change(dir_guester,i,j,arr_Num[i][j]); removeChessnode(dir_guester,i,j+1); break; } if(arr_Num[i][j]>=0&&arr_Num[i][j]==arr_Num[i][j+1]) { CCLog("ssssdwww"); becomposed = true; arr_Num[i][j]++; arr_Num[i][j+1]= -1; addScore(arr_Num[i][j]); change(dir_guester,i,j,arr_Num[i][j]); removeChessnode(dir_guester,i,j+1); } } } CCLog("tttttttttttttttttttttttttttttttttttttttttttttttttttttttt"); logcat_chessArr("left-move-heti1"); if(bemoved_yd1&&!becomposed) { CCLog("can move and can not heti"); move_state = MOVE_OVER; return; } move_state = MOVE_NONE; } else if(move_state == MOVE_YD2) { CCLog("MOVE_YD2MOVE_YD2"); for (int i=0;i<MAX_ROW;i++) { for (int j =1; j < MAX_COL ; j++) { int index = -1; int count = 0; if(arr_Num[i][j]>-1&&arr_Num[i][j-1]==-1)//¬ª√ÅœÄÀö‚Äù‚Äú¬±Ô¨Ç¬†¬´√∏‚Äô¬µ∆? { bemoved_yd1 = true; index = j-1; while (arr_Num[i][index]==-1) { count++; if(index>0) index--; else break; } nodeMove(dir_guester,i,j,count); change2number(arr_Num[i][j],arr_Num[i][j-count]); } } } logcat_chessArr("move-yd2"); move_state = MOVE_OVER; } else if(move_state == MOVE_OVER) { CCLog("left-----------move-over---over"); addNewChess(); if(checkFull()) { bool leftover = checkGameOver(); CCLog("leftover = %d",leftover); } move_state = MOVE_NONE; } } else if(dir_guester == DIR_UP){ //≈ì√ö‚Ķ≈? if (move_state == MOVE_YD1) //¬µ‚ÅÑ‚Äú¬™‚⧌©‚Äú‚àÜ‚àÇ√? { for (int j =0; j < MAX_COL ; j++)//lie { for (int i= MAX_ROW-2;i>=0;i--)//hang { int index = -1; int count = 0; if(arr_Num[i][j]>-1&&arr_Num[i+1][j]==-1)//¬ª√ÅœÄÀö‚Äù‚Äú¬±Ô¨Ç¬†¬´√∏‚Äô¬µ∆? { bemoved_yd1 = true; index = i+1; while (arr_Num[index][j]==-1) { count++; if(index<MAX_ROW-1) index++; else break; } CCLog("j = %d i= %d COUNT = %d",j,i,count); nodeMove(dir_guester,j,i,count); change2number(arr_Num[i][j],arr_Num[i+count][j]); } } } logcat_chessArr("up-move-yd1"); if(bemoved_yd1){ CCLog("up -can move yd1"); move_state = MOVE_NONE; }else{ CCLog("up-can not move yd1"); move_state = MOVE_HETI; } } else if(move_state == MOVE_HETI)//¬µ‚Å?‚⧌©‚à´≈ì‚â•‚Ä? { CCLog("mmmmmmmmmmmmmmmmmm"); update_moveyd1(); for (int j=0;j<MAX_COL;j++) { for (int i=MAX_ROW-1;i>0;i--) { if(arr_Num[i][j]>=0&&arr_Num[i][j]==arr_Num[i-1][j]&&arr_Num[i][j]==arr_Num[i-2][j]&&arr_Num[i][j]==arr_Num[i-3][j]) { CCLog("ppppppppppppppp"); becomposed = true; arr_Num[i][j]++; arr_Num[i-1][j]= -1; addScore(arr_Num[i][j]); change(dir_guester,j,i,arr_Num[i][j]); removeChessnode(dir_guester,j,i-1); break; } else if(arr_Num[i][j]>=0&&arr_Num[i][j]==arr_Num[i-1][j]) { CCLog("qqqqqqqqqqqqqq"); becomposed = true; arr_Num[i][j]++; arr_Num[i-1][j]= -1; addScore(arr_Num[i][j]); change(dir_guester,j,i,arr_Num[i][j]); removeChessnode(dir_guester,j,i-1); } } } CCLog("vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv"); logcat_chessArr("up------move-heti1"); if(bemoved_yd1&&!becomposed) { CCLog("can move and can not heti"); move_state = MOVE_OVER; return; } move_state = MOVE_NONE; } else if(move_state == MOVE_YD2) { for (int j =0; j < MAX_COL ; j++)//lie { for (int i= MAX_ROW-2;i>=0;i--)//hang { int index = -1; int count = 0; if(arr_Num[i][j]>-1&&arr_Num[i+1][j]==-1)//¬ª√ÅœÄÀö‚Äù‚Äú¬±Ô¨Ç¬†¬´√∏‚Äô¬µ∆? { bemoved_yd1 = true; index = i+1; while (arr_Num[index][j]==-1) { count++; if(index<MAX_ROW-1) index++; else break; } CCLog("j = %d i= %d COUNT = %d",j,i,count); nodeMove(dir_guester,j,i,count); change2number(arr_Num[i][j],arr_Num[i+count][j]); } } } logcat_chessArr("move-yd2"); move_state = MOVE_OVER; } else if(move_state == MOVE_OVER) { CCLog("up-----------move-over---over"); addNewChess(); if(checkFull()) { bool upover = checkGameOver(); CCLog("upover = %d",upover); } move_state = MOVE_NONE; } } else if(dir_guester == DIR_DOWN){ if (move_state == MOVE_YD1) //¬µ‚ÅÑ‚Äú¬™‚⧌©‚Äú‚àÜ‚àÇ√? { for (int j =0; j < MAX_COL ; j++)//lie { for (int i= 1;i< MAX_ROW;i++)//hang { int index = -1; int count = 0; if(arr_Num[i][j]>-1&&arr_Num[i-1][j]==-1)//¬ª√ÅœÄÀö‚Äù‚Äú¬±Ô¨Ç¬†¬´√∏‚Äô¬µ∆? { bemoved_yd1 = true; index = i-1; while (arr_Num[index][j]==-1) { count++; if(index>0) index--; else break; } CCLog("j = %d i= %d COUNT = %d",j,i,count); nodeMove(dir_guester,j,i,count); change2number(arr_Num[i][j],arr_Num[i-count][j]); } } } logcat_chessArr("down-move-yd1"); if(bemoved_yd1){ CCLog("down -can move yd1"); move_state = MOVE_NONE; }else{ CCLog("down-can not move yd1"); move_state = MOVE_HETI; } } else if(move_state == MOVE_HETI)//¬µ‚Å?‚⧌©‚à´≈ì‚â•‚Ä? { CCLog("mmmmmmmmmmmmmmmmmm"); update_moveyd1(); for (int j=0;j<MAX_COL;j++) { for (int i=0;i<MAX_ROW-1;i++) { if(arr_Num[i][j]>=0&&arr_Num[i][j]==arr_Num[i+1][j]&&arr_Num[i][j]==arr_Num[i+2][j]&&arr_Num[i][j]==arr_Num[i+3][j]) { CCLog("ppppppppppppppp"); becomposed = true; arr_Num[i][j]++; arr_Num[i+1][j]= -1; addScore(arr_Num[i][j]); change(dir_guester,j,i,arr_Num[i][j]); removeChessnode(dir_guester,j,i+1); break; } else if(arr_Num[i][j]>=0&&arr_Num[i][j]==arr_Num[i+1][j]) { CCLog("qqqqqqqqqqqqqq"); becomposed = true; arr_Num[i][j]++; arr_Num[i+1][j]= -1; addScore(arr_Num[i][j]); change(dir_guester,j,i,arr_Num[i][j]); removeChessnode(dir_guester,j,i+1); } } } CCLog("vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv"); logcat_chessArr("down------move-heti1"); if(bemoved_yd1&&!becomposed) { CCLog("can move and can not heti"); move_state = MOVE_OVER; return; } move_state = MOVE_NONE; } else if(move_state == MOVE_YD2) { for (int j =0; j < MAX_COL ; j++)//lie { for (int i= 1;i< MAX_ROW;i++)//hang { int index = -1; int count = 0; if(arr_Num[i][j]>-1&&arr_Num[i-1][j]==-1)//¬ª√ÅœÄÀö‚Äù‚Äú¬±Ô¨Ç¬†¬´√∏‚Äô¬µ∆? { bemoved_yd1 = true; index = i-1; while (arr_Num[index][j]==-1) { count++; if(index>0) index--; else break; } CCLog("j = %d i= %d COUNT = %d",j,i,count); nodeMove(dir_guester,j,i,count); change2number(arr_Num[i][j],arr_Num[i-count][j]); } } } logcat_chessArr("move-yd2"); move_state = MOVE_OVER; } else if(move_state == MOVE_OVER) { CCLog("down-----------move-over---over"); addNewChess(); if(checkFull()) { bool downover = checkGameOver(); CCLog("downover = %d",downover); } move_state = MOVE_NONE; } } }