void Board::tilt_array(BoardPosition** pos_array, int size, bool& state_changed) { // set all positions to not merged status for (int i = 0; i < size; ++i) { pos_array[i]->set_was_merged(false); } int j = 0; for (int i = size - 2; i >= 0; --i) { if (pos_array[i]->get_value() != 0) { // move tile until first occupied position is found j = i; while ((j < size - 1) && (pos_array[j + 1]->get_value() == 0)) { swap_positions(pos_array[j], pos_array[j + 1]); state_changed = true; ++j; } // determine if the next position has same value and if so, merge tiles if ((j < size - 1) && (pos_array[j]->get_value() == pos_array[j + 1]->get_value()) && (!pos_array[j]->was_merged())) { merge_positions(pos_array[j], pos_array[j + 1]); m_score = m_score + pos_array[j + 1]->get_value(); state_changed = true; } } // else do nothing with the current position } }
void SwappedSystem::reinitialize_phibetas (const Wavefunction<amplitude_t>::Amplitude &phialpha1, const Wavefunction<amplitude_t>::Amplitude &phialpha2) { assert(subsystem_particle_counts_match()); #if defined(DEBUG_VMC_SWAPPED_SYSTEM) || defined(DEBUG_VMC_ALL) for (unsigned int species = 0; species < copy1_subsystem_indices.size(); ++species) std::cerr << "swapping " << copy1_subsystem_indices[species].size() << " particles of species " << species << std::endl; std::cerr << std::endl; #endif PositionArguments swapped_r1(phialpha1.get_positions()), swapped_r2(phialpha2.get_positions()); swap_positions(swapped_r1, swapped_r2); phibeta1 = phialpha1.clone(); phibeta1->reset(swapped_r1); phibeta1_dirty = false; phibeta2 = phialpha2.clone(); phibeta2->reset(swapped_r2); phibeta2_dirty = false; #ifdef VMC_CAREFUL verify_phibetas(phialpha1, phialpha2); #endif }
void SwappedSystem::verify_phibetas (const Wavefunction<amplitude_t>::Amplitude &phialpha1, const Wavefunction<amplitude_t>::Amplitude &phialpha2) const { #ifdef NDEBUG (void) phialpha1; (void) phialpha2; #else const PositionArguments &r1 = phialpha1.get_positions(); const PositionArguments &r2 = phialpha2.get_positions(); assert(r1.get_N_species() == r2.get_N_species()); assert(r1.get_N_sites() == r2.get_N_sites()); assert(copy1_subsystem_indices.size() == r1.get_N_species()); assert(copy2_subsystem_indices.size() == r1.get_N_species()); const Lattice &lattice = phialpha1.get_lattice(); for (unsigned int species = 0; species < r1.get_N_species(); ++species) { const unsigned int N = r1.get_N_filled(species); assert(N == r2.get_N_filled(species)); // verify that the subsystem index arrays have everything they need (and no duplicates!) unsigned int c1 = 0, c2 = 0; for (unsigned int i = 0; i < N; ++i) { const Particle particle(i, species); const bool b1 = vector_find(copy1_subsystem_indices[species], i) != -1; const bool b2 = vector_find(copy2_subsystem_indices[species], i) != -1; if (b1) ++c1; if (b2) ++c2; assert(b1 == subsystem->position_is_within(r1[particle], lattice)); assert(b2 == subsystem->position_is_within(r2[particle], lattice)); } assert(c1 == c2); assert(c1 == copy1_subsystem_indices[species].size()); assert(c2 == copy2_subsystem_indices[species].size()); } assert(phibeta1 != 0); assert(phibeta2 != 0); // verify that the positions in the phibeta's are correct PositionArguments swapped_r1(phialpha1.get_positions()), swapped_r2(phialpha2.get_positions()); swap_positions(swapped_r1, swapped_r2); for (unsigned int species = 0; species < r1.get_N_species(); ++species) { for (unsigned int i = 0; i < r1.get_N_filled(species); ++i) { const Particle particle(i, species); assert(swapped_r1[particle] == phibeta1->get_positions()[particle]); assert(swapped_r2[particle] == phibeta2->get_positions()[particle]); } } #endif }
void AGENT::update_normal(void) { int tx, ty; state = AGENT::NORMAL; // Logic if (!is_dest() && !at_unreachable_dest()) { // move faster if out of position if (within_dist_dest(unitData->radius * 2)) move_mult(1.0); else if (within_dist_dest(unitData->radius * 4)) move_mult(1.1); else move_mult(1.8); // animation setAnimation(ANIMATION_DATA::MOVE, true); } else { // clear last swap memory last_swap = -1; // don't move if (!is_dest_angle() && group->task_type() == TASK::MOVE) rotate_towards((int)group->get_angle_dest()); // rotate towards target else if (rotate_to_group) { if (!is_angle(group->get_rotation())) rotate_towards((int)group->get_rotation()); // rotate to group direction else end_rotate_to_group(); } move_stop(); if (!is_moving()) setAnimation(ANIMATION_DATA::STAND, true); } // Movement if (group->is_single_unit()) sync_to(group); else { swap_count--; if (!collision) move((int)get_dest_x(), (int)get_dest_y(), !group->is_moving()); // no collision else if (!is_dest() && (!agent_collided || agent_collided->getGroup() != getGroup()) && dist_dest() < group->get_radius()) { if (agent_collided) shorten_dest(2 * getRadius()); else { set_dest(group->get_x(), group->get_y()); shorten_dest(100); } } else if (agent_collided && !is_dest() && group->is_dest_angle() && agent_collided->is_near_dest_angle(35) && agent_collided->is_near_dest() && is_near_angle(agent_collided->get_rotation(), 35) && agent_collided->getGroup() == getGroup() && ((!is_last_swap(agent_collided->get_sort_id()) && !agent_collided->is_last_swap(sort_id)) || swap_count < 0)) { // swap group positions swap_positions(agent_collided); // in same group, do it } else collision_avoid(); // collision } // generic update update(); }