<root>
<document scada='0' projtype='1' schema='103' license='1,79829088,Q2XNNM' title='New Embedded Project' description='A mastermind &apos;solver&apos;

A demonstration of the &apos;pool reduction&apos; and Knuth&apos;s &apos;minimax&apos; algorithms' fcversion='720897' target='ESP.ESP32.ESP32_WROOM_32' >
	<config data='' clkspd='240000000' simspd='5' usewdt='0' constif='0' Use3V3='0' />
	<plugins >
		<dll_models enabled='1' />
	</plugins>
	<supplement use='0' head='' body='' />
	<debug >
		<watch expr='Score.black' />
		<watch expr='Score.g' />
		<watch expr='Score.i' />
		<watch expr='Score.j' />
		<watch expr='Score.t' />
		<watch expr='Score.white' />
		<watch expr='Main.code' />
		<watch expr='Main.guess' />
		<watch expr='Main.score' />
		<watch expr='Main.avail' />
		<watch expr='Solve.start' />
		<watch expr='Solve.end' />
		<watch expr='Solve.guess' />
		<watch expr='Solve.score' />
		<watch expr='Solve.checked' />
		<watch expr='Solve.result' />
		<watch expr='bm' />
	</debug>
	<traces />
	<ghost >
		<FK2 >
			<data name='FK2D0' port='4294967295' pin='4294967295' />
			<data name='FK2D1' port='4294967295' pin='4294967295' />
			<data name='FK2D2' port='4294967295' pin='4294967295' />
			<data name='FK2D3' port='4294967295' pin='4294967295' />
			<data name='FK2D4' port='4294967295' pin='4294967295' />
			<data name='FK2D5' port='4294967295' pin='4294967295' />
			<data name='FK2D6' port='4294967295' pin='4294967295' />
			<data name='FK2D7' port='4294967295' pin='4294967295' />
			<data name='FK2D8' port='4294967295' pin='4294967295' />
			<data name='FK2D9' port='4294967295' pin='4294967295' />
			<data name='FK2D10' port='4294967295' pin='4294967295' />
			<data name='FK2D11' port='4294967295' pin='4294967295' />
			<data name='FK2D12' port='4294967295' pin='4294967295' />
			<data name='FK2D13' port='4294967295' pin='4294967295' />
			<data name='FK2D14' port='4294967295' pin='4294967295' />
			<data name='FK2D15' port='4294967295' pin='4294967295' />
			<data name='FK2A0' port='4294967295' pin='4294967295' />
			<data name='FK2A1' port='4294967295' pin='4294967295' />
			<data name='FK2A2' port='4294967295' pin='4294967295' />
			<data name='FK2A3' port='4294967295' pin='4294967295' />
			<data name='FK2A4' port='4294967295' pin='4294967295' />
			<data name='FK2A5' port='4294967295' pin='4294967295' />
		</FK2>
		<ICD >
			<data name='AnalogPrescaleValue' value='19' />
			<data name='DigitalSampleRate' value='100000' />
			<data name='BreakpointCount' value='8' />
			<data name='CallStackDepthCount' value='8' />
			<data name='ClockPort' value='1' />
			<data name='ClockPin' value='6' />
			<data name='DataPort' value='1' />
			<data name='DataPin' value='7' />
			<data name='UseDefaultPins' value='1' />
			<data name='WrapEnabled' value='1' />
			<data name='CommsDelayOverridden' value='0' />
			<data name='CommsDelay' value='1' />
			<data name='CalculatedCommsDelay' value='1' />
			<data name='AnalogEB2PrescaleValue' value='2' />
			<data name='DigitalEB2SampleRate' value='100000' />
		</ICD>
		<pins >
			<digital A='0' B='0' C='0' D='0' E='0' F='0' G='0' H='0' I='0' J='0' K='0' L='0' M='0' N='0' O='0' P='0' Q='0' R='0' S='0' T='0' U='0' V='0' W='0' X='0' Y='0' Z='0' />
			<analog A='0' B='0' C='0' D='0' E='0' F='0' G='0' H='0' I='0' J='0' K='0' L='0' M='0' N='0' O='0' P='0' Q='0' R='0' S='0' T='0' U='0' V='0' W='0' X='0' Y='0' Z='0' />
		</pins>
	</ghost>
	<components >
		<settings autoimg='0' center='1' unitscale='0' fixedscale='0' fixedx='25' fixedy='25' fixedz='25' headcode='0' />
		<definition guid='093edbe5-7d3f-436d-97a6-8db61feb5c64' vstate='40' vmin='0' vmaj='1' srcleaf='' visiblename='' description='' category='' category2='' category3='' bIs2dOnly='0' bIs3dOnly='0' bIsWysiwyg='0' catenable='1' author='' manuname='' manucode='' sysinfo='0' keywords='' dynamic='1' scadaCompatible='0' embeddedCompatible='1' showmacros='1' iconpath='' />
		<component class_type='root' codename='ComponentRoot' panelId='-1' x='0' y='0' z='0' xsz='1' ysz='1' zsz='1' xang='0' yang='0' zang='0' xquat='0' yquat='0' zquat='0' wquat='1' visible='1' scadavisible='1' interactive='1' solid='1' layer='0' poslock='0' ancTop='0' ancBottom='0' ancLeft='0' ancRight='0' ancMinX='0' ancMinY='0' comp2dType='0' >
			<resources />
			<properties />
			<values />
			<events />
			<apis />
			<variables >
				<variable public='0' >
					<def class_type='variable' name='count' type='u16' description='' isconst='0' isHidden='0' isinit='0' usrinit='0' setinit='' />
				</variable>
				<variable public='0' >
					<def class_type='variable' name='bm' type='u32' description='' isconst='0' isHidden='0' isinit='0' usrinit='0' setinit='' >
						<array size='41' />
					</def>
				</variable>
				<variable public='0' >
					<def class_type='variable' name='false' type='b1' description='' isconst='1' isHidden='0' isinit='1' usrinit='0' setinit='0' />
				</variable>
				<variable public='0' >
					<def class_type='variable' name='bitmap' type='u32' description='' isconst='0' isHidden='0' isinit='1' usrinit='0' setinit='0' />
				</variable>
				<variable public='0' >
					<def class_type='variable' name='colours' type='u32' description='' isconst='0' isHidden='0' isinit='1' usrinit='6' setinit='6' />
				</variable>
				<variable public='0' >
					<def class_type='variable' name='PERMUTATIONS' type='u16' description='' isconst='1' isHidden='0' isinit='1' usrinit='1296' setinit='1296' />
				</variable>
				<variable public='0' >
					<def class_type='variable' name='CHUNK' type='u16' description='' isconst='1' isHidden='0' isinit='1' usrinit='1296' setinit='1296' />
				</variable>
				<variable public='0' >
					<def class_type='variable' name='code_lookup' type='u16' description='lookup table to speed calculation of pegs from indexes' isconst='0' isHidden='0' isinit='0' usrinit='0' setinit='' >
						<array size='1296' />
					</def>
				</variable>
				<variable public='0' >
					<def class_type='variable' name='score_map' type='u8' description='' isconst='0' isHidden='0' isinit='0' usrinit='&quot;&quot;' setinit='' >
						<array size='65' />
					</def>
				</variable>
				<variable public='0' >
					<def class_type='variable' name='true' type='b1' description='' isconst='1' isHidden='0' isinit='1' usrinit='1' setinit='1' />
				</variable>
				<variable public='0' >
					<def class_type='variable' name='pegs' type='u32' description='' isconst='0' isHidden='0' isinit='1' usrinit='4' setinit='4' />
				</variable>
			</variables>
			<macros >
				<macro >
					<flowline name='Show' description='' statediag='0' >
						<return name='Return' type='v0' description='' isconst='0' isHidden='0' isinit='0' usrinit='' setinit='' />
						<param name='board' type='u8' description='' isconst='0' isHidden='0' isinit='0' usrinit='&quot;&quot;' setinit='' >
							<array size='4' />
						</param>
						<param name='msg' type='T8' description='' isconst='0' isHidden='0' isinit='0' usrinit='&quot;&quot;' setinit='' >
							<array size='20' />
						</param>
						<local name='i' type='u32' description='' isconst='0' isHidden='0' isinit='1' usrinit='0' setinit='0' />
						<command class_type='call' title='Component Macro' component='UART1' macro='SendString' >
							<argument exp='.msg' />
						</command>
						<command class_type='loop' title='Loop' type='2' forvar='.i' exp='4' >
							<flowline >
								<command class_type='call' title='Component Macro' component='UART1' macro='SendChar' >
									<argument exp='&apos;\t&apos;' />
								</command>
								<command class_type='call' title='Component Macro' component='UART1' macro='SendNumber' >
									<argument exp='.board[.i]' />
								</command>
							</flowline>
						</command>
						<command class_type='call' title='&quot;' component='UART1' macro='SendString' >
							<argument exp='&quot;\r\n&quot;' />
						</command>
					</flowline>
				</macro>
				<macro >
					<flowline name='MiniMax' description='Calculate minimax values as per Knuth&apos;s algorithm.  Returns best move from 
