Exemplo n.º 1
0
bool PlaybackDialog::parseInstruct(QString instruct, int& sec, int& msecdelay) {
    QRegExp secSearch("(\\d+)s");
    QRegExp minSearch("(\\d+)m");
    QRegExp hourSearch("(\\d+)h");
    QRegExp adsearch("(.+)@(.+)");
    QRegExp fpsSearch("(.+)fps");
    bool ok=false;
    sec=0;
    msecdelay=-1;
    int pos;
    pos=secSearch.indexIn(instruct);
    if (pos!=-1) {
        int newsec=secSearch.cap(1).toInt(&ok);
        if (ok) sec+=newsec;
    }
    pos=minSearch.indexIn(instruct);
    if (pos!=-1) {
        int newmin=minSearch.cap(1).toInt(&ok);
        if (ok) sec+=(newmin*60);
    }
    pos=hourSearch.indexIn(instruct);
    if (pos!=-1) {
        int newhour=hourSearch.cap(1).toInt(&ok);
        if (ok) sec+=(newhour*3600);
    }

    pos=adsearch.indexIn(instruct);
    if (pos!=-1) {
        QString fpsstring=adsearch.cap(2);
        pos=fpsSearch.indexIn(fpsstring);
        if (pos!=-1) {
            double fp=fpsSearch.cap(1).toDouble(&ok);
            if (ok) {
                msecdelay=1000.0/fp;
            }
        }
    }

    return (sec>0);
}
Exemplo n.º 2
0
Arquivo: algo.cpp Projeto: Waqee/Chess
//Almost identical to minSearch, only difference being that it tries to maxmize the board and find most profitable move for player 2
int Computer::maxSearch( int depth , chessboard &chess, int alpha, int beta)
{
    short int i;
    short int j;
    chess.turn=2;
    chess.checkmate();
    if(chess.Checkmate==true)
    {
        chess.Checkmate=false;
        return -INFINITY/depth;
    }
    else if(chess.Stalemate==true)
    {
        chess.Stalemate=false;
        if(Evaluate(chess)<0)
            return INFINITY/(2*depth);
        else
            return -INFINITY/(2*depth);
    }

    if(depth==0)
        return Evaluate(chess);

    vector<Vector2i> ::iterator it;
    vector<Vector2i> Z;

    int bestValue = -INFINITY;

    int promotion = 0;

    for( i = 0; i < 8; i++ )
        for( j = 0; j < 8; j++ )
        {
            if(chess.board[i][j]->getid()!=0 && chess.board[i][j]->getplayer()==2 )
            {
                chess.board[i][j]->getposmoves(Vector2i(j,i),Z,chess.board,2);
                for(it=Z.begin();it!=Z.end();it++)
                {
                    pieces* DestinationPiece;
                    DestinationPiece=chess.board[(*it).y][(*it).x];
                    //Moving
                    chess.board[(*it).y][(*it).x]= chess.board[i][j];
                    chess.board[i][j]=new Empty;

                    if(chess.board[(*it).y][(*it).x]->getid() == 1 && (*it).y==7)
                    {
                        promotion=1;
                        chess.board[(*it).y][(*it).x]=new Queen(2);
                    }

                    //
                    chess.checker();
                    if(chess.check[1]==0)
                    {
                        int value = minSearch( depth-1 , chess ,alpha,beta);
                        if( value >= beta )
                        {   chess.board[i][j]=chess.board[((*it).y)][(*it).x];
                            chess.board[(*it).y][(*it).x]=DestinationPiece;
                            return beta;
                        }
                        if( value>alpha )
                            alpha=value;
                    }
                    //Undo
                    if(promotion==1)
                        chess.board[i][j]=new Pawn(2);
                    else
                        chess.board[i][j]=chess.board[((*it).y)][(*it).x];
                    chess.board[(*it).y][(*it).x]=DestinationPiece;

                }
                Z.clear();
            }
        }
        return alpha;
}