double MyParser::EvalRemoveSingularity(double *xvar) { try { double result = Eval(); if ( gsl_isinf(result) || gsl_isnan(result) ) throw Singularity(); return result; } catch (Singularity) { try { if (isinf(Eval())) throw Pole(); int n; frexp (*xvar, &n); double xp = *xvar + ldexp(DBL_EPSILON,n); double xm = *xvar - ldexp(DBL_EPSILON,n); *xvar = xp; double yp = Eval(); if (gsl_isinf(yp) || gsl_isnan(yp)) throw Pole(); *xvar = xm; double ym = Eval(); if (gsl_isinf(ym) || gsl_isnan(ym)) throw Pole(); return (yp + ym)/2; } catch (Pole) { SingularityErrorMessage(*xvar); return GSL_ESING; } } }
void Plansza::WybierzFigure(char& k, short int& w, bool tura) { string temp; while (1) { cout << "Wybierz figurę, którą zamierzasz wykonać ruch (Podaj pole)" << endl; cin >> temp; CzyscBufor(); if (RegexPole(temp)) { if(temp[0]<'Z') k=temp[0]+' '; else k=temp[0]; w=atoi(&temp[1]); if(!Pole(k, w)) EmptyErr(); else if((Pole(k, w)->BoolKolor())!=tura) WCErr(); else { if(Pole(k, w)->CzyMozliwyRuch(_plansza)) { if (/*Potwierdzenie()*/1) break; } else { NMPErr(); } } } } }
Plansza::~Plansza() { for(char i='a';i<'i';++i) { for(short int j=1;j<9;++j) { if (Pole(i,j)) delete Pole(i, j); } } }
void Ko³o::Wypisz() { cout << "S<" << x1 << "," << y1 << ">; "; // cout<<"W2<"<<x2<<","<<y2<<">"<<endl; // cout<<"W3<"<<x3<<","<<y3<<">"<<endl; // cout<<"W4<"<<x4<<","<<y4<<">"<<endl; cout << "Pole=" << Pole() << "; "; cout<<"Obwod="<<Obwód()<<endl; }
void Plansza::WypiszTekst() { int parse=0; for(int i=1;i<9;++i) { for(char c='a';c<'i';++c) { if (Pole(c, i)) { cout << Pole(c, i)->Kolor() << Pole(c, i)->Nazwa() << ' ' << (char)((Pole(c,i)->Kolumna() -'a'+'A')) << Pole(c, i)->Wiersz() << "\t"; } ++parse; if (parse%8) { if (!(Pole(c, i))) cout << "\t\t"; } else cout << endl; } } }
/*! * * \brief Definicja funkcji reprezentująca wykonywane ruchy przez figury. */ void MainWindow::qruch() { Pole tmp(sender()->objectName().toStdString()); if (!end) { if (start == Pole(0,0)) { if (R.P[tmp.x()][tmp.y()].figtype()!=0) { if (R.P[tmp.x()][tmp.y()].kolor() == R.next) { start = tmp; qmozliwe = R.ruchy(R.P[tmp.x()][tmp.y()]); szachownica(qmozliwe); } } } else { for (unsigned int i=0;i<qmozliwe.size();i++) { if (tmp == qmozliwe[i]) { cel = tmp; break; } } if (cel != Pole(0,0)) { R.ruch(start,cel); R.bulid_one(); if (R.wsk.empty()) { if (R.next) { if(R.szach(R.bking)) { R.addlog(start,cel); R.addlog("biale mat"); } else { R.addlog(start,cel); R.addlog("pat"); } } else { if(R.szach(R.wking)) { R.addlog(start,cel); R.addlog("czarne mat"); } else { R.addlog(start,cel); R.addlog("pat"); } } displog(); display(); start=Pole(0,0); cel=Pole(0,0); qmozliwe.clear(); szachownica(); return; } R.addlog(start,cel); displog(); display(); R.bulid_tree(); R.minmax(); Pole s=R.wyb->st; Pole c=R.wyb->cl; R.ruch(s,c); R.bulid_one(); if (R.wsk.empty()) { if (R.next) { if(R.szach(R.bking)) { R.addlog(start,cel); R.addlog("biale mat"); } else { R.addlog(start,cel); R.addlog("pat"); } } else { if(R.szach(R.wking)) { R.addlog(start,cel); R.addlog("czarne mat"); } else { R.addlog(start,cel); R.addlog("pat"); } } displog(); display(); start=Pole(0,0); cel=Pole(0,0); qmozliwe.clear(); szachownica(); return; } R.addlog(s,c); displog(); display(); } start=Pole(0,0); cel=Pole(0,0); qmozliwe.clear(); szachownica(); R.Biale.clear(); R.Czarne.clear(); R.wsk.clear(); } } }
Plansza::Plansza() { this->_plansza = array<array<Figura*, 8>, 8>(); for(int i=0;i<8;++i) { _plansza[i] = array<Figura*, 8>(); } for(char k='a';k<'i';++k) { Pole(k, 2) = new Pion(0, k, 2, 0); Pole(k, 7) = new Pion(1, k, 7, 0); } Pole('a', 1) = new Wieza(0, 'a', 1, 0); Pole('a', 8) = new Wieza(1, 'a', 8, 0); Pole('h', 1) = new Wieza(0, 'h', 1, 0); Pole('h', 8) = new Wieza(1, 'h', 8, 0); Pole('b', 1) = new Skoczek(0, 'b', 1, 0); Pole('b', 8) = new Skoczek(1, 'b', 8, 0); Pole('g', 1) = new Skoczek(0, 'g', 1, 0); Pole('g', 8) = new Skoczek(1, 'g', 8, 0); Pole('c', 1) = new Goniec(0, 'c', 1, 0); Pole('c', 8) = new Goniec(1, 'c', 8, 0); Pole('f', 1) = new Goniec(0, 'f', 1, 0); Pole('f', 8) = new Goniec(1, 'f', 8, 0); Pole('d', 1) = new Hetman(0, 'd', 1, 0); Pole('d', 8) = new Hetman(1, 'd', 8, 0); Pole('e', 1) = new Krol(0, 'e', 1, 0); Pole('e', 8) = new Krol(1, 'e', 8, 0); }