Jump to content

[SOLVED] [not solved!]shuffle command not working


bozebo

Recommended Posts

Ok, I have a card game I'm working on, its all fine except the sudden death setting, where the 2 player's cards (10 cards in total) are merged and shuffled then dished out (so, 2 arrays of 5 numbers)

here is the part that is causing problems:

$cards_host_start = array(1,2,3,4,5);
$cards_client_start = array(6,7,8,9,10);

$mixed_cards = array_merge($cards_host_start,$cards_client_start);
$mixed_cards = shuffle($mixed_cards);

for($cardindex = 0;$cardindex <= 4;$cardindex++){
$hostcards_sudden[$cardindex] = $mixed_cards[$cardindex];
}
$hostcards_sudden = implode(',',$hostcards_sudden);

for($cardindex = 5;$cardindex <= 9;$cardindex++){
$clientcards_sudden[$cardindex] = $mixed_cards[$cardindex];
}
$clientcards_sudden = implode(',',$clientcards_sudden);

echo $hostcards_sudden .'<br />'. $clientcards_sudden;

 

I have stuck it into a test page: http://www.bozebo.com/mixtest/

 

OK, with that, both arrays are full of null values, so its imploded as just ,,,,.

when I remove the line: $mixed_cards = shuffle($mixed_cards);

the output is the same as the input, which i would expect, because the arrays are just merged then split laboriously.

 

so.. why isn't shuffle working correctly?

Link to comment
Share on other sites

<?php
$mixedcards = shuffle($mixedcards);?>

 

ehm.. what? thanks for giving me a useless reply, now nobody will help because it has replies...

Was just reading this and thought having never used shuffle() before that I couldn't see why it doesn't work.

 

So I followed darkfreaks link, and the answer is there for you. Although I did have to scroll down the page to the user notes to find it.

 

Hint:

This in fact does not work because shuffle returns a boolean true or false. More accurate code using this method would be:

 

Link to comment
Share on other sites

<?php
$mixedcards = shuffle($mixedcards);?>

 

ehm.. what? thanks for giving me a useless reply, now nobody will help because it has replies...

Was just reading this and thought having never used shuffle() before that I couldn't see why it doesn't work.

 

So I followed darkfreaks link, and the answer is there for you. Although I did have to scroll down the page to the user notes to find it.

 

Hint:

This in fact does not work because shuffle returns a boolean true or false. More accurate code using this method would be:

 

 

oh? ill take a look

 

edit:

OH.. I was dumb to not notice that lol. Thanks.. (but darkfreaks' reply wasnt actually any help caus he thought the same thing as me :D)

 

OH lol.. now i have [sOLVED][not solved!].. ah well

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.