Exemple #1
0
 bool goodFrame(const StartStop& self) const {
     // longer or equal to frame_length
     // OR good identity
     if (ssLength(self) >= frame_length_) {
         return true;
     }
     int score = countScore(self.first, self.second);
     int min_score = min_identity_ * ssLength(self);
     return score >= min_score;
 }
Exemple #2
0
void MainWindow2::resetGame(){
    ui->label_12->move(QPoint(-85, 25));
    ui->label_15->move(QPoint(-85, 25));
    ui->label_16->move(QPoint(-85, 25));
    ui->label_17->move(QPoint(-85, 25));

    drumID = 0;
    score = 0;
    countScore();
    time = 31;
}
Exemple #3
0
void MainWindow2::hitDrumL(){
    ui->label_9->setVisible(true);
    ui->label_10->setVisible(true);
    QTimer::singleShot(100,this,SLOT(drumUp()));
    if (ui->label_16->x() <=25 && ui->label_16->x() >= 5){
        ui->label_16->move(QPoint(-85, 25));
        drumID = 2;
        ui->label_13->setVisible(true);
        QTimer::singleShot(100,this,SLOT(drumEx()));
    }
    else if (ui->label_17->x() <=25 && ui->label_17->x() >= 5){
        ui->label_17->move(QPoint(-85, 25));
        drumID = 4;
        ui->label_13->setVisible(true);
        QTimer::singleShot(100,this,SLOT(drumEx()));
    }
    else drumID = 0;
    countScore();
}
Exemple #4
0
 bool goodSlice(int start) const {
     int stop = start + frame_length_ - 1;
     return countScore(start, stop) >= frame_score_;
 }
