:: test genetics [nobr]

<<set $nextButton = "Back", $nextLink = "Options">>
<<set _seed = 0>>

All slave array slaves MUST be present in genePool or else there is a malfunction.
<table><caption style="background-color: rgba(127, 127, 127, 0.2)">genePool</caption>
<tr><th>index</th><th>name</th><th>ID</th><th>origin</th></tr>
<<for _i = 0; _i < $genePool.length; _i++>>
	<tr>
		<td>_i</td>
		<td>$genePool[_i].slaveName</td>
		<td>$genePool[_i].ID</td>
		<td>$genePool[_i].origin</td>
	</tr>
<</for>>
</table>

<<set _neededProperties = ['genes', 'origSkin', 'eye.origColor', 'origHColor', 'nationality', 'origRace', 'face', 'faceShape', 'markings', 'intelligence', 'underArmHStyle', 'pubicHStyle']>>
<table><caption style="background-color: rgba(127, 127, 127, 0.2)">slaves</caption>
<tr><th>index</th><th>name</th><th>ID</th><th>origin</th><th>assignment</th></tr>
<<for _i = 0; _i < $slaves.length; _i++>>
	<<set _s = $slaves[_i]>>
	<<set _error = $genePool.every(function(g) { return $slaves[_i].ID !== g.ID; })>>
	<<if _error>><<set _errorCause = "Doesn't exist in the gene pool">><</if>>
	<<if !_error>>
		<<set _missingProperties = _neededProperties.filter(function(p) {
			p = p.split(".");
			let c = _s;
			for (const r of p) {
				if (!(r in c)) {
					return true;
				}
				c = c[r];
			}
			return false;
		})>>
		<<if _missingProperties.length > 0>>
			<<set _error = true, _errorCause = "Missing properties: " + _missingProperties.join(", ")>>
		<</if>>
	<</if>>
	<<if _error>>
		<tr class="red">
			<td>_i</td>
			<td>_s.slaveName</td>
			<td>_s.ID</td>
			<td>_s.origin</td>
			<td>_s.assignment</td>
			<td>_errorCause</td>
		</tr>
	<<else>>
		<tr class="green">
			<td>_i</td>
			<td>_s.slaveName</td>
			<td>_s.ID</td>
			<td>_s.origin</td>
			<td>_s.assignment</td>
			<td></td>
		</tr>
	<</if>>
<</for>>
</table>

<<if _errorCause>>
	@@.red;Errors in the gene pool detected! Please report this.@@
	<<link "Add missing slaves to the gene pool" "Main">>
		<<for _i = 0; _i < $slaves.length; _i++>>
			<<if $genePool.every(function(g) { return $slaves[_i].ID !== g.ID; })>>
				<<set $genePool.push($slaves[_i])>>
			<</if>>
		<</for>>
	<</link>> //This will not fix missing properties.//
<</if>>