available moves...' statediag='0' >
						<return name='Return' type='u16' description='' isconst='0' isHidden='0' isinit='0' usrinit='0' setinit='' />
						<local name='guess' type='u32' description='' isconst='0' isHidden='0' isinit='0' usrinit='0' setinit='' />
						<local name='min_score' type='u32' description='' isconst='0' isHidden='0' isinit='1' usrinit='9999' setinit='9999' />
						<local name='best' type='u32' description='' isconst='0' isHidden='0' isinit='1' usrinit='0' setinit='0' />
						<local name='test' type='u32' description='Test each possible combo that hasn&apos;t been cancelled' isconst='0' isHidden='0' isinit='0' usrinit='0' setinit='' />
						<local name='score' type='u32' description='' isconst='0' isHidden='0' isinit='0' usrinit='0' setinit='' />
						<local name='tallies' type='u16' description='Keep a tally of each possible score' isconst='0' isHidden='0' isinit='0' usrinit='0' setinit='' >
							<array size='14' />
						</local>
						<local name='worst_case' type='u32' description='' isconst='0' isHidden='0' isinit='1' usrinit='0' setinit='0' />
						<local name='i' type='u32' description='' isconst='0' isHidden='0' isinit='1' usrinit='0' setinit='0' />
						<local name='opening_moves' type='u16' description='' isconst='1' isHidden='0' isinit='1' usrinit='0' setinit='{7, 266, 525, 784, 1043, 1260}' >
							<array size='6' />
						</local>
						<command class_type='decision' title='Decision' exp='count = PERMUTATIONS' swap='0' >
							<flowline >
								<command class_type='calculation' title='Calculation' >
									<exp exp='.best = .opening_moves[Random() % 6]' />
								</command>
							</flowline>
							<flowline >
								<command class_type='loop' title='For every possible guess ' type='2' forvar='.guess' exp='PERMUTATIONS' >
									<flowline >
										<command class_type='calculation' title='Calculation' >
											<exp exp='.worst_case = 0' />
										</command>
										<command class_type='loop' title='Loop' type='2' forvar='.i' exp='14' >
											<flowline >
												<command class_type='calculation' title='Calculation' >
													<exp exp='.tallies[.i] = 0' />
												</command>
											</flowline>
										</command>
										<command class_type='loop' title='Loop' type='2' forvar='.test' exp='PERMUTATIONS' >
											<flowline >
												<command class_type='decision' title='Decision' exp='GetBit(bitmap,.test)' swap='0' >
													<flowline >
														<command class_type='call' title='User Macro' macro='Score' >
															<return exp='.score' />
															<argument exp='.guess' />
															<argument exp='.test' />
														</command>
														<command class_type='calculation' title='Calculation' >
															<exp exp='.tallies[score_map[.score]] = .tallies[score_map[.score]] + 1' />
														</command>
													</flowline>
													<flowline />
												</command>
											</flowline>
										</command>
										<command class_type='loop' title='Loop' type='2' forvar='.i' exp='14' >
											<flowline >
												<command class_type='decision' title='Decision' exp='.tallies[.i] &gt; .worst_case' swap='0' >
													<flowline >
														<command class_type='calculation' title='Calculation' >
															<exp exp='.worst_case = .tallies[.i]' />
														</command>
													</flowline>
													<flowline />
												</command>
											</flowline>
										</command>
										<command class_type='decision' title='Is the current worst case better than current best?' exp='.worst_case &lt; .min_score' swap='0' >
											<flowline >
												<command class_type='calculation' title='Calculation' >
													<exp exp='.min_score = .worst_case' />
													<exp exp='.best = .guess' />
												</command>
											</flowline>
											<flowline >
												<command class_type='decision' title='Knuth&apos;s tie-breaker for  eaqual scores - prefer a possible play' exp='.worst_case == .min_score' swap='0' >
													<flowline >
														<command class_type='decision' title='Decision' exp='GetBit(bitmap,.guess) &amp;&amp; !GetBit(bitmap,.best)' swap='0' >
															<flowline >
																<command class_type='calculation' title='Calculation' >
																	<exp exp='.best = .guess' />
																</command>
															</flowline>
															<flowline />
														</command>
													</flowline>
													<flowline />
												</command>
											</flowline>
										</command>
									</flowline>
								</command>
							</flowline>
						</command>
						<command class_type='calculation' title='Calculation' >
							<exp exp='.Return = .best' />
						</command>
					</flowline>
				</macro>
				<macro >
					<flowline name='ShowCode' description='' statediag='0' >
						<return name='Return' type='v0' description='' isconst='0' isHidden='0' isinit='0' usrinit='' setinit='' />
						<param name='msg' type='T8' description='' isconst='0' isHidden='0' isinit='0' usrinit='&quot;&quot;' setinit='' >
							<array size='20' />
						</param>
						<param name='index' type='u32' description='Display a colour code - using it&apos;s index (0..perms - 1)' isconst='0' isHidden='0' isinit='0' usrinit='0' setinit='' />
						<local name='i' type='u32' description='' isconst='0' isHidden='0' isinit='0' usrinit='0' setinit='' />
						<local name='col' type='u32' description='' isconst='0' isHidden='0' isinit='1' usrinit='0' setinit='0' />
						<command class_type='call' title='Component Macro' component='UART1' macro='SendString' >
							<argument exp='&quot;\x1b[40m&quot;' />
						</command>
						<command class_type='call' title='Component Macro' component='UART1' macro='SendString' >
							<argument exp='.msg' />
						</command>
						<command class_type='call' title='Component Macro' component='UART1' macro='SendChar' >
							<argument exp='&apos; &apos;' />
						</command>
						<command class_type='calculation' title='Calculation' >
							<exp exp='.index = code_lookup[.index]' />
						</command>
						<command class_type='loop' title='Loop' type='2' forvar='.i' exp='pegs' >
							<flowline >
								<command class_type='calculation' title='Calculation' >
									<exp exp='.col = .index &amp; 0x0f' />
									<exp exp='.index = .index &gt;&gt; 4' />
								</command>
								<command class_type='call' title='Component Macro' component='UART1' macro='SendString' >
									<argument exp='&quot;\x1B[&quot;' />
								</command>
								<command class_type='call' title='Component Macro' component='UART1' macro='SendNumber' >
									<argument exp='40+.col' />
								</command>
								<command class_type='call' title='&quot;' component='UART1' macro='SendString' >
									<argument exp='&quot;m  &quot;' />
								</command>
							</flowline>
						</command>
						<command class_type='call' title='Component Macro' component='UART1' macro='SendString' >
							<argument exp='&quot;\x1b[40m&quot;' />
						</command>
					</flowline>
				</macro>
				<macro >
					<flowline name='SetBitMap' description='' statediag='0' >
						<return name='Return' type='v0' description='' isconst='0' isHidden='0' isinit='0' usrinit='' setinit='' />
						<param name='bitmap' type='u32' description='' isconst='0' isHidden='0' isinit='0' usrinit='0' setinit='' />
						<param name='size' type='u32' description='' isconst='0' isHidden='0' isinit='0' usrinit='0' setinit='' />
						<param name='value' type='u32' description='' isconst='0' isHidden='0' isinit='0' usrinit='0' setinit='' />
						<command class_type='native' title='Code' ccode='  MX_UINT32 *ptr = (MX_UINT32*)FCL_BITMAP;
  for(int i = 0; i &lt; FCL_SIZE / 32 + 1; i++) ptr[i] = FCL_VALUE;' language='C' />
						<command class_type='calculation' title='Calculation' >
							<exp exp='count = 1296' />
						</command>
					</flowline>
				</macro>
				<macro >
					<flowline name='GetGuess' description='Get a &apos;random&apos; play from available pool' statediag='0' >
						<return name='Return' type='u16' description='' isconst='0' isHidden='0' isinit='0' usrinit='0' setinit='' />
						<local name='i' type='s16' description='' isconst='0' isHidden='0' isinit='1' usrinit='-1' setinit='-1' />
						<local name='avail' type='b1' description='' isconst='0' isHidden='0' isinit='0' usrinit='0' setinit='' />
						<local name='n' type='u32' description='' isconst='0' isHidden='0' isinit='0' usrinit='0' setinit='' />
						<command class_type='calculation' title='Calculation' >
							<exp exp='.n = Random() % count + 1' />
						</command>
						<command class_type='loop' title='Loop' type='0' exp='.n' >
							<flowline >
								<command class_type='calculation' title='Calculation' >
									<exp exp='.i = (.i + 1) % PERMUTATIONS' />
								</command>
								<command class_type='call' title='User Macro' macro='GetBit' >
									<return exp='.avail' />
									<argument exp='bitmap' />
									<argument exp='.i' />
								</command>
								<command class_type='decision' title='Decision' exp='.avail' swap='0' >
									<flowline >
										<command class_type='calculation' title='Calculation' >
											<exp exp='.n = .n - 1' />
										</command>
									</flowline>
									<flowline />
								</command>
							</flowline>
						</command>
						<command class_type='calculation' title='Calculation' >
							<exp exp='.Return = .i' />
						</command>
					</flowline>
				</macro>
				<macro >
					<flowline name='Score' description='' statediag='0' >
						<return name='Return' type='u8' description='' isconst='0' isHidden='0' isinit='0' usrinit='0' setinit='' />
						<param name='guess' type='u32' description='' isconst='0' isHidden='0' isinit='0' usrinit='0' setinit='' />
						<param name='target' type='u32' description='' isconst='0' isHidden='0' isinit='0' usrinit='0' setinit='' />
						<local name='i' type='u32' description='' isconst='0' isHidden='0' isinit='0' usrinit='0' setinit='' />
						<local name='black' type='u32' description='' isconst='0' isHidden='0' isinit='1' usrinit='0' setinit='0' />
						<local name='white' type='u32' description='' isconst='0' isHidden='0' isinit='1' usrinit='0' setinit='0' />
						<local name='g' type='u8' description='' isconst='0' isHidden='0' isinit='0' usrinit='&quot;&quot;' setinit='' >
							<array size='8' />
						</local>
						<local name='t' type='u8' description='' isconst='0' isHidden='0' isinit='0' usrinit='&quot;&quot;' setinit='' >
							<array size='8' />
						</local>
						<local name='p' type='u8' description='' isconst='0' isHidden='0' isinit='1' usrinit='0' setinit='0' />
						<local name='j' type='u8' description='' isconst='0' isHidden='0' isinit='1' usrinit='0' setinit='0' />
						<local name='temp' type='u32' description='' isconst='0' isHidden='0' isinit='1' usrinit='0' setinit='0' />
						<local name='tt' type='u16' description='' isconst='0' isHidden='0' isinit='1' usrinit='0' setinit='0' />
						<local name='gt' type='u16' description='' isconst='0' isHidden='0' isinit='1' usrinit='0' setinit='0' />
						<command class_type='calculation' title='Calculation' >
							<exp exp='.temp = .guess' />
							<exp exp='.gt = code_lookup[.guess]' />
							<exp exp='.tt = code_lookup[.target]' />
						</command>
						<command class_type='loop' title='Extract the colors at each position' type='2' forvar='.i' exp='pegs' >
							<flowline >
								<command class_type='calculation' title='Calculation' >
									<exp exp='.t[.i] = .tt &amp; 0x0f' />
									<exp exp='.tt = .tt &gt;&gt; 4' />
									<exp exp='' />
									<exp exp='.g[.i] = .gt &amp; 0x0f' />
									<exp exp='.gt = .gt &gt;&gt; 4' />
								</command>
								<command class_type='decision' title='If matching increase black count' exp='.t[.i] == .g[.i]' swap='0' >
									<flowline >
										<command class_type='calculation' title='Match - mark as used and inc black count' >
											<exp exp='.t[.i] = 0' />
											<exp exp='.g[.i] = 0' />
											<exp exp='.black = .black + 1' />
										</command>
									</flowline>
									<flowline />
								</command>
							</flowline>
						</command>
						<command class_type='loop' title='White count (right colour wrong position)' type='2' forvar='.i' exp='pegs' >
							<flowline >
								<command class_type='calculation' title='Calculation' >
									<exp exp='.p = .g[.i]' />
								</command>
								<command class_type='decision' title='Check it&apos;s a valid peg' exp='.p' swap='0' >
									<flowline >
										<command class_type='calculation' title='Calculation' >
											<exp exp='.j = 0' />
										</command>
										<command class_type='loop' title='Loop' type='2' forvar='.j' exp='pegs' >
											<flowline >
												<command class_type='decision' title='Decision' exp='.p = .t[.j]' swap='0' >
													<flowline >
														<command class_type='calculation' title='Calculation' >
															<exp exp='.white = .white + 1' />
															<exp exp='.t[.j] = 0 // Mark peg as used' />
															<exp exp='.j = pegs // Match just adds 1 to white count' />
														</command>
													</flowline>
													<flowline />
												</command>
											</flowline>
										</command>
									</flowline>
									<flowline />
								</command>
							</flowline>
						</command>
						<command class_type='calculation' title='Calculation' >
							<exp exp='.Return = (.black &lt;&lt; 4) + .white' />
						</command>
					</flowline>
				</macro>
				<macro >
					<flowline name='Mark' description='' statediag='0' >
						<return name='Return' type='v0' description='' isconst='0' isHidden='0' isinit='0' usrinit='' setinit='' />
						<param name='start' type='u16' description='Index of first test patter to check (to allow &apos;slicing&apos; on Arduino)' isconst='0' isHidden='0' isinit='0' usrinit='0' setinit='' />
						<param name='end' type='u16' description='Index of first test patter to check (to allow &apos;slicing&apos; on Arduino)' isconst='0' isHidden='0' isinit='0' usrinit='0' setinit='' />
						<param name='guess' type='u16' description='' isconst='0' isHidden='0' isinit='0' usrinit='0' setinit='' />
						<param name='score' type='u16' description='' isconst='0' isHidden='0' isinit='0' usrinit='0' setinit='' />
						<local name='checked' type='b1' description='' isconst='0' isHidden='0' isinit='0' usrinit='0' setinit='' />
						<local name='result' type='u16' description='' isconst='0' isHidden='0' isinit='0' usrinit='0' setinit='' />
						<command class_type='loop' title='Mark a &apos;chunk&apos; of values (to allow Arduinoification)' type='0' exp='.start &lt; .end' >
							<flowline >
								<command class_type='call' title='User Macro' macro='GetBit' >
									<return exp='.checked' />
									<argument exp='bitmap' />
									<argument exp='.start' />
								</command>
								<command class_type='decision' title='Decision' exp='.checked' swap='0' >
									<flowline >
										<command class_type='call' title='Does the current guess and the previous guess give the same scor' macro='Score' >
											<return exp='.result' />
											<argument exp='.start' />
											<argument exp='.guess' />
										</command>
										<command class_type='decision' title='Decision' exp='.score != .result' swap='0' >
											<flowline >
												<command class_type='call' title='User Macro' macro='SetBit' >
													<argument exp='bitmap' />
													<argument exp='.start' />
													<argument exp='false' />
												</command>
												<command class_type='calculation' title='Decrease pool size' >
													<exp exp='count -= 1' />
												</command>
											</flowline>
											<flowline />
										</command>
									</flowline>
									<flowline />
								</command>
								<command class_type='calculation' title='Calculation' >
									<exp exp='.start = .start + 1' />
								</command>
							</flowline>
						</command>
					</flowline>
				</macro>
				<macro >
					<flowline name='SetBit' description='' statediag='0' >
						<return name='Return' type='v0' description='' isconst='0' isHidden='0' isinit='0' usrinit='' setinit='' />
						<param name='map' type='u32' description='' isconst='0' isHidden='0' isinit='0' usrinit='0' setinit='' />
						<param name='bit' type='u32' description='' isconst='0' isHidden='0' isinit='0' usrinit='0' setinit='' />
						<param name='set' type='b1' description='' isconst='0' isHidden='0' isinit='0' usrinit='0' setinit='' />
						<command class_type='native' title='Code' ccode='  MX_UINT32 *ptr = (MX_UINT32*)FCL_MAP;
  if(FCL_SET) {
    ptr[FCL_BIT / 32] |= 1UL &lt;&lt; (FCL_BIT % 32);
  } else {
    ptr[FCL_BIT / 32] &amp;= ~(1UL &lt;&lt; (FCL_BIT % 32));
  }' language='C' />
						<command class_type='decision' title='Decision' disable='1' exp='.set' swap='0' >
							<flowline >
								<command class_type='calculation' title='Calculation' >
									<exp exp='bm[.bit / 32] = bm[.bit / 32] | (1 &lt;&lt; (.bit % 32))' />
								</command>
							</flowline>
							<flowline >
								<command class_type='calculation' title='Calculation' disable='1' >
									<exp exp='bm[.bit / 32] = bm[.bit / 32] &amp; (~(1 &lt;&lt; (.bit % 32)))' />
								</command>
							</flowline>
						</command>
					</flowline>
				</macro>
				<macro >
					<flowline name='Game' description='Plays a game of Mastermind - solves a secret code using
