所以我很困惑如何重新洗牌。我编写了代码,并说card_t类型可以分配给int类型;我明白了,但我不知道还能做什么。
void reshuffle(shoe_t* shoe) {
int i, random_position = 0;
card_t arr[52* shoe->num_decks];
card_t temp;
printf("SHUFFLING!\n");
for(i=0; i< 52 * shoe->num_decks; i++) {
random_position = i + rand() % (52* shoe->num_decks - i);
temp = arr[random_position];
arr[random_position] = arr[i];
arr[i] = temp;
}
}
答案 0 :(得分:0)
arr
被定义为int
的数组。看起来你的意思是它是一个card_t
的数组。您可能还希望在random_position
中使用card_t temp = arr[random_position]
之前初始化arr
。
更新:
您也永远不会将shoe
传递给您的主人。 (// Add checkout custom text fields
add_action( 'woocommerce_before_order_notes', 'add_checkout_custom_text_fields', 20, 1 );
function add_checkout_custom_text_fields( $checkout) {
$index = 0;
// 1st Loop through cart items
foreach(WC()->cart->get_cart() as $cart_item){
$index++;
// 2nd Loop through each unit related to item quantity
for($i = 1; $i <= $cart_item['quantity']; $i++){
woocommerce_form_field("my_field[$index][$i]", array(
'type' =>'text',
'class'=>array('my-field-class form-row-wide'),
'label'=>__('My Field')." (item $index - $i)",
'placeholder'=>__('Please enter your data'),
), $checkout->get_value("my_field[$index][$i]"));
}
}
}
// Save fields in order meta data
add_action('woocommerce_checkout_create_order', 'save_custom_fields_to_order_meta_data', 20, 2 );
function save_custom_fields_to_order_meta_data( $order, $data ) {
$index = 0;
// 1st Loop through order items
foreach( $order->get_items() as $item ){
$index++;
// 2nd Loop through each unit related to item quantity
for($i = 1; $i <= $item->get_quantity(); $i++){
if (isset( $_POST['my_field'][$index][$i]) && ! empty($_POST['my_field'][$index][$i]) ){
$order->update_meta_data( '_my_field_'.$index.'_'.$i, esc_attr( $_POST['my_field'][$index][$i] ) );
}
}
}
}
// Display fields in order edit pages
add_action('woocommerce_admin_order_data_after_billing_address','display_custom_fields_in_admin_order', 20, 1);
function display_custom_fields_in_admin_order( $order ){
$index = 0;
// 1st Loop through order items
foreach( $order->get_items() as $item ){
$index++;
// 2nd Loop through each unit related to item quantity
for($i = 1; $i <= $item->get_quantity(); $i++){
$my_field = get_post_meta($order->get_id(),'_my_field_'.$index.'_'.$i, true );
if (! empty($my_field) ){
echo '<p><strong>'.__('My Field')." <em>(item $index - $i)</em>".':</strong> ' . $my_field . '</p>';
}
}
}
}
中是否有一系列卡片正在试图改组?)