currently im working on a game and I'm progressing quite well.
The problem is my shuffle algorithm. A word should be shuffled with randomness
but MUST NOT shuffled in its original wordform. Example: "table" -> "table"
I want something like this: "table" -> "tlabe"
The first and last letter should stay at its place but the rest can be shuffled randomly except to its original wordform.
Currently i am using this function i wrote:
function shuffle_word($word)
{
if(strlen($word) < 2)
return $word;
else
return $word{0} . str_shuffle(substr($word, 1, -1)) . $word{strlen($word) - 1};
}
You can check out my game so far and get a better idea of it:
WordShuffle - The Game
(Sorry the words are german at the moment, because I am german and testing it with friends make it easier)