either Pool Reduction or Minimax algorithms' statediag='0' >
						<return name='Return' type='v0' description='' isconst='0' isHidden='0' isinit='0' usrinit='' setinit='' />
						<param name='secret' type='u16' description='' isconst='0' isHidden='0' isinit='0' usrinit='0' setinit='' />
						<param name='minimax' type='b1' description='Set to true to use minimax algorithm' isconst='0' isHidden='0' isinit='0' usrinit='0' setinit='' />
						<local name='turns' type='u8' description='' isconst='0' isHidden='0' isinit='1' usrinit='0' setinit='0' />
						<local name='score' type='u8' description='' isconst='0' isHidden='0' isinit='0' usrinit='0' setinit='' />
						<local name='guess' type='u16' description='' isconst='0' isHidden='0' isinit='0' usrinit='0' setinit='' />
						<local name='start' type='u16' description='' isconst='0' isHidden='0' isinit='0' usrinit='0' setinit='' />
						<local name='remain' type='u16' description='' isconst='0' isHidden='0' isinit='0' usrinit='0' setinit='' />
						<local name='n' type='u16' description='' isconst='0' isHidden='0' isinit='1' usrinit='0' setinit='0' />
						<command class_type='call' title='Set all codes as available' macro='SetBitMap' >
							<argument exp='bitmap' />
							<argument exp='PERMUTATIONS' />
							<argument exp='-1' />
						</command>
						<command class_type='calculation' title='Generate a random code' >
							<exp exp='.turns = 1' />
						</command>
						<command class_type='decision' title='Decision' exp='.minimax' swap='0' >
							<flowline >
								<command class_type='call' title='User Macro' macro='ShowCode' >
									<argument exp='&quot;\r\nKnuth&apos;s minimax&quot;' />
									<argument exp='.secret' />
								</command>
							</flowline>
							<flowline >
								<command class_type='call' title='User Macro' macro='ShowCode' >
									<argument exp='&quot;\r\nPool reduction &quot;' />
									<argument exp='.secret' />
								</command>
							</flowline>
						</command>
						<command class_type='loop' title='Keep playing until solved' type='1' exp='.score = 4 &lt;&lt; 4' start='0' >
							<flowline >
								<command class_type='decision' title='Decision' exp='.minimax' swap='0' >
									<flowline >
										<command class_type='call' title='User Macro' macro='MiniMax' >
											<return exp='.guess' />
										</command>
									</flowline>
									<flowline >
										<command class_type='call' title='User Macro' macro='GetGuess' >
											<return exp='.guess' />
										</command>
									</flowline>
								</command>
								<command class_type='call' title='User Macro' macro='ShowCode' >
									<argument exp='&quot; guess&quot;' />
									<argument exp='.guess' />
								</command>
								<command class_type='call' title='User Macro' macro='Score' >
									<return exp='.score' />
									<argument exp='.guess' />
									<argument exp='.secret' />
								</command>
								<command class_type='decision' title='Decision' exp='.score != 4 &lt;&lt; 4' swap='0' >
									<flowline >
										<command class_type='calculation' title='Calculation' >
											<exp exp='.remain = PERMUTATIONS' />
											<exp exp='.start = 0' />
											<exp exp='.turns = .turns + 1' />
										</command>
										<command class_type='loop' title='Loop' type='0' exp='.remain &gt; 0' >
											<flowline >
												<command class_type='decision' title='Decision' exp='.remain &gt; CHUNK' swap='0' >
													<flowline >
														<command class_type='calculation' title='Calculation' >
															<exp exp='.n = CHUNK' />
														</command>
													</flowline>
													<flowline >
														<command class_type='calculation' title='Calculation' >
															<exp exp='.n = .remain' />
														</command>
													</flowline>
												</command>
												<command class_type='call' title='User Macro' macro='Mark' >
													<argument exp='.start' />
													<argument exp='.start + .n' />
													<argument exp='.guess' />
													<argument exp='.score' />
												</command>
												<command class_type='calculation' title='Calculation' >
													<exp exp='.remain = .remain - .n' />
													<exp exp='.start = .start + .n' />
												</command>
											</flowline>
										</command>
									</flowline>
									<flowline />
								</command>
							</flowline>
						</command>
						<command class_type='call' title='Component Macro' component='UART1' macro='SendString' >
							<argument exp='&quot; matches in &quot;' />
						</command>
						<command class_type='call' title='Component Macro' component='UART1' macro='SendNumber' >
							<argument exp='.turns' />
						</command>
						<command class_type='call' title='Component Macro' component='UART1' macro='SendString' >
							<argument exp='&quot;\r\n&quot;' />
						</command>
					</flowline>
				</macro>
				<macro >
					<flowline name='DeleteBitMap' description='' statediag='0' >
						<return name='Return' type='v0' description='' isconst='0' isHidden='0' isinit='0' usrinit='' setinit='' />
						<param name='map' type='u32' description='' isconst='0' isHidden='0' isinit='0' usrinit='0' setinit='' />
						<command class_type='decision' title='Decision' exp='.map' swap='0' >
							<flowline >
								<command class_type='native' title='Code' ccode='    free(FCL_MAP);' language='C' />
							</flowline>
							<flowline />
						</command>
					</flowline>
				</macro>
				<macro >
					<flowline name='ClearBitMap' description='' statediag='0' >
						<return name='Return' type='v0' description='' isconst='0' isHidden='0' isinit='0' usrinit='' setinit='' />
						<param name='bitmap' type='u32' description='' isconst='0' isHidden='0' isinit='0' usrinit='0' setinit='' />
						<param name='count' type='u32' description='' isconst='0' isHidden='0' isinit='0' usrinit='0' setinit='' />
						<command class_type='native' title='Code' ccode='  MX_UINT32 *ptr = (MX_UINT32*)FCL_BITMAP;
  for(int i = 0; i &lt; FCL_COUNT / 32 + 1; i++) ptr[i] = 0;' language='C' />
					</flowline>
				</macro>
				<macro >
					<flowline name='GetBit' description='' statediag='0' >
						<return name='Return' type='b1' description='' isconst='0' isHidden='0' isinit='0' usrinit='0' setinit='' />
						<param name='map' type='u32' description='' isconst='0' isHidden='0' isinit='0' usrinit='0' setinit='' />
						<param name='bit' type='u32' description='' isconst='0' isHidden='0' isinit='0' usrinit='0' setinit='' />
						<command class_type='native' title='Code' ccode='  MX_UINT32 *ptr = (MX_UINT32*)FCL_MAP;
  FCR_RETVAL = (ptr[FCL_BIT / 32] &amp; (1UL &lt;&lt; (FCL_BIT % 32))) != 0;
