コード例 #1
0
ファイル: test-texture-3d.c プロジェクト: 3v1n0/cogl
static void
validate_result (void)
{
  int i;

  validate_block (0, 0, 0);

  for (i = 0; i < TEX_DEPTH; i++)
    validate_block (i, 1, i);
}
コード例 #2
0
ファイル: crypto777.c プロジェクト: jonesnxt/SuperNET_API
struct crypto777_block *parse_block777(struct consensus_model *model,struct crypto777_node *nn,struct crypto777_block *block,int32_t len,uint32_t peerid)
{
    char *blockstr = (char *)block->rawblock;
    uint64_t metric;
    int32_t bestacct;
    cJSON *json;
    uint32_t timestamp,blocknum = 0;
    if ( (bestacct= validate_block(block)) >= 0 && peerid < nn->numpeers && (json= cJSON_Parse(blockstr)) != 0 )
    {
        blocknum = juint(json,"blocknum");
        timestamp = juint(json,"timestamp");
        metric = get_API_nxt64bits(cJSON_GetObjectItem(json,"metric"));
        model->peermetrics[blocknum][peerid] = metric;
        model->peerblocknum[peerid] = blocknum;
        free_json(json);
        if ( block->blocknum == blocknum ) //  block->gen.metric == metric &&
            return(block);
        else printf("error parse.(%s) metric %.8f vs %.8f blocknum %u vs %u\n",blockstr,dstr(block->gen.metric),dstr(metric),block->blocknum,blocknum);
    }
    else
    {
        int i;
        for (i=0; i<len; i++)
            printf("%02x ",((uint8_t *)block)[i]);
        printf("block.%d (%s) peerid.%d numpeers.%d\n",block->blocknum,blockstr,peerid,nn->numpeers);
    }
    return(0);
}
コード例 #3
0
ファイル: rlnc_data_dec.hpp プロジェクト: hundeboll/netmix
    void put_pkt(buf_ptr &buf)
    {
        size_t rank;
        size_t block = super::rlnc_hdr_block(buf);

        if (!validate_block(block)) {
            if (m_late_pkts++ % 5 == 1)
                send_ack(block, base::m_coder->symbols());
            return;
        }

        assert(buf->data_val() % 4u == 0);
        assert(buf->data_len() >= super::rlnc_symbol_size());

        rank = base::m_coder->rank();
        super::rlnc_hdr_del(buf);
        base::m_coder->decode(buf->head());

        assert(base::m_coder->rank() <= base::m_coder->remote_rank());

        if (base::m_coder->rank() == rank) {
            ++m_linear;
            ++m_linear_block;
            ++m_linear_count;
        } else {
            m_linear = 0;
        }

        if (m_linear < 50)
            return;

        std::cout << "emergency ack " << base::m_coder->rank() << std::endl;
        send_ack(super::rlnc_hdr_block(), base::m_coder->rank());
    }
コード例 #4
0
    void process_ack(buf_ptr &buf)
    {
        size_t block = super::rlnc_hdr_block(buf);

        if (!validate_block(block))
            return;

        base::put_status(buf->data(), &m_decoder_rank);

        std::cout << "enc ack rank " << m_decoder_rank << std::endl;

        if (m_decoder_rank < super::rlnc_symbols())
            return;

        std::cout << "enc ack block " << block << std::endl;
        increment();
    }
