void CFieldHandler::UpdatePossibleMoves(int Index) { for(int b = 0; b < NUM_COLORS*NUM_SHAPES; ++b) { CStoneHandler::CStone *pStone = new CStoneHandler::CStone(); pStone->m_Color = b%NUM_COLORS; pStone->m_Shape = (b-pStone->m_Color)/NUM_COLORS; int points = CanPlace(Index, pStone); if(points > 0) { CMoveHandler::CMove *pTemp = new CMoveHandler::CMove(); pTemp->m_FieldIndex = Index; if(!pStone) printf("WTF"); pTemp->m_pStone = pStone; pTemp->m_Points = points; if(!m_PossibleStones.IsExisting(pTemp)) m_PossibleStones.m_lpMoves.add(pTemp); } else delete pStone; } }
void CFieldHandler::InitPossibleMoves() { m_PossibleStones.m_lpMoves.hint_size(128); for(int a = 0; a < FIELD_WIDTH*FIELD_HEIGHT; ++a) { for(int b = 0; b < NUM_COLORS*NUM_SHAPES; ++b) { CStoneHandler::CStone *pStone = new CStoneHandler::CStone(); pStone->m_Color = b%NUM_COLORS; pStone->m_Shape = (b-pStone->m_Color)/NUM_COLORS; int points = CanPlace(a, pStone); if(points > 0) { CMoveHandler::CMove *pTemp = new CMoveHandler::CMove(); pTemp->m_FieldIndex = a; pTemp->m_pStone = pStone; pTemp->m_Points = points; if(!m_PossibleStones.IsExisting(pTemp)) m_PossibleStones.m_lpMoves.add(pTemp); else delete pTemp; } else delete pStone; } } }
// я╜╩╥еп╤оя╟ур╫Б void GetResult() { int j; int i; for( i = 0; i<4; i++) for ( j = 0; j < 4; j++) if( CanPlace(i,j) ) Board[i][j] = 1; }
void CFieldHandler::UpdatePossibleMoves(){ for(int i = 0; i < m_PossibleStones.m_lpMoves.size();) { if(CanPlace(m_PossibleStones.m_lpMoves[i]->m_FieldIndex, m_PossibleStones.m_lpMoves[i]->m_pStone) == 0) { delete m_PossibleStones.m_lpMoves[i]; m_PossibleStones.m_lpMoves.remove_index(i); continue; } ++i; } }
// Attempt to insert an entry into the table // Will fail if no room or a duplicate key is found. RETURN_TYPE AE_LoadImage( IMAGE *image ) { // Retrieve hashed index from string unsigned index = UHashMod( image->ID ); unsigned indexStart = index; // Search for empty or deleted location in table with linear probing while(!CanPlace( IMABE_TABLE, index )) { // Break from the loop if a duplicate is found if(strcmp( IMABE_TABLE[index]->ID, image->ID ) == 0) break; ++index; // wraparound to beginning of table instead of index beyond table if(index == TABLESIZE) { index = 0; } // If searched entire table (means table is full) if(indexStart == index) { isTableFull = TRUE; // set the isTableFull flag break; } } // Skip the allocation process if a duplicate entry is found if(HasEntry( IMABE_TABLE, index )) { if(strcmp( IMABE_TABLE[index]->ID, image->ID ) == 0) { return RETURN_FAILURE; } } // Skip the alloction process if there's no room in the table. if(isTableFull == TRUE) return RETURN_FAILURE; IMABE_TABLE[index] = image; return RETURN_SUCCESS; }
CanPlace CrossWordsField::CanPlaceToCrossPos(Cross crossPos, Word word) { Point shitTop = Point(crossPos._point.X, crossPos._point.Y - word.Text.find(crossPos._symbol,0)); Point shitLeft = Point(crossPos._point.X - word.Text.find(crossPos._symbol, 0), crossPos._point.Y); auto canTop = true; auto canLeft = true; auto topCrossingCount = 0; auto leftCrossingCount = 0; // try top for (int index = 0; index < word.Text.length(); index++) { auto c = word.Text.at(index); auto internalChar = InternalMatrix[shitTop.X][ shitTop.Y + index]; if ((internalChar.Symbol == DefSymbol) || (internalChar.Symbol == c)) { if (internalChar.Symbol == c) { topCrossingCount++; } if (topCrossingCount > 1) { canTop = false; break; } continue; } else { canTop = false; break; } } for (int index = 0; index < word.Text.length(); index++) { auto c = word.Text.at(index); auto internalChar = InternalMatrix[shitLeft.X + index][ shitLeft.Y]; if ((internalChar.Symbol == DefSymbol) || (internalChar.Symbol == c)) { if (internalChar.Symbol == c) { leftCrossingCount++; } if (leftCrossingCount > 1) { canLeft = false; break; } continue; } else { canLeft = false; break; } } return CanPlace(canTop, shitTop, canLeft, shitLeft); }