' language='C' />
						<command class_type='calculation' title='Calculation' disable='1' >
							<exp exp='.Return = (bm[.bit / 32] &amp; (1 &lt;&lt; .bit % 32)) != 0' />
						</command>
					</flowline>
				</macro>
				<macro >
					<flowline name='Main' description='' statediag='0' >
						<return name='Return' type='v0' description='' isconst='0' isHidden='0' isinit='0' usrinit='' setinit='' />
						<local name='code' type='u16' description='' isconst='0' isHidden='0' isinit='1' usrinit='0' setinit='0' />
						<command class_type='call' title='User Macro' macro='Initialise' />
						<command class_type='loop' title='Loop' type='3' exp='1' >
							<flowline >
								<command class_type='calculation' title='Calculation' >
									<exp exp='.code = Random() % PERMUTATIONS' />
								</command>
								<command class_type='call' title='User Macro' macro='Game' >
									<argument exp='true' />
									<argument exp='.code' />
								</command>
								<command class_type='call' title='User Macro' macro='Game' >
									<argument exp='false' />
									<argument exp='.code' />
								</command>
								<command class_type='call' title='Component Macro' component='UART1' macro='SendString' >
									<argument exp='&quot;\r\n&quot;' />
								</command>
								<command class_type='delay' title='Delay' exp='10' type='1' />
							</flowline>
						</command>
					</flowline>
				</macro>
				<macro >
					<flowline name='CreateBitMap' description='Creates a bitmap with n bits.  These can be accessed using the SetBit and GetBit macros.
