-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathScrambler.php
executable file
·47 lines (41 loc) · 1.1 KB
/
Scrambler.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
class Scrambler
{
private $faces = array('U', 'D', 'L', 'R', 'F', 'B');
public function __construct()
{
$this->length = 25;
$this->chance_prime = 25;
$this->chance_double = 35;
}
public function setLength($value)
{
$this->length = $value;
}
public function setChancePrime($value)
{
$this->chance_prime = $value;
}
public function setChanceDouble($value)
{
$this->chance_double = $value;
}
public function generate()
{
$last = null;
do {
$move = $this->faces[array_rand($this->faces)];
if ($move != $last) {
$last = $move;
$rand = mt_rand(0, 100);
if ($rand <= $this->chance_prime) {
$move .= "'";
} elseif ($rand <= $this->chance_prime + $this->chance_double) {
$move .= '2';
}
$scramble[] = $move;
}
} while (count($scramble) < $this->length);
return implode(' ', $scramble);
}
}