bool PlayerCanCapture(Board board, cellState player) { bool captureavailable = false; for(int y=0; y<BOARD_HEIGHT; y++) { for(int x=0; x<BOARD_WIDTH; x++) { //If the current cell is one of the player's men or kings and it can capture, return true. if((board.cells[y][x] == player)||(board.cells[y][x] == player+1)) { if(CanCapture(board,x,y)) { captureavailable = true; } } } } return captureavailable; }
bool HasWon(cellState player, Board board) { //Get the opponent's colour cellState opponent = otherplayer(player); bool won = true; //Get the direction the opponent can move in int direction; if(opponent == M_BLACK) { direction = -1; } else { direction = 1; } /* In draughts, a player wins if their opponent cannot move. This code therefore checks to see if there are any possible moves for the player's opponent. */ for(int y=0; y<BOARD_HEIGHT; y++) { for(int x=0; x<BOARD_WIDTH; x++) { //If the current space is the opponent's man or king if(board.cells[y][x] == opponent || board.cells[y][x] == opponent + 1) { //Can it move normally? if(board.cells[y+direction][x+1] == EMPTY || board.cells[y+direction][x-1] == EMPTY) { won = false; } //If it is a king, can it move backwards? if(board.cells[y][x] == opponent + 1 && (board.cells[y-direction][x+1] == EMPTY || board.cells[y-direction][x-1] == EMPTY)) { won = false; } //Can it capture? if(CanCapture(board,x,y)) { won = false; } } } } return won; }
//////////////////////////////////////////////////////////// /// Start the capture. /// Warning : only one capture can happen at the same time //////////////////////////////////////////////////////////// void SoundRecorder::Start(unsigned int SampleRate) { // Check if the device can do audio capture if (!CanCapture()) { std::cerr << "Failed to start capture : your system cannot capture audio data (call sfSoundRecorder::CanCapture to check it)" << std::endl; return; } // Check that another capture is not already running if (CaptureDevice) { std::cerr << "Trying to start audio capture, but another capture is already running" << std::endl; return; } // Open the capture device for capturing 16 bits mono samples CaptureDevice = alcCaptureOpenDevice(NULL, SampleRate, AL_FORMAT_MONO16, SampleRate); if (!CaptureDevice) { std::cerr << "Failed to open the audio capture device" << std::endl; return; } // Clear the sample array mySamples.clear(); // Store the sample rate mySampleRate = SampleRate; // Start the capture alcCaptureStart(CaptureDevice); // Start the capture in a new thread, to avoid blocking the main thread myIsCapturing = true; Launch(); }