/** * Moves a board in all the possible directions and adds the new states to the queue. * @param board The board to be moved. * @param queue The priority queue holding all board states. */ std::pair<bool, Board*> MoveAllDirectionsAndAddToQueue(Board* &board, std::priority_queue<Board*, std::vector<Board*>, QueueCompareClass> &queue) { // For all 4 directions, try to move in that direction. for (unsigned int i = 0; i < 4; ++i) { int direction = DIRECTIONS[i]; // If the board can move in that direction, then move it. // If it can't, then do nothing. if (CanMoveInDirection(direction, board)) { // Create a copy of the current board, and move the copy. Board* new_board = new Board(*board); // Actually move the board. MoveInDirection(direction, new_board); // Set the previous board state. new_board->SetPreviousState(board); // Check if the board is at the goal state, if so then stop. if (new_board->IsAtGoalState()) { return std::make_pair(true, new_board); } // Do not add the new state to the queue if the new board is the // same as the previous state. if (board->GetPreviousState() && *(board->GetPreviousState()) == *new_board) { delete new_board; new_board = NULL; } else { queue.push(new_board); } } } return std::make_pair(false, reinterpret_cast<Board*>(NULL)); }
void PacmanObject::MoveInDirection(int iDir, int iCurrentTime) { if (CanMoveInDirection(iDir)) { m_iMapX += GetXDiffForDirection(m_iDir); m_iMapY += GetYDiffForDirection(m_iDir); m_oMover.Setup( m_iCurrentScreenX, m_iCurrentScreenY, GetScreenPosForMapX(m_iMapX), GetScreenPosForMapY(m_iMapY), iCurrentTime, iCurrentTime+400); } }
void PacmanEnemy::HandleMovementFinished(int iCurrentTime) { int iAIDir = m_pAI->GetMove(this, m_iMapX, m_iMapY); if (iAIDir != -1) { if (rand()%3 == 0 && CanMoveInDirection(iAIDir)) m_iDir = iAIDir; MoveInDirection(m_iDir, iCurrentTime); } else { // Don't move! return; } }