コード例 #5
0
ファイル: parser.cpp プロジェクト: maleadt/genetic
// Evaluate DNA
void Parser::validate(const DNA& iDNA) {
    // Reset the quotum
    mInstructionCounter = 0;

    // Validate all blocks
    for (unsigned int i = 0; i < iDNA.genes(); i++) {
        // Extract the blocks
        unsigned char* tGene;
        unsigned int tSize;
        iDNA.extract_gene(i, tGene, tSize);

        // Evaluate the block
        validate_block(tGene, tSize);

        // Free the block
        free(tGene);
    }
}
コード例 #6
0
ファイル: sudoku.c プロジェクト: phpminu/danieleugenewilliams
bool
legal(int num)
{
    // convert ascii value to integer value
    char ch[2];
    sprintf(ch, "%c", num);
    int nbr = atoi(ch);

    // validate row
    for(int i = 0; i < 9; i++)
    {
        if((g.board[g.y][i] != 0) && (g.board[g.y][i] == nbr) && (g.x != i))
            return false;
    }
    
    // validate column
    for(int i = 0; i < 9; i++)
    {
        if((g.board[i][g.x] != 0) && (g.board[i][g.x] == nbr) && (g.y != i))
            return false;
    }
    
    // validate top row 3x3 blocks
    if(g.y >= 0 && g.y <= 2)
    {
        // top-left 3x3 block
        if(g.x >= 0 && g.x <= 2)
        {
            if(!validate_block(0, 2, 0, 2, nbr))
                return false;
        }
        
        // top-middle 3x3 block
        if(g.x >= 3 && g.x <= 5)
        {
            if(!validate_block(0, 2, 3, 5, nbr))
                return false;
        }
        
        // top-right 3x3 block
        if(g.x >= 6 && g.x <= 8)
        {
            if(!validate_block(0, 2, 6, 8, nbr))
                return false;
        }
    }
    
    // validate middle row 3x3 blocks
    if(g.y >= 3 && g.y <= 5)
    {
        // middle-left 3x3 block
        if(g.x >= 0 && g.x <= 2)
        {
            if(!validate_block(3, 5, 0, 2, nbr))
                return false;
        }
        
        // middle-middle 3x3 block
        if(g.x >= 3 && g.x <= 5)
        {
            if(!validate_block(3, 5, 3, 5, nbr))
                return false;            
        }
        
        // middle-right 3x3 block
        if(g.x >= 6 && g.x <= 8)
        {
            if(!validate_block(3, 5, 6, 8, nbr))
                return false;
        }
    }
    
    // validate bottom row 3x3 blocks
    if(g.y >= 6 && g.y <= 8)
    {
        // bottom-left 3x3 block
        if(g.x >= 0 && g.x <= 2)
        {
            if(!validate_block(6, 8, 0, 2, nbr))
                return false;
        }
        
        // bottom-middle 3x3 block
        if(g.x >= 3 && g.x <= 5)
        {
            if(!validate_block(6, 8, 3, 5, nbr))
                return false;
        } 
        
        // bottom-right 3x3 block
        if(g.x >= 6 && g.x <= 8)
        {
            if(!validate_block(6, 8, 6, 8, nbr))
                return false;
        }  
    }
    
    return true;
}
コード例 #7
0
ファイル: validation.c プロジェクト: kanatohodets/MoarVM
/* Validate that a static frame's bytecode is executable by the interpreter. */
void MVM_validate_static_frame(MVMThreadContext *tc,
                               MVMStaticFrame *static_frame) {
    MVMStaticFrameBody *fb = &static_frame->body;
    Validator val[1];

    val->tc        = tc;
    val->cu        = fb->cu;
    val->frame     = static_frame;
    val->loc_count = fb->num_locals;
    val->loc_types = fb->local_types;
    val->bc_size   = fb->bytecode_size;
    val->src_cur_op = fb->bytecode;
    val->src_bc_end = fb->bytecode + fb->bytecode_size;
    val->labels    = MVM_calloc(fb->bytecode_size, 1);
    val->cur_info  = NULL;
    val->cur_mark  = NULL;
    val->cur_instr = 0;
    val->cur_call  = NULL;
    val->cur_arg   = 0;

    val->expected_named_arg    = 0;
    val->remaining_positionals = 0;
    val->remaining_jumplabels  = 0;
    val->reg_type_var          = 0;

#ifdef MVM_BIGENDIAN
    assert(fb->bytecode == fb->orig_bytecode);
    val->bc_start = MVM_malloc(fb->bytecode_size);
    memset(val->bc_start, 0xDB, fb->bytecode_size);
    fb->bytecode = val->bc_start;
#else
    val->bc_start = fb->bytecode;
#endif
    val->bc_end = val->bc_start + fb->bytecode_size;
    val->cur_op = val->bc_start;

    while (val->cur_op < val->bc_end) {
        read_op(val);
        if (val->cur_mark && val->cur_mark[0] == 's')
            fail(val, MSG(val, "Illegal appearance of spesh op"));

        switch (val->cur_mark[0]) {
        case MARK_regular:
        case MARK_special:
            validate_operands(val);
            break;

        case MARK_sequence:
            validate_sequence(val);
            break;

        case MARK_head:
            validate_block(val);
            break;

        default:
            fail_illegal_mark(val);
        }
    }

    validate_branch_targets(val);
    validate_final_return(val);

    /* Validation successful. Cache the located instruction offsets. */
    fb->instr_offsets = val->labels;
}
コード例 #8
0
ファイル: grid.cpp プロジェクト: MisanthropicBit/Blockzorz-2
void grid::check_block(int row, int col) {
    int score = 0;

    // Is the block even valid?
    if(validate_block(row, col) == BLOCK_TYPE_NOGOOD) {
        return;
    }

    block_type type = grid[row][col]->block_type();

    int connected_above = 0;
    int connected_below = 0;
    //bool pointsAboveOrBelow = false;

    // Check above block
    for (int i = row - 1; i >= 0; --i) {
        if (validate_block(i, col) == type) {
            ++connected_above;
        } else {
            break;
        }
    }

    // Check below block
    for (int i = row + 1; i < GRID_MAX_ROWS; ++i) {
        if(ValidateBlock(i, col) == type) {
            ++connected_below;
        } else {
            break;
        }
    }

    if(connecteda_bove + connected_below >= 2) {
        //pointsAboveOrBelow = true;
        score += connected_above + connected_below;

        for (int i = row + connectedbelow; i >= row - connectedabove; --i) {
            grid[i][col]->kill();
        }

        for (int i = row - connectedabove - 1; i >= 0; --i) {
            if (validate_block(i, col) != BLOCK_TYPE_NOGOOD) {
                grid[i][col]->Fall();
            } else {
                break;
            }
        }
    }

    int connected_left  = 0;
    int connected_right = 0;

    // Check left of block
    for (int i = col - 1; i >= 0; --i) {
        if(validate_block(row, i) == type) {
            ++connectedleft;
        } else {
            break;
        }
    }

    // Check right of block
    for (int i = col + 1; i < GRID_MAX_COLUMNS; ++i) {
        if (ValidateBlock(row, i) == blocktype) {
            ++connected_right;
        } else {
            break;
        }
    }

    // We need at least three connected blocks
    if (connected_left + connected_right >= 2) {
        // Add to score
        score += connectedleft + connectedright;

        for (int i = col - connectedleft; i <= col + connectedright; ++i) {
            // Run through blocks again and kill them
            grid[row][i]->kill();
        }

        for (int i = col - connectedleft; i <= col + connectedright; ++i) {
            // Run through blocks than now need to fall
            //if(pointsAboveOrBelow && i == col) // Points scored in vertical direction, don't make 
            //  continue;

            for (int j = row - 1; j >= 1; --j) {
                if (validate_block(j, i) != BLOCK_TYPE_NOGOOD) {
                    grid[j][i]->fall();
                } else {
                    break;
                }
            }
        }
    }

    if (score > 0) {
        // If the player scored any points
        // For the block we're checking
        score += 1; 
        grid[row][col]->kill();

        if (game::game_settings.cf_mode_unlocked) {
            audio_manager::get()->play_sound("yes!", 0);
        }

        if(score > 3) {
            // More than three blocks connected counts as a combo
            ++combos;
            score *= POINTS_PER_BLOCK;
            score += COMBO_POINTS * (score - 3);
        } else {
            score *= POINTS_PER_BLOCK;
        }

        this->score += score;

        //audio_manager::get()->play_sound("explosion", 0);
    } else {
        grid[row][col]->dont_check(); // If no points were scored, don't check this block anymore
    }
}