Exemple #5
0
int evaluateMaxMove( unsigned int *board, int depth )
{
    int value, x, y;
    int max = MIN_INFINITY-1;
    int scores1[MAX_BOARD_SIZE][MAX_BOARD_SIZE];
    int scores2[MAX_BOARD_SIZE][MAX_BOARD_SIZE];
    
    // printf("DEPTH=%d\n", depth);
    boards_checked++;
    /*
     for (i = 0; i < depth; i++) printf(" ");
     printf("%d min %d %d\n", depth, last_move_x, last_move_y);
     */
    
    /* Player 1 (min) just made a move, so we evaluate that move here */
    if (checkPlayerWin(X_PLAYER, board)) return MIN_INFINITY;
    
    /* If Player 2 has a winning position, take it */
    for (x = 0; x < MAX_BOARD_SIZE; x++)
        for (y = 0; y < MAX_BOARD_SIZE; y++) {
            
            if (getCell(x, y, board) == EMPTY && hasNeighbor(x, y, board)) {
                scores1[x][y] = countScore( O_PLAYER, x, y, board, 4);
                if (scores1[x][y] == MAX_INFINITY) {
                    if (depth == 0) { computer_move_x = x; computer_move_y = y; }
                    return MAX_INFINITY;
                }
            }
        }
    
    /* If Player 1 has a winning position, block it */
    for (x = 0; x < MAX_BOARD_SIZE; x++)
        for (y = 0; y < MAX_BOARD_SIZE; y++)
            if (getCell(x, y, board) == EMPTY && hasNeighbor(x, y, board)) {
                
                scores2[x][y] = countScore( X_PLAYER, x, y, board, 4);
                if (scores2[x][y] == MAX_INFINITY) {
                    putCell( O_PLAYER, x, y, board );
                    if (depth == 0) { computer_move_x = x; computer_move_y = y; return 0; }
                    max = evaluateMinMove( board, depth+1 );
                    resetCell( x, y, board);
                    return max;
                }
            }
    
    /* Cutoff checking */
    if (depth >= CUTOFF) {
        // printf("depth %d scores\n", depth);
        for (x = 0; x < MAX_BOARD_SIZE; x++)
            for (y = 0; y < MAX_BOARD_SIZE; y++)
                if (getCell(x, y, board) == EMPTY && hasNeighbor(x, y, board)) {
                    value = (scores2[x][y])+(scores1[x][y]<<1);
                    // printf("max (%d %d) %d %d %d\n", x, y, value, scores1[x][y], scores2[x][y]);
                    if (value > max) {
                        max = value;
                    }
                }
        return max;
    }
    
    for (x = 0; x < MAX_BOARD_SIZE; x++)
        for (y = 0; y < MAX_BOARD_SIZE; y++)
            if (getCell(x, y, board) == EMPTY && hasNeighbor(x, y, board)) {
                
                putCell( O_PLAYER, x, y, board );
                value = evaluateMinMove( board, depth+1 );
                resetCell( x, y, board);
                
                // printf("depth=%d value = %d for %d %d\n", depth, value, x, y);
                if (value > max) {
                    max = value;
                    if (depth == 0) { 
                        computer_move_x = x; computer_move_y = y; 
                    }
                    if (max == MAX_INFINITY) return max;
                }
                
            }
    
    /* No move is possible -- draw */
    if (max == MIN_INFINITY-1) {
        return DRAW;
    }
    
    return max;
}
Exemple #6
0
int evaluateMinMove( unsigned int *board, int depth )
{
    int value, x, y;
    int min = MAX_INFINITY+1;
    int scores1[MAX_BOARD_SIZE][MAX_BOARD_SIZE];
    int scores2[MAX_BOARD_SIZE][MAX_BOARD_SIZE];
    
    // printf("DEPTH=%d\n", depth);
    boards_checked++;
    /*
     for (i = 0; i < depth; i++) printf(" ");
     printf("%d max %d %d\n", depth, last_move_x, last_move_y);
     */
    
    /* Player 2 (max) just made a move, so we evaluate that move here */
    if (checkPlayerWin(O_PLAYER, board)) return MAX_INFINITY;
    
    /* If Player 1 has a winning position, take it */
    for (x = 0; x < MAX_BOARD_SIZE; x++)
        for (y = 0; y < MAX_BOARD_SIZE; y++)
            if (getCell(x, y, board) == EMPTY && hasNeighbor(x, y, board)) {
                scores1[x][y] = countScore( X_PLAYER, x, y, board, 4);
                if (scores1[x][y] == MAX_INFINITY) return MIN_INFINITY;
            }
    
    /* If Player 2 has a winning position, block it */
    for (x = 0; x < MAX_BOARD_SIZE; x++)
        for (y = 0; y < MAX_BOARD_SIZE; y++)
            if (getCell(x, y, board) == EMPTY && hasNeighbor(x, y, board)) {
                scores2[x][y] = countScore( O_PLAYER, x, y, board, 4);
                if (scores2[x][y] == MAX_INFINITY) {
                    putCell( X_PLAYER, x, y, board );
                    min = evaluateMaxMove( board, depth+1 );
                    resetCell( x, y, board);
                    return min;
                }
            }
    
    /* Cutoff checking */
    if (depth >= CUTOFF) {
        // printf("depth %d scores\n", depth);
        for (x = 0; x < MAX_BOARD_SIZE; x++)
            for (y = 0; y < MAX_BOARD_SIZE; y++)
                if (getCell(x, y, board) == EMPTY && hasNeighbor(x, y, board)) {
                    // the value of position (x, y) is the sum of its score when the opponent is placed
                    // at that position plus the twice of the score when itself is placed at that position.
                    value = (scores2[x][y])+(scores1[x][y]<<1);
                    
                    // printf("min (%d %d) %d %d %d\n", x, y, value, scores1[x][y], scores2[x][y]);
                    
                    // the value is negated for min-move
                    value = -value;
                    if (value < min) {
                        min = value;
                    }
                }
        return min;
    }
    
    for (x = 0; x < MAX_BOARD_SIZE; x++)
        for (y = 0; y < MAX_BOARD_SIZE; y++)
            if (getCell(x, y, board) == EMPTY && hasNeighbor(x, y, board)) {
                
                putCell( X_PLAYER, x, y, board );
                value = evaluateMaxMove( board, depth+1 );
                resetCell(x, y, board);
                
                // printf("depth=%d value = %d for %d %d\n", depth, value, x, y);
                if (value < min) {
                    min = value;
                    if (min == MIN_INFINITY) return min;
                }
            }
    
    /* No move is possible -- draw */
    if (min == MAX_INFINITY+1) {
        return DRAW;
    }
    
    return min;
}
Exemple #7
0
int checkPlayerWin( int player, unsigned int *board )
{
    // Check if there are four same pieces in a row at position (last_move_x, last_move_y)
    return (countScore(player, last_move_x, last_move_y, board, 4) == MAX_INFINITY);
}