// should be easy... bool StrategyLargeAttackCL::leaveSupport(Point supportCenter, Point target) { LOG_FUNCTION(); const Radian THETA_DELTA = M_PI_4/3; MvtMgr->setRobotDirection(MOVE_DIRECTION_FORWARD); Move->go2Target(target); Events->wait(evtEndMove); if (Events->isInWaitResult(EVENTS_MOVE_END)) { return true; } else { if (checkEndEvents()) return false; // end of match CollisionEnum collision = checkCollisionEvents(); if (collision == COLLISION_LEFT || collision == COLLISION_RIGHT) { // turn on wheel bool collisionLeft = (collision == COLLISION_LEFT); LOG_INFO("Collision (%s) in leaveSupport\n", collisionLeft?"left":"right"); bool stopLeft = collisionLeft; Radian deltaTheta = THETA_DELTA* (collisionLeft? 1: -1); Move->rotateOnWheel(RobotPos->thetaAbsolute() + deltaTheta, stopLeft); Events->wait(evtEndMove); } // try again Move->go2Target(target); Events->wait(evtEndMove); return (Events->isInWaitResult(EVENTS_MOVE_END)); } }
void GameController::doScoring () { LOG_FUNCTION(cout, "GameController::doScoring"); // Calculate scores // size_t playerOneScore = m_playerOne.calculateScore(); size_t playerTwoScore = m_playerTwo.calculateScore(); // Determine winner and notify players // if (playerOneScore == playerTwoScore) { m_playerOne.notifyTied(); m_playerTwo.notifyTied(); } else if (playerOneScore > playerTwoScore) { m_playerOne.notifyWon(); m_playerTwo.notifyLost(); } else // (playerTwoScore > playerOneScore) { m_playerTwo.notifyWon(); m_playerOne.notifyLost(); } }
// -------------------------------------------------------------------------- // met a jour la position du pont en fonction des sharps quand on est en face du // pont BRIDGE_POS_MIDDLE_BORDURE ou qu'on est aligne pour traverser sur le // pont du milieu // -------------------------------------------------------------------------- bool StrategyAttackCL::getBridgePosBySharp() { LOG_FUNCTION(); // on reccupere la valeur des capteurs 2 fois pour voir si on n'a // pas un soucis de bruit bridgeBySharps_ =BRIDGE_POS_UNKNOWN; BridgeCaptorStatus captors[BRIDGE_CAPTORS_NBR]; if (!getBridgeCaptors(captors, true)) goto endGetBridgePosBySharp; if (bridgeDetectionByCenter_) { if (!getBridgePosBySharpFromCenter(captors)) goto endGetBridgePosBySharp; } else { if (!getBridgePosBySharpFromLeft(captors)) goto endGetBridgePosBySharp; } LOG_INFO("Bridge by Sharp=%s\n", BridgePosTxt(bridge_)); Log->bridge(bridge_); bridgeBySharps_ = bridge_; #ifdef USE_SHARPS_FIRST return true; #endif endGetBridgePosBySharp: #ifdef USE_SHARPS_FIRST return false; #else LOG_INFO("Do not use sharps!\n"); // pour aller tout droit!, on update bridge_ getNearestBridgeEntry(); return true; #endif }
/** Reset les hctl (gauche et droite) */ bool MotorSimu::reset() { LOG_FUNCTION(); MotorCL::reset(); return true; }
size_t Board::removeCapturedStones (StoneColor colorToCapture) { LOG_FUNCTION(cout, "Board::removeCapturedStones"); size_t captureCount = 0; // A set of points that we've already examined. This helps prevents some // bad recursion and keeps a chain from being "found" once for each stone // in the chain. // ConstPointSet alreadyVisited; for (size_t row = 0; row < m_points.size(); ++row) { for (size_t column = 0; column < m_points[row].size(); ++column) { const Point & thePoint = m_points.at(row).at(column); // If the point we are considering has already been visited, // then Chain's ctor will throw a PointVisitedAlreadyException // object. We can safely swallow that exception and move on // to the next point. // try { Chain currentChain {thePoint, *this, &alreadyVisited}; gLogger.log(LogLevel::kMedium, cout, "Discovered chain"); // " : ", chain); // If the chain we are looking at is the color we should consider capturing and // the chain has no liberties, then capture it // if (currentChain.color() == colorToCapture && currentChain.libertyCount() == 0) { captureCount += currentChain.size(); // For each point in the chain, remove the stone from the board // at those coordniates // currentChain.forEachPoint([this](const Point & point) { LOG_BUSY_FUNCTION(cout, "Chain::removeCapturedStones::lambda_doStoneRemoval"); m_points[point.coordinates.row][point.coordinates.column].removeStone(); }); } } catch (const Chain::PointVisitedAlreadyException & ex) { gLogger.log(LogLevel::kFirehose, cout, "Skipping ", thePoint); } } } // If we ended up only capturing one stone, the 'Ko' rule might affect // the next move, so remember that fact! // m_koState.first = (captureCount == 1); return captureCount; }
HRESULT DD_API MyDirectDrawSurfaceSw::GetDDInterface(LPVOID * lplpDD) { LOG_FUNCTION(); CHECK_PARAM(nullptr != lplpDD); *lplpDD = static_cast<LPDIRECTDRAW>(mParent); return S_OK; }
MyDirectDrawClipperProxy::MyDirectDrawClipperProxy(logger *log, LPDIRECTDRAWCLIPPER c): mRefCount(1), mLog(log), mClipper(c) { LOG_FUNCTION(); }
// _______________________________________________________________________________________ // void CAAudioFile::UpdateClientMaxPacketSize() { LOG_FUNCTION("CAAudioFile::UpdateClientMaxPacketSize", "%p", this); mFrame0Offset = 0; if (mConverter != NULL) { AudioConverterPropertyID property = (mMode == kReading) ? kAudioConverterPropertyMaximumOutputPacketSize : kAudioConverterPropertyMaximumInputPacketSize; UInt32 propertySize = sizeof(UInt32); XThrowIfError(AudioConverterGetProperty(mConverter, property, &propertySize, &mClientMaxPacketSize), "get audio converter's maximum packet size"); if (mFileDataFormat.mBitsPerChannel == 0) { AudioConverterPrimeInfo primeInfo; propertySize = sizeof(primeInfo); OSStatus err = AudioConverterGetProperty(mConverter, kAudioConverterPrimeInfo, &propertySize, &primeInfo); if (err == noErr) mFrame0Offset = primeInfo.leadingFrames; #if VERBOSE_CONVERTER printf("kAudioConverterPrimeInfo: err = %ld, leadingFrames = %ld\n", err, mFrame0Offset); #endif } } else { mClientMaxPacketSize = mFileMaxPacketSize; } }
// ------------------------------------------------------------------------- // UartManagerCL::isOpened // ------------------------------------------------------------------------- bool UartManagerCL::reset() { LOG_FUNCTION(); init_ = true; if (lcd_) { init_ &= lcd_->reset(); } if (odometer_) { init_ &= odometer_->reset(); } return init_;; }
MyDirectDrawSw::~MyDirectDrawSw() { LOG_FUNCTION(); if(mHDC) { ReleaseDC(mHWnd, mHDC); } }
MotorSimu::MotorSimu(bool automaticReset, MotorAlertFunction fn) : MotorCL(automaticReset, fn) { LOG_FUNCTION(); reset(); LOG_OK("Initialisation terminée\n"); }
// ------------------------------------------------------------------------- // UartManagerCL::allocDevices // ------------------------------------------------------------------------- // Alloue l'instance du controleur de carte des cartes qui ont ete trouvees // ------------------------------------------------------------------------- void UartManagerCL::allocDevices() { if (RobotConfig->ioManagerAlloc) { LOG_FUNCTION(); allocLcd(); allocOdometer(); } }
// -------------------------------------------------------------------------- // verifie si les roues avant du robot ne sont pas dans le vide // renvoie false si la carte bumper ne repond pas ou si l'info des bumpers // n'est pas consistante // -------------------------------------------------------------------------- bool StrategyAttackCL::getBridgePosByBumper(bool& bridgeInFront) { LOG_FUNCTION(); BridgeCaptorStatus captors[BRIDGE_CAPTORS_NBR]; if (!getBridgeCaptors(captors, false)) return false; // on n'est pas dans la merde les bumpers ne marchent pas bridgeInFront = ((captors[BRIDGE_BUMPER_LEFT]==BRIDGE_DETECTED) && (captors[BRIDGE_BUMPER_RIGHT]==BRIDGE_DETECTED)); return true; }
GameController::GameController (IPlayer & one, IPlayer & two) : m_playerOne(one) , m_playerTwo(two) { LOG_FUNCTION(cout, "GameController::GameController"); m_playerOne.setGameBoard(m_board); m_playerTwo.setGameBoard(m_board); }
static NTSTATUS EVhdDriverLoad(ULONG32 *pResult) { UNICODE_STRING szShimName = { 0 }, szRootPath = { 0 }; NTSTATUS status = STATUS_SUCCESS; OBJECT_ATTRIBUTES ObjectAttributes = { 0 }; IO_STATUS_BLOCK StatusBlock = { 0 }; PFILE_OBJECT pFileObject = NULL; ULONG32 dwRequest = 0xC0; RtlInitUnicodeString(&szRootPath, L""); status = FindShimDevice(&szShimName, &szRootPath); if (!NT_SUCCESS(status)) { LOG_FUNCTION(LL_FATAL, LOG_CTG_GENERAL, "FindShimDevice failed with error 0x%08X", status); goto cleanup_failure; } ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES); ObjectAttributes.ObjectName = &szShimName; ObjectAttributes.Attributes = OBJ_KERNEL_HANDLE | OBJ_CASE_INSENSITIVE; status = ZwCreateFile(&g_shimFileHandle, GENERIC_READ | SYNCHRONIZE, &ObjectAttributes, &StatusBlock, 0, FILE_READ_ATTRIBUTES, FILE_SHARE_READ | FILE_SHARE_WRITE, FILE_OPEN, FILE_NON_DIRECTORY_FILE, NULL, 0); if (!NT_SUCCESS(status)) { LOG_FUNCTION(LL_FATAL, LOG_CTG_GENERAL, "ZwCreateFile %S failed with error 0x%08x\n", szShimName.Buffer, status); goto cleanup_failure; } status = ObReferenceObjectByHandle(g_shimFileHandle, 0, *IoFileObjectType, KernelMode, (PVOID*)&pFileObject, NULL); if (!NT_SUCCESS(status)) { LOG_FUNCTION(LL_FATAL, LOG_CTG_GENERAL, "ObReferenceObjectByHandle failed with error 0x%08X\n", status); goto cleanup_failure; } status = SynchronouseCall(pFileObject, IOCTL_STORAGE_REGISTER_BALANCER, &dwRequest, sizeof(ULONG32), pResult, sizeof(ULONG32)); cleanup_failure: if (pFileObject) ObDereferenceObject(pFileObject); if (szShimName.Buffer) ExFreePool(szShimName.Buffer); return status; }
// _______________________________________________________________________________________ // void CAAudioFile::Open(const FSRef &fsref) { LOG_FUNCTION("CAAudioFile::Open", "%p", this); XThrowIf(mMode != kClosed, kExtAudioFileError_InvalidOperationOrder, "file already open"); mFSRef = fsref; XThrowIfError(AudioFileOpen(&mFSRef, fsRdPerm, 0, &mAudioFile), "open audio file"); mOwnOpenFile = true; mMode = kReading; GetExistingFileInfo(); }
HRESULT DD_API MyDirectDrawSurfaceSw::PageLock(DWORD dwFlags) { LOG_FUNCTION(); CHECK_PARAM(0 == dwFlags); if(0 == mPageLockCount++) { ::VirtualLock(GetBufferPtr(), bufferSize()); } return S_OK; }
// _______________________________________________________________________________________ // void CAAudioFile::SetFileChannelLayout(const CAAudioChannelLayout &layout) { LOG_FUNCTION("CAAudioFile::SetFileChannelLayout", "%p", this); mFileChannelLayout = layout; #if VERBOSE_CHANNELMAP printf("file channel layout set explicitly (%s): %s\n", mMode == kReading ? "read" : "write", CAChannelLayouts::ConstantToString(mFileChannelLayout.Tag())); #endif if (mMode != kReading) FileFormatChanged(); }
void GameController::doGameLoop (PlayerPair & playerPair) { LOG_FUNCTION(cout, "GameController::doGameLoop"); // Counter used to determine the number of consecutive "pass" moves // unsigned short passCount = 0; // While there haven't been two consecutive passes, continue prompting // players for moves, execute the moves, and alternate players // while (passCount < 2) { IPlayer & currentPlayer = playerPair.first; IPlayer & waitingPlayer = playerPair.second; // Notify the current player that it is their turn // currentPlayer.notifyTurn(); // If the player has stones left, have the current player make // a move; otherwise count as a pass // if (currentPlayer.hasStones()) { // Make move // auto theMove = currentPlayer.playStone(); // Remove captured stones and count them // size_t captureCount = m_board.removeCapturedStones(waitingPlayer.getStoneColor()); // Add captured stones to current player's total (for scoring purposes) // currentPlayer.addToCaptured(captureCount); gLogger.log(LogLevel::kNone, cout, "Player ", currentPlayer.getName(), " captured ", captureCount, " stones"); passCount = (didPlayerPass(theMove)) ? passCount + 1 : 0; } else { ++passCount; } // Swap the players so that on the next iteration, the current // player alternates // swap(playerPair.first, playerPair.second); } }
HRESULT DD_API MyDirectDrawSurfaceSw::PageUnlock(DWORD dwFlags) { LOG_FUNCTION(); CHECK_PARAM(isPageLocked()); CHECK_PARAM(0 == dwFlags); if(0 == --mPageLockCount) { ::VirtualUnlock(GetBufferPtr(), bufferSize()); OnChangedInternal(); } return S_OK; }
// _______________________________________________________________________________________ // void CAAudioFile::Wrap(AudioFileID fileID, bool forWriting) { LOG_FUNCTION("CAAudioFile::Wrap", "%p", this); XThrowIf(mMode != kClosed, kExtAudioFileError_InvalidOperationOrder, "file already open"); mAudioFile = fileID; mOwnOpenFile = false; mMode = forWriting ? kPreparingToWrite : kReading; GetExistingFileInfo(); if (forWriting) FileFormatChanged(); }
HRESULT DD_API MyDirectDrawSurfaceSw::GetAttachedSurface(LPDDSCAPS lpDDSCaps, LPDIRECTDRAWSURFACE2 *lplpDDAttachedSurface) { LOG_FUNCTION(); CHECK_PARAM(nullptr != lpDDSCaps); CHECK_PARAM(nullptr != lplpDDAttachedSurface); MyDirectDrawSurfaceSw* ret = GetAttachedSurfaceInternal(lpDDSCaps); if(nullptr != ret) { *lplpDDAttachedSurface = ret; return S_OK; } return DDERR_NOTFOUND; }
MyDirectDrawSw::MyDirectDrawSw(logger *log, const Settings *settings): mRefCount(1), mLog(log), mSettings(settings), mHook(log, std::bind(&MyDirectDrawSw::myWndProcInternal, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5)) { LOG_FUNCTION(); mPrevFrameTime = clock::now(); }
// _______________________________________________________________________________________ // void CAAudioFile::InitFileMaxPacketSize() { LOG_FUNCTION("CAAudioFile::InitFileMaxPacketSize", "%p", this); UInt32 propertySize = sizeof(UInt32); OSStatus err = AudioFileGetProperty(mAudioFile, kAudioFilePropertyMaximumPacketSize, &propertySize, &mFileMaxPacketSize); if (err) { // workaround for 3361377: not all file formats' maximum packet sizes are supported if (!mFileDataFormat.IsPCM()) XThrowIfError(err, "get audio file's maximum packet size"); mFileMaxPacketSize = mFileDataFormat.mBytesPerFrame; } AllocateBuffers(true /* okToFail */); }
// _______________________________________________________________________________________ // // call for existing file, NOT new one - from Open() or Wrap() void CAAudioFile::GetExistingFileInfo() { LOG_FUNCTION("CAAudioFile::GetExistingFileInfo", "%p", this); UInt32 propertySize; OSStatus err; // get mFileDataFormat propertySize = sizeof(AudioStreamBasicDescription); XThrowIfError(AudioFileGetProperty(mAudioFile, kAudioFilePropertyDataFormat, &propertySize, &mFileDataFormat), "get audio file's data format"); // get mFileChannelLayout err = AudioFileGetPropertyInfo(mAudioFile, kAudioFilePropertyChannelLayout, &propertySize, NULL); if (err == noErr && propertySize > 0) { AudioChannelLayout *layout = static_cast<AudioChannelLayout *>(malloc(propertySize)); err = AudioFileGetProperty(mAudioFile, kAudioFilePropertyChannelLayout, &propertySize, layout); if (err == noErr) { mFileChannelLayout = layout; #if VERBOSE_CHANNELMAP printf("existing file's channel layout: %s\n", CAChannelLayouts::ConstantToString(mFileChannelLayout.Tag())); #endif } free(layout); XThrowIfError(err, "get audio file's channel layout"); } if (mMode != kReading) return; #if 0 // get mNumberPackets propertySize = sizeof(mNumberPackets); XThrowIfError(AudioFileGetProperty(mAudioFile, kAudioFilePropertyAudioDataPacketCount, &propertySize, &mNumberPackets), "get audio file's packet count"); #if VERBOSE_IO printf("CAAudioFile::GetExistingFileInfo: %qd packets\n", mNumberPackets); #endif #endif // get mMagicCookie err = AudioFileGetPropertyInfo(mAudioFile, kAudioFilePropertyMagicCookieData, &propertySize, NULL); if (err == noErr && propertySize > 0) { mMagicCookie = new Byte[propertySize]; mMagicCookieSize = propertySize; XThrowIfError(AudioFileGetProperty(mAudioFile, kAudioFilePropertyMagicCookieData, &propertySize, mMagicCookie), "get audio file's magic cookie"); } InitFileMaxPacketSize(); mPacketMark = 0; mFrameMark = 0; UpdateClientMaxPacketSize(); }
HRESULT DD_API MyDirectDrawSw::QueryInterface(const IID &riid, LPVOID *ppvObj) { LOG_FUNCTION(); const std::pair<int,IID> versions[] = {{1,IID_IDirectDraw}, {2,IID_IDirectDraw2}, {4,IID_IDirectDraw4}, {7,IID_IDirectDraw7}, {7,IID_IDirect3D7}}; const auto ver = std::find_if(std::begin(versions), std::end(versions), [&](const std::pair<int,GUID>& val) { return riid == val.second; }); if(std::end(versions) == ver) { mVersion = 1; LOG_INFO() << "Unknown DD version. IID: " << riid; *ppvObj = nullptr; return E_NOINTERFACE; } else { mVersion = (*ver).first; LOG_INFO() << "DD version: " << mVersion; } AddRef(); if(mVersion >= 1) { *ppvObj = static_cast<LPDIRECTDRAW>(this); } if(mVersion >= 2) { *ppvObj = static_cast<LPDIRECTDRAW2>(this); } if(mVersion >= 4) { *ppvObj = static_cast<LPDIRECTDRAW4>(this); } if(mVersion >= 7) { *ppvObj = static_cast<LPDIRECTDRAW7>(this); } return S_OK; }
// _______________________________________________________________________________________ // void CAAudioFile::CreateNew(const FSRef &parentDir, CFStringRef filename, AudioFileTypeID filetype, const AudioStreamBasicDescription &dataFormat, const AudioChannelLayout *layout) { LOG_FUNCTION("CAAudioFile::CreateNew", "%p", this); XThrowIf(mMode != kClosed, kExtAudioFileError_InvalidOperationOrder, "file already open"); mFileDataFormat = dataFormat; if (layout) { mFileChannelLayout = layout; #if VERBOSE_CHANNELMAP printf("PrepareNew passed channel layout: %s\n", CAChannelLayouts::ConstantToString(mFileChannelLayout.Tag())); #endif } mMode = kPreparingToCreate; FileFormatChanged(&parentDir, filename, filetype); }
void Board::placeStoneAt (const PointCoords & coords, std::unique_ptr<Stone> stone) { LOG_FUNCTION(cout, "Board::placeStoneAt"); assert(stone.get() != nullptr); Point & thePoint = m_points.at(coords.row).at(coords.column); // Remember this point for implementing the 'Ko' rule // m_koState.second = thePoint; // Actually play the stone // thePoint.playStone(std::move(stone)); }
Board::Board () : m_koState( { false, m_points[0][0] }) { LOG_FUNCTION(cout, "Board::Board"); for (size_t row = 0; row < BOARD_SIZE; ++row) { for (size_t column =0; column < BOARD_SIZE; ++column) { m_points[row][column].coordinates.row = row; m_points[row][column].coordinates.column = column; } } }
void GameController::start () { LOG_FUNCTION(cout, "GameController::start"); // Place the players into a 'flippable' container // PlayerPair playerPair = make_pair(ref(m_playerOne), ref(m_playerTwo)); // Let the players enter their own names // gLogger.log(LogLevel::kMedium, cout, "Players choosing names"); m_playerOne.chooseName(); m_playerTwo.chooseName(); // Assign stones, Player 1 gets to choose, Player 2 gets the remainder // gLogger.log(LogLevel::kMedium, cout, "Player 1 picking color"); StoneColor colorOne = m_playerOne.chooseStoneColor(); m_playerTwo.setStoneColor(getOpposingColor(colorOne)); // Reorder the players according to the stone choices // if (StoneColor::WHITE == colorOne) swap(playerPair.first, playerPair.second); // Signal to the players that the game is ready // playerPair.first.get().notifyGameReady(); playerPair.second.get().notifyGameReady(); // Start the move selection loop // doGameLoop(playerPair); // Game is over! Time to score // doScoring(); }