-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtiles.php
47 lines (45 loc) · 1.3 KB
/
tiles.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
trait Tiles {
public function sharedProperty() {
$sharedProperties = $this->sharedProperties();
if (count($sharedProperties) === 0) {
return null;
} elseif (count($sharedProperties) === 1) {
return $sharedProperties[0];
} else {
throw new IllegalArgumentException("Cannot called sharedProperty on a single tile or duplicates of a single tile.");
}
}
public function sharedProperties() {
$sharedProperty = null;
$sharedProperties = [];
foreach (Color::colors() as $color) {
foreach ($this->tiles() as $tile) {
if ($sharedProperty === null || $sharedProperty === $tile->color()) {
$sharedProperty = $tile->color();
} else {
$sharedProperty = null;
break 2;
}
}
}
if ($sharedProperty !== null) {
$sharedProperties[] = $sharedProperty;
}
$sharedProperty = null;
foreach (Shape::shapes() as $shape) {
foreach ($this->tiles() as $tile) {
if ($sharedProperty === null || $sharedProperty === $tile->shape()) {
$sharedProperty = $tile->shape();
} else {
$sharedProperty = null;
break 2;
}
}
}
if ($sharedProperty !== null) {
$sharedProperties[] = $sharedProperty;
}
return $sharedProperties;
}
}