void Field::giveHint() { if (makeRandomSpecial()) return; int r = rand() % field.size(); for (;; r = rand() % field.size()) { if (field[r].type != Tile::BOMB && !field[r].is_revealed) break; } makeSpecial(r); }
bool Field::makeRandomSpecial() { int nr = field.size(); for (uint i = 0; i < field.size(); ++i) { if (field[i].type != Tile::EMPTY || field[i].is_revealed) nr--; } if (nr == 0) { if (is_debugging) { cout << "No special block this time :(\n"; } return false; } int r = rand() % field.size(); for (;; r = rand() % field.size()) { if (field[r].type == Tile::EMPTY && !field[r].is_revealed) break; } makeSpecial(r); return true; }
int main(int argc, char *argv[]) { char outFileName[64],datFileName[64],moldyName[128]; char *str; // atom *atomPtr; int g,nstart,j,ak,count; FILE *fp; double charge; int moldyFlag = 0; // suppress creation of ..._moldy.in file int distPlotFlag = 0; // suppress creation of disList.dat /* Let's set the radii of certain elements by hand: */ // atRad = (double *)realloc(atRadf, 109*sizeof(double)); // covRad = (double *)realloc(covRadf,109*sizeof(double)); atRad = (double *)malloc(109*sizeof(double)); covRad = (double *)malloc(109*sizeof(double)); memcpy(atRad, atRadf,36*sizeof(double)); memcpy(covRad,covRadf,36*sizeof(double)); atRad[39-1]=2.27; covRad[39-1]=2.62; // Y atRad[57-1]=2.74; covRad[57-1]=1.69; // La atRad[71-1]=2.25; covRad[71-1]=1.56; // Lu if (argc < 2) sprintf(datFileName,"gb.gbm"); else strcpy(datFileName,argv[1]); // read a flag: if (argc > 2) { if (strncmp(argv[2],"-m",2) == 0) { moldyFlag = 1; // also write a moldy file! printf("Saving moldy input file!\n"); } } muls->nCellX = 1; muls->nCellY = 1; muls->nCellZ = 1; muls->ctiltx = 0; muls->ctilty = 0; muls->ctiltz = 0; superCell.atoms = NULL; superCell.natoms = 0; if (!readParams(datFileName)) exit(0); if (nGrains > 0) { // loop, until we find crystalline grains: for (g=0; g<nGrains; g++) if (grains[g].amorphFlag == CRYSTALLINE) break; /* make the crystalline part of the super cell */ if (g<nGrains) makeSuperCell(); /* if there is also an amorphous part, then add it now, and also write a * MD input file, so that the amorphous phase atoms can be relaxed */ for (g=0; g<nGrains; g++) if (grains[g].amorphFlag != CRYSTALLINE) break; if (g<nGrains) { if (moldyFlag) { sprintf(moldyName,"%s",datFileName); moldyName[strlen(datFileName)-4] = '\0'; strcat(moldyName,"_moldy.in"); if ((fp=fopen(moldyName,"w")) == NULL) { printf("Could not open moldy input file %s!\n",moldyName); exit(0); } } else { fp = NULL; } if (nGrains > 1) { writeFrameWork(fp,superCell); computeCenterofMass(); nstart = superCell.natoms; switch (grains[g].amorphFlag) { case 1: makeAmorphous(); break; case 2: makeSpecial(distPlotFlag); break; } writeAmorphous(fp,superCell,nstart,superCell.natoms); } else { switch (grains[g].amorphFlag) { case 1: makeAmorphous(); break; case 2: makeSpecial(distPlotFlag); break; } writeAmorphous(fp,superCell,0,superCell.natoms); } if (moldyFlag) fclose(fp); } } if (0) { // (moldyFlag) { /////////////////////////////////////////////////////////////// // write Moldy input file, without presence of amorphous phase: sprintf(moldyName,"%s",datFileName); moldyName[strlen(datFileName)-4] = '\0'; strcat(moldyName,"_moldy.in"); if ((fp=fopen(moldyName,"w")) == NULL) { printf("Could not open moldy input file %s!\n",moldyName); exit(0); } // writeFrameWork(fp,superCell); // computeCenterofMass(); // superCell2Moldy(fp,superCell); fclose(fp); } // end of: if moldyFlag ... strcpy(outFileName,datFileName); // atomPtr = readUnitCell(&natoms,fileName,&muls); // writePDB(atomPtr,nat /* reset the input file and advance to the next crystal row */ str = strchr(outFileName,'.'); if (str == NULL) str=outFileName+strlen(outFileName); sprintf(str,".cfg"); muls->ax = (float)superCell.ax; muls->by = (float)superCell.by; muls->c = (float)superCell.cz; superCell.natoms = removeVacancies(superCell.atoms,superCell.natoms); printf("will write cfg file to %s\n",outFileName); writeCFG(superCell.atoms, superCell.natoms, outFileName, muls); printf("wrote cfg file to %s\n",outFileName); /************************************************************** * find the charge for the Y-atoms, in order to remain neutral: */ charge = 0.0; if (0) { for (ak=0;ak<muls->atomKinds;ak++) { count =0; for (j=0;j<superCell.natoms;j++) { if (muls->Znums[ak] == superCell.atoms[j].Znum) count++; } printf("Z=%3d: %d\n",muls->Znums[ak],count); switch (muls->Znums[ak]) { case 7: charge += count*(-3.0); break; case 8: charge += count*(-2.0); break; case 38: charge += count*(2.0); break; case 22: charge += count*(4.0); break; case 14: charge += count* 4.0; break; } } } else { for (j=0;j<superCell.natoms;j++) { charge += superCell.atoms[j].q*superCell.atoms[j].occ; } } // printf("Total charge: %g, i.e. %g %s\n",charge,charge,(charge > 0) ? "holes" : "electrons"); printf("Total charge: %g",charge); if (charge > 0) printf(", i.e. %g holes\n",charge); if (charge < 0) printf(", i.e. %g electrons\n",-charge); delete(muls); return 0; }
void Field::makeSpecial(int x, int y) { makeSpecial(y*size.x + x); }