When (if) the bitmap is no longer required then it can be deleted with DeleteBitMap' statediag='0' >
						<return name='Return' type='u32' description='' isconst='0' isHidden='0' isinit='0' usrinit='0' setinit='' />
						<param name='n' type='u32' description='Number of bits to map' isconst='0' isHidden='0' isinit='0' usrinit='0' setinit='' />
						<local name='sz' type='u32' description='' isconst='0' isHidden='0' isinit='1' usrinit='0' setinit='0' />
						<local name='addr' type='u32' description='' isconst='0' isHidden='0' isinit='0' usrinit='0' setinit='' />
						<local name='i' type='u32' description='' isconst='0' isHidden='0' isinit='1' usrinit='0' setinit='0' />
						<command class_type='calculation' title='number of long words required' >
							<exp exp='.sz = .n / 32 + 1' />
						</command>
						<command class_type='native' title='Code' ccode='  FCL_ADDR = calloc(FCL_SZ, sizeof(MX_UINT32));' language='C' />
						<command class_type='calculation' title='Calculation' >
							<exp exp='.Return = .addr' />
						</command>
						<command class_type='loop' title='Loop' disable='1' type='2' forvar='.i' exp='41' >
							<flowline >
								<command class_type='calculation' title='Calculation' disable='1' >
									<exp exp='bm[.i] = 0' />
								</command>
							</flowline>
						</command>
						<command class_type='calculation' title='Calculation' disable='1' >
							<exp exp='.Return = 0' />
						</command>
					</flowline>
				</macro>
				<macro >
					<flowline name='Initialise' description='' statediag='0' >
						<return name='Return' type='v0' description='' isconst='0' isHidden='0' isinit='0' usrinit='' setinit='' />
						<local name='i' type='u32' description='' isconst='0' isHidden='0' isinit='0' usrinit='0' setinit='' />
						<local name='peg' type='u32' description='' isconst='0' isHidden='0' isinit='0' usrinit='0' setinit='' />
						<local name='code' type='u16' description='' isconst='0' isHidden='0' isinit='1' usrinit='0' setinit='0' />
						<local name='temp' type='u16' description='' isconst='0' isHidden='0' isinit='0' usrinit='0' setinit='' />
						<command class_type='call' title='User Macro' macro='CreateBitMap' >
							<return exp='bitmap' />
							<argument exp='PERMUTATIONS' />
						</command>
						<command class_type='call' title='Component Macro' component='UART1' macro='Initialise' />
						<command class_type='calculation' title='Possible score map to 14 possible minimax tallies' >
							<exp exp='score_map[0] = 0 // No score' />
							<exp exp='score_map[1] = 1 // 1 white' />
							<exp exp='score_map[2] = 2 // 2 white' />
							<exp exp='score_map[3] = 3' />
							<exp exp='score_map[4] = 4' />
							<exp exp='score_map[0x10] = 5 // 1 black' />
							<exp exp='score_map[0x11] = 6 // 1 black 1 white' />
							<exp exp='score_map[0x12] = 7' />
							<exp exp='score_map[0x13] = 8' />
							<exp exp='score_map[0x20] = 9 // 2 black' />
							<exp exp='score_map[0x21] = 10' />
							<exp exp='score_map[0x22] = 11' />
							<exp exp='score_map[0x30] = 12' />
							<exp exp='score_map[0x40] = 13' />
						</command>
						<command class_type='loop' title='Create a lookup of all the colour layouts - quicker than % and /' type='2' forvar='.i' exp='Permutations' >
							<flowline >
								<command class_type='calculation' title='Calculation' >
									<exp exp='.code = .i' />
									<exp exp='.temp = 0' />
								</command>
								<command class_type='loop' title='Loop' type='2' forvar='.peg' exp='pegs' >
									<flowline >
										<command class_type='calculation' title='Calculation' >
											<exp exp='.temp = (.temp &gt;&gt; 4) | ((.code % 6 + 1) &lt;&lt; 12)' />
											<exp exp='.code = .code / 6' />
										</command>
									</flowline>
								</command>
								<command class_type='calculation' title='Calculation' >
									<exp exp='code_lookup[.i] = .temp' />
								</command>
							</flowline>
						</command>
					</flowline>
				</macro>
			</macros>
			<component class_type='ref' guid='c73616d1-7ad0-45d9-aada-69ccfa4c5efc' vmin='0' vmaj='3' codename='UART1' panelId='0' x='123' y='-124' z='0' xsz='25.1778' ysz='25.1392' zsz='25' xang='0' yang='0' zang='0' xquat='0' yquat='0' zquat='0' wquat='1' visible='1' scadavisible='1' interactive='1' solid='1' layer='2' poslock='1' ancTop='0' ancBottom='0' ancLeft='0' ancRight='0' ancMinX='0' ancMinY='0' comp2dType='0' >
				<resources />
				<properties />
				<values >
					<value target='cal_uart::CHANNEL' data='001' />
					<value target='cal_uart::BAUD_LIST' data='009' />
					<value target='cal_uart::BAUD' data='115200' />
					<value target='cal_uart::DBITS' data='008' />
					<value target='cal_uart::RETURN' data='001' />
					<value target='cal_uart::ECHO' data='000' />
					<value target='cal_uart::UseTX' data='1' />
					<value target='cal_uart::TX' data='$PORTA.1' />
					<value target='cal_uart::OutputPins' data='000' />
					<value target='cal_uart::TXAlt' data='0' />
					<value target='cal_uart::UseRX' data='1' />
					<value target='cal_uart::RX' data='$PORTA.3' />
					<value target='cal_uart::InputPins' data='001' />
					<value target='cal_uart::RXAlt' data='0' />
					<value target='cal_uart::FLOWEN' data='000' />
					<value target='cal_uart::RTS' data='$PORTB.2' />
					<value target='cal_uart::CTS' data='$PORTB.1' />
					<value target='label' data='UART' />
					<value target='cal_uart::ScopeTraces' data='0' />
					<value target='cal_uart::ConsoleData' data='1' />
					<value target='cal_uart::ConsoleFormat' data='000' />
					<value target='cal_uart::ConsoleColumns' data='64' />
					<value target='cal_uart::DataSource' data='000' />
					<value target='cal_uart::com_port' data='000' />
					<value target='cal_uart::Injector' data='000' />
					<value target='cal_uart::APIUseDDR' data='' />
					<value target='cal_uart::APIDDRPin' data='' />
					<value target='cal_uart::APIDDRRXState' data='' />
					<value target='cal_uart::APIUseFC' data='' />
					<value target='cal_uart::APICTSPin' data='' />
					<value target='cal_uart::APIRTSPin' data='' />
				</values>
				<events />
				<apis />
				<variables />
				<macros />
			</component>
		</component>
	</components>
	<scadaresourcelookup />
	<keymap />
	<panel2d shadows='0' lighting='2' brightness='0' >
		<background rgb='7292207' img='' style='0' />
		<camera xe='0' ye='0' ze='623.424' xt='0' yt='0' zt='0' xquat='0' yquat='0' zquat='0' wquat='1' />
		<viewport dx='267' dy='1556' zoom='51.8219' fix_topleft='0' />
		<page x='1000' y='1000' show='0' rgb='7360576' />
		<winpos ID='7005' RectRecentFloat='794,303,1280,720' RectRecentDocked='0,0,267,1606' RecentFrameAlignment='16384' RecentRowIndex='0' IsFloating='0' MRUWidth='32767' PinState='0' IsMaximized='0' IsVisible='0' />
	</panel2d>
	<panel3d shadows='0' lighting='2' brightness='0' perspective='1' >
		<background rgb='8409120' img='' style='0' />
		<table rgb='7360576' img='' style='0' size='0' />
		<camera xe='0' ye='0' ze='781.66' xt='0' yt='0' zt='0' xquat='0' yquat='0' zquat='0' wquat='1' />
		<camerakey0 xe='0' ye='0' ze='300' xt='0' yt='0' zt='0' xquat='0' yquat='0' zquat='0' wquat='1' />
		<camerakey1 xe='-3.67394e-14' ye='0' ze='-300' xt='0' yt='0' zt='0' xquat='0' yquat='1' zquat='0' wquat='6.12323e-17' />
		<camerakey2 xe='0' ye='-300' ze='6.66134e-14' xt='0' yt='0' zt='0' xquat='-0.707107' yquat='0' zquat='0' wquat='0.707107' />
		<camerakey3 xe='-3.67394e-14' ye='300' ze='6.66134e-14' xt='0' yt='0' zt='0' xquat='-4.32978e-17' yquat='0.707107' zquat='0.707107' wquat='4.32978e-17' />
		<camerakey4 xe='-300' ye='-6.66134e-14' ze='6.66134e-14' xt='0' yt='0' zt='0' xquat='-0.5' yquat='0.5' zquat='0.5' wquat='0.5' />
		<camerakey5 xe='300' ye='-6.66134e-14' ze='6.66134e-14' xt='0' yt='0' zt='0' xquat='-0.5' yquat='-0.5' zquat='-0.5' wquat='0.5' />
		<camerakey6 xe='-173.205' ye='-173.205' ze='173.205' xt='0' yt='0' zt='0' xquat='-0.424708' yquat='0.17592' zquat='0.339851' wquat='0.820473' />
		<winpos ID='7004' RectRecentFloat='0,143,654,720' RectRecentDocked='0,0,469,1690' RecentFrameAlignment='16384' RecentRowIndex='0' IsFloating='0' MRUWidth='32767' PinState='0' IsMaximized='0' IsVisible='0' />
	</panel3d>
	<panels2d count='1' >
		<panel2d_0 id='0' name='2D Panel' type='0' >
			<winpos ID='1171' RectRecentFloat='455,251,1105,701' RectRecentDocked='2735,328,3377,2018' RecentFrameAlignment='16384' RecentRowIndex='0' IsFloating='1' MRUWidth='32767' PinState='0' IsMaximized='0' IsVisible='0' />
			<background fill='288230376151053813' showgrid='1' gridstyle='1' gridsize='10' gridbrush='71776119075691740' snaptogrid='1' fitcomp='0' disp_x='300' disp_y='400' scale='100' disp_col='16777215' />
		</panel2d_0>
	</panels2d>
	<layout >
		<view type='0' name='CreateBitMap' mode='0' placement='LAAAAAAAAAABAAAA---------------------wUAAAAzAAAAcgoAAJUGAAA' zoom='170' scrollx='0' scrolly='0' flags='0' />
		<view type='0' name='DeleteBitMap' mode='0' placement='LAAAAAAAAAABAAAA---------------------wUAAAAzAAAAcgoAAJUGAAA' zoom='130' scrollx='0' scrolly='0' flags='0' />
		<view type='0' name='SetBit' mode='0' placement='LAAAAAAAAAABAAAA---------------------wUAAAAzAAAAcgoAAJUGAAA' zoom='170' scrollx='0' scrolly='0' flags='0' />
		<view type='0' name='GetBit' mode='0' placement='LAAAAAAAAAABAAAA---------------------wUAAAAzAAAAcgoAAJUGAAA' zoom='135' scrollx='0' scrolly='0' flags='0' />
		<view type='0' name='Score' mode='0' placement='LAAAAAAAAAABAAAA---------------------wUAAAAzAAAAcgoAAJUGAAA' zoom='220' scrollx='0' scrolly='1812' flags='0' />
		<view type='0' name='Mark' mode='0' placement='LAAAAAAAAAABAAAA---------------------wUAAAAzAAAAcgoAAJUGAAA' zoom='260' scrollx='0' scrolly='552' flags='0' />
		<view type='0' name='Show' mode='0' placement='LAAAAAAAAAABAAAA---------------------wUAAAAzAAAAcgoAAJUGAAA' zoom='135' scrollx='0' scrolly='0' flags='0' />
		<view type='0' name='ClearBitMap' mode='0' placement='LAAAAAAAAAABAAAA---------------------wUAAAAzAAAAcgoAAJUGAAA' zoom='150' scrollx='0' scrolly='0' flags='0' />
		<view type='0' name='ShowCode' mode='0' placement='LAAAAAAAAAABAAAA---------------------wUAAAAzAAAAcgoAAJUGAAA' zoom='150' scrollx='0' scrolly='0' flags='0' />
		<view type='0' name='Initialise' mode='0' placement='LAAAAAAAAAABAAAA---------------------wUAAAAzAAAAcgoAAJUGAAA' zoom='170' scrollx='0' scrolly='0' flags='0' />
		<view type='0' name='MiniMax' mode='0' placement='LAAAAAAAAAABAAAA---------------------wUAAAAzAAAAcgoAAJUGAAA' zoom='260' scrollx='7' scrolly='0' flags='0' />
		<view type='0' name='SetBitMap' mode='0' placement='LAAAAAAAAAABAAAA---------------------wUAAAAzAAAAcgoAAJUGAAA' zoom='135' scrollx='0' scrolly='0' flags='0' />
		<view type='0' name='Game' mode='0' placement='LAAAAAAAAAABAAAA---------------------wUAAAAzAAAAcgoAAJUGAAA' zoom='260' scrollx='0' scrolly='0' flags='0' />
		<view type='0' name='GetGuess' mode='0' placement='LAAAAAAAAAABAAAA---------------------wUAAAAzAAAAcgoAAJUGAAA' zoom='200' scrollx='0' scrolly='0' flags='0' />
		<view type='0' name='Main' mode='0' placement='LAAAAAAAAAABAAAA---------------------wUAAAAzAAAAcgoAAJUGAAA' zoom='180' scrollx='0' scrolly='0' flags='0' />
	</layout>
</document>
</root>
