void test::TestComponentPool() { auto components = new stoked::ComponentPool<ComponentA>(4); auto c1 = components->Get(); auto c2 = components->Get(); auto c3 = components->Get(); auto c4 = components->Get(); assert(c1 != nullptr); assert(c2 != nullptr); assert(c3 != nullptr); assert(c4 != nullptr); assert(c1->GetID() < components->GetCapacity()); assert(c2->GetID() < components->GetCapacity()); assert(c3->GetID() < components->GetCapacity()); assert(c4->GetID() < components->GetCapacity()); // Currently, when "Get" is called, the component is not "free", in the sense that it is assumed that it is // attached to an entity. This is actually pretty confusing. assert(!c1->IsFree()); assert(!c2->IsFree()); assert(!c3->IsFree()); assert(!c4->IsFree()); PASSED(); }
void CMap::Input(Vec2I position) { Vec2I end_pos(position.x / GRID_WIDTH, position.y / GRID_HEIGHT); DEBUG_TRACE("start:%d,%d\tend:%d,%d\n", m_pos.x, m_pos.y, end_pos.x, end_pos.y); if (! IsFree(end_pos)) return; QWORD start_time = GetTimer()->GetTime(); if (m_Astar.FindPath(m_pos, end_pos)) { QWORD end_time = GetTimer()->GetTime(); DEBUG_TRACE("find path time:%f\n", GetTimer()->GetTimeMillisec(end_time - start_time)); m_findPath.clear(); std::vector<Vec2I>& vec = m_Astar.GetPath(); m_findPath.reserve(vec.size()); for (int i = 0; i < vec.size(); ++i) { Vec2I pt = vec[i]; m_findPath.push_back(Grid2CenterPt(pt)); } m_pos = end_pos; m_rect.SetRect(m_pos.x * GRID_WIDTH, m_pos.y * GRID_HEIGHT, (m_pos.x + 1) * GRID_WIDTH, (m_pos.y + 1) * GRID_HEIGHT); } }
bool HP_HogMode::CurrentProcessIsOwnerOrIsFree() const { if(mOwner == -2) { const_cast<HP_HogMode*>(this)->mOwner = GetOwnerFromPreference(true); } return (CurrentProcessIsOwner() || IsFree()); }
// -------------------------------------------------------------------------------- // Name : AddAtEmptySpot // Description : Add the given rectangle // -------------------------------------------------------------------------------- bool CRectPlacement::AddAtEmptySpot (TRect &r) { // Find a valid spot among available anchors. bool bFound = false; CPosArray::iterator it; for (it = m_vPositions.begin(); !bFound && it != m_vPositions.end(); ++it) { TRect Rect(it->x, it->y, r.w, r.h); if (IsFree(Rect)) { r = Rect; bFound = true; break; // Don't let the loop increase the iterator. } } if (bFound) { // Remove the used anchor point m_vPositions.erase(it); // Sometimes, anchors end up displaced from the optimal position // due to irregular sizes of the subrects. // So, try to adjut it up & left as much as possible. int x,y; for (x = 1; x <= r.x; x++) if (!IsFree(TRect(r.x - x, r.y, r.w, r.h))) break; for (y = 1; y <= r.y; y++) if (!IsFree(TRect(r.x, r.y - y, r.w, r.h))) break; if (y > x) r.y -= y-1; else r.x -= x-1; AddRect(r); } return bFound; }
/// <summary> This method computes the exact external degree </summary> /// <param name="i">variable</param> /// <returns>degree</returns> long MD_Qqraph :: ExternalDegree(long i) { long idx, idx2; long d = 0; long na = A [ i ]->Count; long ne = E [ i ]->Count; long *pa = A [ i ]->Items, *pe = E [ i ]->Items; { //foreach(long a in A[i]) if(pPIdx[a]==0) {pLIdx[a] = 1;d++;} for ( idx = na - 1; idx >= 0; idx-- ) { long a = pa [ idx ]; if ( pPIdx [ a ] == 0 ) { pLIdx [ a ] = 1; d++; } } //foreach(long e in E[i]) foreach(long j in L[e])if (pPIdx[j]==0 && pLIdx[j]!=1) {pLIdx[j] = 1;d++;} for ( idx = ne - 1; idx >= 0; idx-- ) { long e = pe [ idx ]; //foreach(long j in L[e]) IntArrayList &Lp = * L [ e ]; for ( idx2 = 0; idx2 < Lp.Count; idx2++ ) { long j = Lp [ idx2 ]; if ( pPIdx [ j ] == 0 && pLIdx [ j ] != 1 ) { pLIdx [ j ] = 1; d++; } } } //foreach(long a in A[i]) pLIdx[a] = 0; A [ i ]->SetIndexesTo(pLIdx, 0); //foreach(long e in E[i]) foreach(long j in L[e]) if(pPIdx[j]==0) pLIdx[j] = 0; for ( idx = ne - 1; idx >= 0; idx-- ) { long e = pe [ idx ]; //foreach(long j in L[e]) IntArrayList &Lp = * L [ e ]; for ( idx2 = 0; idx2 < Lp.Count; idx2++ ) { long j = Lp [ idx2 ]; if ( pPIdx [ j ] == 0 ) { pLIdx [ j ] = 0; } } } if ( MinDegB > d && IsFree(i) ) { MinDegB = d; vi_Min = i; } } return d; }
bool CFieldHandler::CheckRestrictions(int FieldIndex) { if(m_Moves > 6) return false; if(m_aRestrictions[0] != -1) { int x1 = m_aRestrictions[0]%FIELD_WIDTH; int y1 = (m_aRestrictions[0]-x1)/FIELD_WIDTH; int x2 = FieldIndex%FIELD_WIDTH; int y2 = (FieldIndex-x2)/FIELD_WIDTH; int diffX = x2-x1; int diffY = y2-y1; if(diffX != 0 && diffY != 0) return false; if(m_aRestrictions[1] != -1) { int x3 = m_aRestrictions[1]%FIELD_WIDTH; int y3 = (m_aRestrictions[1]-x3)/FIELD_WIDTH; if(diffX == 0 && (x3-x1) != 0) { return false; } else if(diffY == 0 && (y3-y1) != 0) { return false; } } { int dir = 1; if(diffY != 0) dir = diffY > 0 ? FIELD_WIDTH : -FIELD_WIDTH; else if(diffX != 0) dir = diffX > 0 ? 1 : -1; for(int i = m_aRestrictions[0]; i < FIELD_WIDTH*FIELD_WIDTH; i += dir) { if(i == FieldIndex) break; if(IsFree(i)) return false; } } } return true; }
bool CFieldHandler::UpdateFirstMove() { m_IsFirstMove = true; for(int i = 0; i < FIELD_WIDTH*FIELD_HEIGHT; ++i) { if(!IsFree(i)) { m_IsFirstMove = false; break; } } return m_IsFirstMove; }
long MD_Qqraph :: ApproximateMinumumDegree(long i, IntArrayList &Lp) { IntArrayList &Ali = * A [ i ]; IntArrayList &Eli = * E [ i ]; long idx; //long na = Ali.Count; long ne = Eli.Count; long *pe = Eli.Items; { long Aic = 0; //foreach(long j in A[i]) if (pPIdx[j]==0) Aic++; Aic += Ali.CountWithoutMask(pPIdx); long Lpc = 0; //foreach(long j in Lp) if (pPIdx[j]==0) Lpc++; for ( idx = 0; idx < Lp.Count; idx++ ) { long j = Lp [ idx ]; if ( pPIdx [ j ] == 0 ) { Lpc++; } } long d = std::min(n - this->no_elements, degrees [ i ] + Lpc); long Les = 0; //foreach(long e in E[i]) if (amd_w[e]<0) Les += L[e].Length; else Les += amd_w[e]; for ( idx = ne - 1; idx >= 0; idx-- ) { long e = pe [ idx ]; if ( amd_w [ e ] < 0 ) { Les += L [ e ]->Count; } else { Les += amd_w [ e ]; } } d = std::min(d, Aic + Lpc + Les); if ( MinDegB > d && IsFree(i) ) { MinDegB = d; vi_Min = i; } return d; } }
void HP_HogMode::Take() { if(IsFree()) { // set the new owner mOwner = CAProcess::GetPID(); // write the new owner's pid to the preferences SetOwnerInPreference(mOwner); // tell the device that the hog mode state has changed mDevice->HogModeStateChanged(); // signal that hog mode changed to the device CAPropertyAddress theAddress(kAudioDevicePropertyHogMode); mDevice->PropertiesChanged(1, &theAddress); // signal that hog mode changed to the world SendHogModeChangedNotification(); } }
TEST_F(GlobalAllocatorTest, RequestBlock) { auto instance = gcix::GlobalAllocator::Instance; ASSERT_NE(nullptr, instance); // Check internals ASSERT_EQ(0, instance->Chunks.Count()); // Request a memory block auto blockData0 = instance->RequestBlock(false); ASSERT_EQ(1, instance->Chunks.Count()); // Gets the chunk auto chunk0 = instance->Chunks[0]; ASSERT_NE(nullptr, chunk0); // Check that a chunk has the same address as the first block data EXPECT_EQ((void*)chunk0, (void*)blockData0); EXPECT_TRUE(chunk0->IsFree()); EXPECT_TRUE(chunk0->HasFreeBlocks()); EXPECT_FALSE(chunk0->HasRecyclableBlocks()); // Check block count per chunk EXPECT_EQ(Constants::BlockCountPerChunk, chunk0->GetBlockCount()); // Check allocated blocks for (int i = 0; i < chunk0->GetBlockCount(); i++) { auto block = chunk0->GetBlock(i); if (i == 0) { EXPECT_EQ(block, blockData0); } EXPECT_TRUE(block->IsFree()); EXPECT_FALSE(block->IsRecyclable()); EXPECT_FALSE(block->IsUnavailable()); // Check that all block data are aligned on a block size EXPECT_EQ(0, (intptr_t)block & Constants::BlockSizeInBytesMask); // Check line flags are empty for (uint32_t lineIndex = Constants::HeaderLineCount; lineIndex < Constants::LineCount; lineIndex++) { EXPECT_EQ(LineFlags::Empty, block->Header.LineFlags[lineIndex]); // Check line datas are empty for (uint32_t columnIndex = 0; columnIndex < Constants::LineSizeInBytes; columnIndex++) { EXPECT_EQ(0, block->Lines[lineIndex][columnIndex]); } } } // Check Bump cursor in BlockData, must be equal to the header size EXPECT_EQ(Constants::HeaderSizeInBytes, blockData0->Header.Info.BumpCursor); // Check BumpCursorLimit = 0 EXPECT_EQ(0, blockData0->Header.Info.BumpCursorLimit); // Check Chunk min/max memory auto minChunkAddress = chunk0; auto maxChunkAddress = (Chunk*)((intptr_t)chunk0 + Constants::BlockSizeInBytes * Constants::BlockCountPerChunk); // Check pointers inside the chunk EXPECT_TRUE(instance->Chunks.Contains(chunk0)); EXPECT_TRUE(instance->Chunks.Contains((Chunk*)((intptr_t)maxChunkAddress - 1))); // Check pointers outside the chunk EXPECT_FALSE(instance->Chunks.Contains((Chunk*)((intptr_t)chunk0 - 1))); EXPECT_FALSE(instance->Chunks.Contains(maxChunkAddress)); // Allocate remaining blocks into the chunk for (int i = 1; i < chunk0->GetBlockCount(); i++) { auto nextBlock = instance->RequestBlock(false); EXPECT_TRUE(instance->Chunks.Contains((Chunk*)nextBlock)); } // Reallocate a new block from a new chunk auto nextBlockOfNextChunj = instance->RequestBlock(false); auto nextChunk = (Chunk*)nextBlockOfNextChunj; EXPECT_TRUE(nextChunk < minChunkAddress || nextChunk > maxChunkAddress); // Recycle freshly allocated block, as they have not been marked, the nextChunk must be freed by the recycle // while the firstChunk must be kept for future allocation. instance->Recycle(); EXPECT_EQ(1, instance->Chunks.Count()); // TODO Add tests after recycle }
void SDeferredLinetestReceiver::OnDataReceived( const QueuedRayID& rayID, const RayCastResult& result ) { CRY_ASSERT(rayID == queuedRayID); CPlayerVisTable * visTable = g_pGame->GetPlayerVisTable(); //This may be receiving results from the previous frame's physics, when // the game has just been reset and the vis table with it if(!IsFree()) { SDeferredLinetestBuffer& visBuffer = visTable->GetDeferredLinetestBuffer(visBufferIndex); if(IsValid()) { SVisTableEntry& visEntry = visTable->GetNthVisTableEntry(visTableIndex); const bool obstructed = (result.hitCount > 0); if(obstructed) { //The linetest hit something en route to the target visEntry.flags &= ~(eVF_Visible|eVF_VisibleThroughGlass|eVF_Requested|eVF_Pending|eVF_CheckAgainstCenter); bool isGlass = true; int i = 0; while(i < result.hitCount && isGlass) { float bouncy, friction; uint32 pierceabilityMat; gEnv->pPhysicalWorld->GetSurfaceParameters(result.hits[i].surface_idx, bouncy, friction, pierceabilityMat); pierceabilityMat &= sf_pierceable_mask; if(pierceabilityMat <= PIERCE_GLASS) { isGlass = false; } i++; } if(isGlass) { visEntry.flags |= eVF_VisibleThroughGlass; } else if (result->pCollider->GetType() == PE_ARTICULATED) { visEntry.flags |= eVF_Visible; } else if(IEntity* pTarget = gEnv->pEntitySystem->GetEntityFromPhysics(result->pCollider)) { // Test if this is an environmental weapon. If so, get its OWNER (the owner is still visible). CEnvironmentalWeapon *pEnvWeapon = static_cast<CEnvironmentalWeapon*>(g_pGame->GetIGameFramework()->QueryGameObjectExtension(pTarget->GetId(), "EnvironmentalWeapon")); if(pEnvWeapon && pEnvWeapon->GetOwner() == visEntry.entityId) { visEntry.flags |= eVF_Visible | eVF_VisibleThroughGlass; } } } else { visEntry.flags |= eVF_Visible | eVF_VisibleThroughGlass; visEntry.flags &= ~(eVF_Requested|eVF_Pending|eVF_CheckAgainstCenter); } #if ALLOW_VISTABLE_DEBUGGING visTable->GetDebugDraw().UpdateDebugTarget(visEntry.entityId, ZERO, !obstructed); #endif queuedRayID = 0; //Pending ray processed SetInvalid(); visEntry.framesSinceLastCheck = 0; } //Mark this SVisTableEntry_Processing as available SetFree(); visBuffer.m_numLinetestsCurrentlyProcessing--; } }
/// <summary> /// Returns the permutation according to minimum degree algorithm. /// </summary> /// <param name="approximate_degree"> true=approximate degree, false=true external degree</param> /// <returns>permutation vector</returns> IntArrayList *MD_Qqraph :: GenerateMD(bool approximate_degree, IntArrayList *fixed) { this->approximate_degree = approximate_degree; no_elements = 0; ht.Init(n); // temporarly used as the index array // eventually this array contains the permutation long *permutation = new long [ n ]; // this array stores elements on position [0..no_elements-1] and then variables [no_elements..n] // Finally this array contains Order of eliminated elemtents long *vlasts = new long [ n ]; long *vnexts = new long [ n ]; // number of fixed nodes which must be ordered to the end of the list long no_fixed = 0; if ( fixed ) { pfixed = new long [ n ]; Array :: Clear(pfixed, 0, n); fixed->SetIndexesTo(pfixed, 1); no_fixed = fixed->Count; } elements = new IntArrayList(n); elements->Alloc(); long *pivot_pattern = new long [ n ]; memset( pivot_pattern, 0, n * sizeof( long ) ); degrees = new long [ n ]; amd_w = new long [ n ]; MinDegA = n; MinDegB = n; MinDegC = n; this->E = new IntArrayList * [ n ]; this->L = new IntArrayList * [ n ]; this->A = mtx->ColumnsIndexes; this->I = new IntArrayList * [ n ]; // in the begining all DOFs are variables for ( long k = 0; k < n; k++ ) { I [ k ] = new IntArrayList(4); I [ k ]->Add(k); E [ k ] = new IntArrayList(4); //A[k] = mtx->ColumnsIndexes[k]; L [ k ] = NULL; vlasts [ k ] = k - 1; vnexts [ k ] = k + 1; degrees [ k ] = A [ k ]->Count; if ( degrees [ k ] > n ) { mtx->Writeln("Connectivity matrix is corrupt !"); return NULL; } if ( degrees [ k ] < MinDegA && IsFree(k) ) { MinDegA = degrees [ k ]; } permutation [ k ] = 0; amd_w [ k ] = -1; } vnexts [ n - 1 ] = -1; // Draw the quotient graph //mtx.MT.DrawGraph(this); //long noDots = 0; //long denDots = n / 24; if (denDots==0) denDots = 1; long *pLIdx = permutation, *pPIdx = pivot_pattern, *vl = vlasts, *vn = vnexts; { this->pLIdx = pLIdx; this->pPIdx = pPIdx; variables.Init(vl, vn, n); if ( keep_sorted_order ) { for ( long i = 0; i < n; i++ ) { Eliminate(fixed->Items [ i ]); } } else { while ( no_elements < n ) { long MinimDeg = std::min(MinDegB, MinDegA); MinDegB = n; MinDegC = n; // find minimum degree for ( long vi = variables.first; vi >= 0; ) { //long deg_vi = p_degrees[vi]; if ( IsFree(vi) && ( MinimDeg >= degrees [ vi ] ) ) { // do elimination Eliminate(vi); if ( MinDegB < MinimDeg ) { MinimDeg = MinDegB; vi = vi_Min; continue; } } else { if ( IsFree(vi) && ( degrees [ vi ] < MinDegC ) ) { MinDegC = degrees [ vi ]; } } vi = variables.next [ vi ]; } MinDegA = MinDegC; if ( no_fixed && ( no_elements == n - no_fixed ) ) { // we can now unblock the fixed nodes delete [] pfixed; pfixed = NULL; no_fixed = 0; } //for (long i=no_elements/denDots; i>noDots; noDots++) //{ // mtx->Write("."); //mtx.MT.NextStep(); //} } } } // Permutation = order^-1 delete [] pfixed; pfixed = NULL; delete [] permutation; delete [] vlasts; delete [] vnexts; delete [] pivot_pattern; IntArrayList *order = elements; elements = NULL; // return the order return order; }
void MD_Qqraph :: SupervariablesDetection(IntArrayList &Lp) { if ( keep_sorted_order ) { return; } long idx, ix; //supervariable detection, pairs found via hash function //foreach(long i in Lp) for ( idx = 0; idx < Lp.Count; idx++ ) { long i = Lp [ idx ]; if ( I [ i ] == NULL || !IsFree(i) ) { continue; } long key = Hash(i); ht.AddValue(key, i); } for ( idx = ht.occupied_buckets.Count - 1; idx >= 0; idx-- ) { IntArrayList &al = * ht.buckets [ ht.occupied_buckets.Items [ idx ] ]; if ( al.Count >= 2 ) { hash_parents.Alloc(al.Count); for ( ix = 0; ix < al.Count; ix++ ) { long i = al [ ix ]; if ( hash_parents [ ix ] < 0 ) { continue; } for ( long jx = ix + 1; jx < al.Count; jx++ ) { if ( hash_parents [ jx ] < 0 ) { continue; } long j = al [ jx ]; if ( IsIndistinguishable(i, j) ) { hash_parents [ jx ] = ~i; } } } for ( ix = 0; ix < al.Count; ix++ ) { if ( hash_parents [ ix ] < 0 ) { long i = ~hash_parents [ ix ]; long j = al [ ix ]; //remove supervariable j IntArrayList &Ij = * I [ j ]; for ( long ij = Ij.Count - 1; ij >= 0; ij-- ) { I [ i ]->SortInsert(Ij.Items [ ij ]); } degrees [ i ] -= I [ j ]->Count; if ( MinDegB > degrees [ i ] ) { MinDegB = degrees [ i ]; vi_Min = i; } variables.Remove(j); if ( I [ j ] ) { delete I [ j ]; I [ j ] = NULL; } //if (A[j]) {delete A[j];A[j] = NULL;} //A[j] = NULL; if ( E [ j ] ) { delete E [ j ]; E [ j ] = NULL; } } } } } ht.Clear(); }
int CFieldHandler::CanPlace(int index, CStoneHandler::CStone *pStone) { /*int x = index%FIELD_WIDTH; int y = (index-x)/FIELD_WIDTH; int temp = 0; int points = 0; if(!IsFree(index)) return 0; //field not empty int dirx = 0; int diry = 0; if(x > 0) { if(!IsFree(index-1)) dirx = -1; } if(x < FIELD_WIDTH-1) { if(!IsFree(index+1)) { if(dirx != 0) //dont allow chaining return 0; dirx = 1; } } if(y > 0) { if(!IsFree(index-FIELD_WIDTH)) diry = -FIELD_WIDTH; } if(y < FIELD_HEIGHT-1) { if(!IsFree(index+FIELD_WIDTH)) { if(diry != 0) //dont allow chaining return 0; diry = FIELD_WIDTH; } } for(int i = index; i < (y+1)*FIELD_WIDTH; i += dirx) { }*/ if(!IsFree(index)) return 0; //field not empty if(CheckRestrictions(index) == false) return 0; int x = index%FIELD_WIDTH; int y = (index-x)/FIELD_WIDTH; int temp = 0; int points = 0; for(int i = x-1; i >= 0; --i) { if(IsFree(i+y*FIELD_WIDTH)) { temp = i+1; break; } } unsigned short flags = 0; int num_colors = 0; int num_shapes = 0; int num = 0; bool gotNeighbours = false; for(int i = temp; i < FIELD_WIDTH; ++i) { if(num >= 6) //bereits 6 steine gelegt return 0; if(i == x) continue; // if(i-temp >= 5) // return 0; if(IsFree(i+y*FIELD_WIDTH)) break; ++num; if(!(m_aField[i+y*FIELD_WIDTH].m_Flags & FIELD_COUNTED_X)) points++; if(CStoneHandler::CheckShape(&m_aField[i+y*FIELD_WIDTH], pStone)) ++num_shapes; if(CStoneHandler::CheckColor(&m_aField[i+y*FIELD_WIDTH], pStone)) ++num_colors; if(num_shapes == 0 && (flags & (1<<m_aField[i+y*FIELD_WIDTH].m_pStone->m_Shape))) { return 0; } else flags |= (1<<m_aField[i+y*FIELD_WIDTH].m_pStone->m_Shape); if(num_colors == 0 && (flags & (64<<m_aField[i+y*FIELD_WIDTH].m_pStone->m_Color))) { return 0; } else flags |= (64<<m_aField[i+y*FIELD_WIDTH].m_pStone->m_Color); } if(num > 0) { if(!((num_shapes == 0 && num_colors == num) || (num_shapes == num && num_colors == 0))) return 0; gotNeighbours = true; points += 1; if(num == 5) points += 6; } temp = 0; flags = 0; for(int i = y-1; i >= 0; --i) { if(IsFree(x+i*FIELD_WIDTH)) { temp = i+1; break; } } num_colors = 0; num_shapes = 0; num = 0; for(int i = temp; i < FIELD_HEIGHT; ++i) { if(num >= 6) //bereits 6 steine gelegt return 0; if(i == y) continue; // if(i-temp >= 5) //bereits 6 steine gelegt // return 0; if(IsFree(x+i*FIELD_WIDTH)) break; ++num; if(!(m_aField[x+i*FIELD_WIDTH].m_Flags & FIELD_COUNTED_Y)) points++; if(CStoneHandler::CheckShape(&m_aField[x+i*FIELD_WIDTH], pStone)) ++num_shapes; if(CStoneHandler::CheckColor(&m_aField[x+i*FIELD_WIDTH], pStone)) ++num_colors; if(num_shapes == 0 && (flags & (1<<m_aField[x+i*FIELD_WIDTH].m_pStone->m_Shape))) { return 0; } else flags |= (1<<m_aField[x+i*FIELD_WIDTH].m_pStone->m_Shape); if(num_colors == 0 && (flags & (64<<m_aField[x+i*FIELD_WIDTH].m_pStone->m_Color))) { return 0; } else flags |= (64<<m_aField[x+i*FIELD_WIDTH].m_pStone->m_Color); } if(num > 0) { if(!((num_shapes == 0 && num_colors == num) || (num_shapes == num && num_colors == 0))) return 0; gotNeighbours = true; points ++; if(num == 5) points += 6; } if(!m_IsFirstMove && gotNeighbours) return points; else if(m_IsFirstMove) // we can lay wherever we want return points; else return 0; }
int CFieldHandler::PlaceStone(int index, CStoneHandler::CStone *pStone, bool update) { if(pStone == 0) { printf("NULL-POINTER FH-STONE"); return 0; } m_aField[index].m_pStone = pStone; if(m_Moves < 2) { m_aRestrictions[m_Moves] = index; } ++m_Moves; int x = index%FIELD_WIDTH; int y = (index-x)/FIELD_WIDTH; int temp = 0; for(int i = x-1; i>=0; i--) { if(IsFree(i+y*FIELD_WIDTH)) { temp = i +1; if(update) UpdatePossibleMoves(i+y*FIELD_WIDTH); break; } } int num = 0; for(int i = temp; i < FIELD_WIDTH; i++) { if(!IsFree(i+y*FIELD_WIDTH)) { if(i != x) { m_aField[i+y*FIELD_WIDTH].m_Flags |= FIELD_COUNTED_X; num++; } } else { if(update) UpdatePossibleMoves(i+y*FIELD_WIDTH); break; } } if(num > 0) m_aField[index].m_Flags |= FIELD_COUNTED_X; temp = 0; num = 0; for(int i = y-1; i>=0; i--) { if(IsFree(x+i*FIELD_WIDTH)) { temp = i +1; if(update) UpdatePossibleMoves(x+i*FIELD_WIDTH); break; } } for(int i = temp; i < FIELD_HEIGHT; i++) { if(!IsFree(x+i*FIELD_WIDTH)) { if(i != y) { m_aField[x+i*FIELD_WIDTH].m_Flags |= FIELD_COUNTED_Y; num++; } } else { if(update) UpdatePossibleMoves(x+i*FIELD_WIDTH); break; } } if(num > 0) m_aField[index].m_Flags |= FIELD_COUNTED_Y; if(update) UpdatePossibleMoves(); }
int CFieldHandler::GetPoints(int index, CStoneHandler::CStone *pStone) { int points = 0; int blocks = 0; int x = index%FIELD_WIDTH; int y = index/FIELD_WIDTH; for(int i = x-1; i>=0; i--) { if(!IsFree(i+y*FIELD_WIDTH)) { points++; blocks++; } else { break; } } for(int i = x+1; i<FIELD_WIDTH; i++) { if(!IsFree(i+y*FIELD_WIDTH)) { points++; blocks++; } else { break; } } if(blocks > 0) { points ++; //für den eigenen Stein if(blocks = 5) //Sixpack { points +=6; } } blocks = 0; for(int i = y-1; i>=0; i--) { if(!IsFree(i*FIELD_WIDTH+x)) { points++; blocks++; } else { break; } } for(int i = y+1; i<FIELD_HEIGHT; i++) { if(!IsFree(i*FIELD_WIDTH+x)) { points++; blocks++; } else { break; } } if(blocks > 0) { points ++; //für den eigenen Stein if(blocks = 5) //Sixpack { points +=6; } } return points; }