User File #11335776409434011

Upload All User Files

#11335776409434011 - Q-bert Lua Bot (works)

Q-Bert_Bot.lua
Game: Q*bert ( NES, see all files )
885 downloads
Uploaded 12/15/2013 11:47 AM by TASeditor (see all 188)
Hooray, the Bot works, but the script is ugly as fuck.
I tested it on the first level (enemies were disabled) and it found the fastest strat in 35 attempts, which took 5 minutes.
The bot still doesn't find the fastest with enemies enabled.
I still want to have a window where I can type the needed color and the fastest attempt of a level, without changing the script everytime.

NeededColor = 26;
BlocksColor = {};
LivesMem = Lives;
Pos = 0;
i = 0;
n = 0;
FastestAttempt = 2000;
Attempts = 1;

while (true) do

BlocksColor[0] = memory.read_u8(0x15);
BlocksColor[1] = memory.read_u8(0x34);
BlocksColor[2] = memory.read_u8(0x36);
BlocksColor[3] = memory.read_u8(0x53);
BlocksColor[4] = memory.read_u8(0x55);
BlocksColor[5] = memory.read_u8(0x57);
BlocksColor[6] = memory.read_u8(0x62);
BlocksColor[7] = memory.read_u8(0x64);
BlocksColor[8] = memory.read_u8(0x66);
BlocksColor[9] = memory.read_u8(0x68);
BlocksColor[10] = memory.read_u8(0x01);
BlocksColor[11] = memory.read_u8(0x03);
BlocksColor[12] = memory.read_u8(0x05);
BlocksColor[13] = memory.read_u8(0x07);
BlocksColor[14] = memory.read_u8(0x09);
BlocksColor[15] = memory.read_u8(0x20);
BlocksColor[16] = memory.read_u8(0x22);
BlocksColor[17] = memory.read_u8(0x24);
BlocksColor[18] = memory.read_u8(0x26);
BlocksColor[19] = memory.read_u8(0x28);
BlocksColor[20] = memory.read_u8(0x2A);

Lives = memory.read_u8(0x08);

XPos = memory.read_u8(0x2B);
YPos = memory.read_u8(0x43);

Frame = emu.framecount();

-- Displays the color of each block
gui.text(77+62,25+56,""..BlocksColor[0]);
gui.text(65+50,53+56,""..BlocksColor[1]);
gui.text(93+78,53+56,""..BlocksColor[2]);
gui.text(53+38,81+58,""..BlocksColor[3]);
gui.text(77+62,81+58,""..BlocksColor[4]);
gui.text(105+90,81+58,""..BlocksColor[5]);
gui.text(41+26,109+60,""..BlocksColor[6]);
gui.text(65+50,109+60,""..BlocksColor[7]);
gui.text(93+78,109+60,""..BlocksColor[8]);
gui.text(117+102,109+60,""..BlocksColor[9]);
gui.text(29+14,137+62,""..BlocksColor[10]);
gui.text(65+26,137+62,""..BlocksColor[11]);
gui.text(77+62,137+62,""..BlocksColor[12]);
gui.text(105+90,137+62,""..BlocksColor[13]);
gui.text(129+114,137+62,""..BlocksColor[14]);
gui.text(16+4,165+63,""..BlocksColor[15]);
gui.text(41+26,165+63,""..BlocksColor[16]);
gui.text(65+50,165+63,""..BlocksColor[17]);
gui.text(93+78,165+63,""..BlocksColor[18]);
gui.text(117+102,165+63,""..BlocksColor[19]);
gui.text(141+128,165+63,""..BlocksColor[20]);

-- Defines a number for each block, 
-- The one at the top is 0,
-- Going from left to right, top to bottom
-- The last block is in the corner right at the bottom
if YPos == 25
then if XPos == 77
	 then Pos = 0;
	 end
elseif YPos == 53
	then if XPos == 65
		 then Pos = 1;
		 elseif XPos == 93
			then Pos = 2;
			end
	elseif YPos == 81
		then if XPos == 53
			 then Pos = 3;
			 elseif XPos == 77
				 then Pos = 4;
				 elseif XPos == 105
					 then Pos = 5;
					 end
		elseif YPos == 109
			then if XPos == 41
				 then Pos = 6;
				 elseif XPos == 65
					 then Pos = 7;
					 elseif XPos == 93
						 then Pos = 8;
						 elseif XPos == 117
							 then Pos = 9;
							 end
			elseif YPos == 137
				then if XPos == 29
					 then Pos = 10;
					 elseif XPos == 53
						 then Pos = 11;
						 elseif XPos == 77
							 then Pos = 12;
							 elseif XPos == 105
								 then Pos = 13;
								 elseif XPos == 129
									 then Pos = 14;
									 end
				elseif YPos == 165
					then if XPos == 16
						 then Pos = 15;
						 elseif XPos == 41
							 then Pos = 16;
							 elseif XPos == 65
								 then Pos = 17;
								 elseif XPos == 93
									 then Pos = 18;
									 elseif XPos == 117
										 then Pos = 19;
										 elseif XPos == 141
											 then Pos = 20;
											 end
end;

i = math.random(0,3);

-- Decides to which block to jump
if Pos == 0
then if i <= 1
	 then if BlocksColor[1] ~= NeededColor
		  then joypad.set({Down=true},1)
		  elseif BlocksColor[2] ~= NeededColor 
			  then joypad.set({Right=true},1)
			  else joypad.set({Down=true},1)
          end 		  
	 elseif i >= 2 
		 then if BlocksColor[2] ~= NeededColor
			  then joypad.set({Right=true},1)
		      elseif BlocksColor[1] ~= NeededColor 
			      then joypad.set({Down=true},1)
				  else joypad.set({Right=true},1)
			  end
	 end	 
end;

if Pos == 1
then if i == 0
	 then if BlocksColor[0] ~= NeededColor
	      then joypad.set({Up=true},1)
		  elseif BlocksColor[3] ~= NeededColor
			  then joypad.set({Down=true},1)
			  elseif BlocksColor[4] ~= NeededColor
				  then joypad.set({Right=true},1)
				  else joypad.set({Up=true},1)
		  end
	 elseif i > 1  
		 then if BlocksColor[3] ~= NeededColor
		      then joypad.set({Down=true},1)
			  elseif BlocksColor[0] ~= NeededColor
			      then joypad.set({Up=true},1)
			      elseif BlocksColor[4] ~= NeededColor
				      then joypad.set({Right=true},1)
					  else joypad.set({Down=true},1)
			  end
		 elseif i == 1
		     then if BlocksColor[4] ~= NeededColor
			      then joypad.set({Right=true},1)
				  elseif BlocksColor[3] ~= NeededColor
			          then joypad.set({Down=true},1)
			          elseif BlocksColor[0] ~= NeededColor
				          then joypad.set({Up=true},1)
						  else joypad.set({Right=true},1)
				  end
	 end	 
end;

if Pos == 2
then if i == 0
	 then if BlocksColor[0] ~= NeededColor
	      then joypad.set({Left=true},1)
		  elseif BlocksColor[4] ~= NeededColor
			  then joypad.set({Down=true},1)
			  elseif BlocksColor[5] ~= NeededColor
				  then joypad.set({Right=true},1)
				  else joypad.set({Left=true},1)
		  end
	 elseif i > 1  
		 then if BlocksColor[4] ~= NeededColor
		      then joypad.set({Down=true},1)
			  elseif BlocksColor[0] ~= NeededColor
			      then joypad.set({Left=true},1)
			      elseif BlocksColor[5] ~= NeededColor
				      then joypad.set({Right=true},1)
					  else joypad.set({Down=true},1)
			  end
		 elseif i == 1
		     then if BlocksColor[5] ~= NeededColor
			      then joypad.set({Right=true},1)
				  elseif BlocksColor[0] ~= NeededColor
			          then joypad.set({Left=true},1)
			          elseif BlocksColor[4] ~= NeededColor
				          then joypad.set({Down=true},1)
						  else joypad.set({Right=true},1)
				  end
	 end	 
end;

if Pos == 3
then if i == 0
	 then if BlocksColor[1] ~= NeededColor
	      then joypad.set({Up=true},1)
		  elseif BlocksColor[6] ~= NeededColor
			  then joypad.set({Down=true},1)
			  elseif BlocksColor[7] ~= NeededColor
				  then joypad.set({Right=true},1)
				  else joypad.set({Up=true},1)
		  end
	 elseif i > 1  
		 then if BlocksColor[6] ~= NeededColor
		      then joypad.set({Down=true},1)
			  elseif BlocksColor[1] ~= NeededColor
			      then joypad.set({Up=true},1)
			      elseif BlocksColor[7] ~= NeededColor
				      then joypad.set({Right=true},1)
					  else joypad.set({Down=true},1)
			  end
		 elseif i == 1
		     then if BlocksColor[7] ~= NeededColor
			      then joypad.set({Right=true},1)
				  elseif BlocksColor[1] ~= NeededColor
			          then joypad.set({Up=true},1)
			          elseif BlocksColor[6] ~= NeededColor
				          then joypad.set({Down=true},1)
						  else joypad.set({Right=true},1)
				  end
	 end	 
end;

if Pos == 4
then if i == 0
	 then if BlocksColor[1] ~= NeededColor
	      then joypad.set({Left=true},1)
		  elseif BlocksColor[2] ~= NeededColor
			  then joypad.set({Up=true},1)
			  elseif BlocksColor[7] ~= NeededColor
				  then joypad.set({Down=true},1)
				  elseif BlocksColor[8] ~= NeededColor
				      then joypad.set({Right=true},1)
					  else joypad.set({Left=true},1)
		  end
	 elseif i == 1  
		 then if BlocksColor[2] ~= NeededColor
		      then joypad.set({Up=true},1)
			  elseif BlocksColor[1] ~= NeededColor
			      then joypad.set({Left=true},1)
			      elseif BlocksColor[7] ~= NeededColor
				      then joypad.set({Down=true},1)
					  elseif BlocksColor[8] ~= NeededColor
				          then joypad.set({Right=true},1)
						  else joypad.set({Up=true},1)
			  end
		 elseif i == 2
		     then if BlocksColor[7] ~= NeededColor
			      then joypad.set({Down=true},1)
				  elseif BlocksColor[1] ~= NeededColor
			          then joypad.set({Left=true},1)
			          elseif BlocksColor[2] ~= NeededColor
				          then joypad.set({Up=true},1)
						  elseif BlocksColor[8] ~= NeededColor
				              then joypad.set({Right=true},1)
							  else joypad.set({Down=true},1)
				  end
			 elseif i == 3
			 then if BlocksColor[8] ~= NeededColor
			      then joypad.set({Right=true},1)
				  elseif BlocksColor[1] ~= NeededColor
			          then joypad.set({Left=true},1)
			          elseif BlocksColor[2] ~= NeededColor
				          then joypad.set({Up=true},1)
						  elseif BlocksColor[7] ~= NeededColor
							  then joypad.set({Down=true},1)
							  else joypad.set({Right=true},1)
				  end
	 end	 
end;

if Pos == 5
then if i == 0
	 then if BlocksColor[2] ~= NeededColor
	      then joypad.set({Left=true},1)
		  elseif BlocksColor[8] ~= NeededColor
			  then joypad.set({Down=true},1)
			  elseif BlocksColor[9] ~= NeededColor
				  then joypad.set({Right=true},1)
				  else joypad.set({Left=true},1)
		  end
	 elseif i > 1  
		 then if BlocksColor[8] ~= NeededColor
		      then joypad.set({Down=true},1)
			  elseif BlocksColor[2] ~= NeededColor
			      then joypad.set({Left=true},1)
			      elseif BlocksColor[9] ~= NeededColor
				      then joypad.set({Right=true},1)
					  else joypad.set({Down=true},1)
			  end
		 elseif i == 1
		     then if BlocksColor[9] ~= NeededColor
			      then joypad.set({Right=true},1)
				  elseif BlocksColor[2] ~= NeededColor
			          then joypad.set({Left=true},1)
			          elseif BlocksColor[8] ~= NeededColor
				          then joypad.set({Down=true},1)
						  else joypad.set({Right=true},1)
				  end
	 end	 
end;

if Pos == 6
then if i == 0
	 then if BlocksColor[3] ~= NeededColor
	      then joypad.set({Up=true},1)
		  elseif BlocksColor[10] ~= NeededColor
			  then joypad.set({Down=true},1)
			  elseif BlocksColor[11] ~= NeededColor
				  then joypad.set({Right=true},1)
				  else joypad.set({Up=true},1)
		  end
	 elseif i > 1  
		 then if BlocksColor[10] ~= NeededColor
		      then joypad.set({Down=true},1)
			  elseif BlocksColor[3] ~= NeededColor
			      then joypad.set({Up=true},1)
			      elseif BlocksColor[11] ~= NeededColor
				      then joypad.set({Right=true},1)
					  else joypad.set({Down=true},1)
			  end
		 elseif i == 1
		     then if BlocksColor[11] ~= NeededColor
			      then joypad.set({Right=true},1)
				  elseif BlocksColor[3] ~= NeededColor
			          then joypad.set({Up=true},1)
			          elseif BlocksColor[10] ~= NeededColor
				          then joypad.set({Down=true},1)
						  else joypad.set({Right=true},1)
				  end
	 end	 
end;

if Pos == 7
then if i == 0
	 then if BlocksColor[3] ~= NeededColor
	      then joypad.set({Left=true},1)
		  elseif BlocksColor[4] ~= NeededColor
			  then joypad.set({Up=true},1)
			  elseif BlocksColor[11] ~= NeededColor
				  then joypad.set({Down=true},1)
				  elseif BlocksColor[12] ~= NeededColor
				      then joypad.set({Right=true},1)
					  else joypad.set({Left=true},1)
		  end
	 elseif i == 1  
		 then if BlocksColor[4] ~= NeededColor
		      then joypad.set({Up=true},1)
			  elseif BlocksColor[3] ~= NeededColor
			      then joypad.set({Left=true},1)
			      elseif BlocksColor[11] ~= NeededColor
				      then joypad.set({Down=true},1)
					  elseif BlocksColor[12] ~= NeededColor
				          then joypad.set({Right=true},1)
						  else joypad.set({Up=true},1)
			  end
		 elseif i == 2
		     then if BlocksColor[11] ~= NeededColor
			      then joypad.set({Down=true},1)
				  elseif BlocksColor[3] ~= NeededColor
			          then joypad.set({Left=true},1)
			          elseif BlocksColor[4] ~= NeededColor
				          then joypad.set({Up=true},1)
						  elseif BlocksColor[12] ~= NeededColor
				              then joypad.set({Right=true},1)
							  else joypad.set({Down=true},1)
				  end
			 elseif i == 3
			 then if BlocksColor[12] ~= NeededColor
			      then joypad.set({Right=true},1)
				  elseif BlocksColor[3] ~= NeededColor
			          then joypad.set({Left=true},1)
			          elseif BlocksColor[4] ~= NeededColor
				          then joypad.set({Up=true},1)
						  elseif BlocksColor[11] ~= NeededColor
							  then joypad.set({Down=true},1)
							  else joypad.set({Right=true},1)
				  end
	 end	 
end;

if Pos == 8
then if i == 0
	 then if BlocksColor[4] ~= NeededColor
	      then joypad.set({Left=true},1)
		  elseif BlocksColor[5] ~= NeededColor
			  then joypad.set({Up=true},1)
			  elseif BlocksColor[12] ~= NeededColor
				  then joypad.set({Down=true},1)
				  elseif BlocksColor[13] ~= NeededColor
				      then joypad.set({Right=true},1)
					  else joypad.set({Left=true},1)
		  end
	 elseif i == 1  
		 then if BlocksColor[5] ~= NeededColor
		      then joypad.set({Up=true},1)
			  elseif BlocksColor[4] ~= NeededColor
			      then joypad.set({Left=true},1)
			      elseif BlocksColor[12] ~= NeededColor
				      then joypad.set({Down=true},1)
					  elseif BlocksColor[13] ~= NeededColor
				          then joypad.set({Right=true},1)
						  else joypad.set({Up=true},1)
			  end
		 elseif i == 2
		     then if BlocksColor[12] ~= NeededColor
			      then joypad.set({Down=true},1)
				  elseif BlocksColor[4] ~= NeededColor
			          then joypad.set({Left=true},1)
			          elseif BlocksColor[5] ~= NeededColor
				          then joypad.set({Up=true},1)
						  elseif BlocksColor[13] ~= NeededColor
				              then joypad.set({Right=true},1)
							  else joypad.set({Down=true},1)
				  end
			 elseif i == 3
			 then if BlocksColor[13] ~= NeededColor
			      then joypad.set({Right=true},1)
				  elseif BlocksColor[4] ~= NeededColor
			          then joypad.set({Left=true},1)
			          elseif BlocksColor[5] ~= NeededColor
				          then joypad.set({Up=true},1)
						  elseif BlocksColor[12] ~= NeededColor
							  then joypad.set({Down=true},1)
							  else joypad.set({Right=true},1)
				  end
	 end	 
end;

if Pos == 9
then if i == 0
	 then if BlocksColor[5] ~= NeededColor
	      then joypad.set({Left=true},1)
		  elseif BlocksColor[13] ~= NeededColor
			  then joypad.set({Down=true},1)
			  elseif BlocksColor[14] ~= NeededColor
				  then joypad.set({Right=true},1)
				  else joypad.set({Left=true},1)
		  end
	 elseif i > 1  
		 then if BlocksColor[13] ~= NeededColor
		      then joypad.set({Down=true},1)
			  elseif BlocksColor[5] ~= NeededColor
			      then joypad.set({Left=true},1)
			      elseif BlocksColor[14] ~= NeededColor
				      then joypad.set({Right=true},1)
					  else joypad.set({Down=true},1)
			  end
		 elseif i == 1
		     then if BlocksColor[14] ~= NeededColor
			      then joypad.set({Right=true},1)
				  elseif BlocksColor[5] ~= NeededColor
			          then joypad.set({Left=true},1)
			          elseif BlocksColor[13] ~= NeededColor
				          then joypad.set({Down=true},1)
						  else joypad.set({Right=true},1)
				  end
	 end	 
end;

if Pos == 10
then if i == 0
	 then if BlocksColor[6] ~= NeededColor
	      then joypad.set({Up=true},1)
		  elseif BlocksColor[15] ~= NeededColor
			  then joypad.set({Down=true},1)
			  elseif BlocksColor[16] ~= NeededColor
				  then joypad.set({Right=true},1)
				  else joypad.set({Up=true},1)
		  end
	 elseif i > 1  
		 then if BlocksColor[15] ~= NeededColor
		      then joypad.set({Down=true},1)
			  elseif BlocksColor[6] ~= NeededColor
			      then joypad.set({Up=true},1)
			      elseif BlocksColor[16] ~= NeededColor
				      then joypad.set({Right=true},1)
					  else joypad.set({Down=true},1)
			  end
		 elseif i == 1
		     then if BlocksColor[16] ~= NeededColor
			      then joypad.set({Right=true},1)
				  elseif BlocksColor[6] ~= NeededColor
			          then joypad.set({Up=true},1)
			          elseif BlocksColor[15] ~= NeededColor
				          then joypad.set({Down=true},1)
						  else joypad.set({Right=true},1)
				  end
	 end	 
end;

if Pos == 11
then if i == 0
	 then if BlocksColor[6] ~= NeededColor
	      then joypad.set({Left=true},1)
		  elseif BlocksColor[7] ~= NeededColor
			  then joypad.set({Up=true},1)
			  elseif BlocksColor[16] ~= NeededColor
				  then joypad.set({Down=true},1)
				  elseif BlocksColor[17] ~= NeededColor
				      then joypad.set({Right=true},1)
					  else joypad.set({Left=true},1)
		  end
	 elseif i == 1  
		 then if BlocksColor[7] ~= NeededColor
		      then joypad.set({Up=true},1)
			  elseif BlocksColor[6] ~= NeededColor
			      then joypad.set({Left=true},1)
			      elseif BlocksColor[16] ~= NeededColor
				      then joypad.set({Down=true},1)
					  elseif BlocksColor[17] ~= NeededColor
				          then joypad.set({Right=true},1)
						  else joypad.set({Up=true},1)
			  end
		 elseif i == 2
		     then if BlocksColor[16] ~= NeededColor
			      then joypad.set({Down=true},1)
				  elseif BlocksColor[6] ~= NeededColor
			          then joypad.set({Left=true},1)
			          elseif BlocksColor[7] ~= NeededColor
				          then joypad.set({Up=true},1)
						  elseif BlocksColor[17] ~= NeededColor
				              then joypad.set({Right=true},1)
							  else joypad.set({Down=true},1)
				  end
			 elseif i == 3
			 then if BlocksColor[17] ~= NeededColor
			      then joypad.set({Right=true},1)
				  elseif BlocksColor[6] ~= NeededColor
			          then joypad.set({Left=true},1)
			          elseif BlocksColor[7] ~= NeededColor
				          then joypad.set({Up=true},1)
						  elseif BlocksColor[16] ~= NeededColor
							  then joypad.set({Down=true},1)
							  else joypad.set({Right=true},1)
				  end
	 end	 
end;

if Pos == 12
then if i == 0
	 then if BlocksColor[7] ~= NeededColor
	      then joypad.set({Left=true},1)
		  elseif BlocksColor[8] ~= NeededColor
			  then joypad.set({Up=true},1)
			  elseif BlocksColor[17] ~= NeededColor
				  then joypad.set({Down=true},1)
				  elseif BlocksColor[18] ~= NeededColor
				      then joypad.set({Right=true},1)
					  else joypad.set({Left=true},1)
		  end
	 elseif i == 1  
		 then if BlocksColor[8] ~= NeededColor
		      then joypad.set({Up=true},1)
			  elseif BlocksColor[7] ~= NeededColor
			      then joypad.set({Left=true},1)
			      elseif BlocksColor[17] ~= NeededColor
				      then joypad.set({Down=true},1)
					  elseif BlocksColor[18] ~= NeededColor
				          then joypad.set({Right=true},1)
						  else joypad.set({Up=true},1)
			  end
		 elseif i == 2
		     then if BlocksColor[17] ~= NeededColor
			      then joypad.set({Down=true},1)
				  elseif BlocksColor[7] ~= NeededColor
			          then joypad.set({Left=true},1)
			          elseif BlocksColor[8] ~= NeededColor
				          then joypad.set({Up=true},1)
						  elseif BlocksColor[18] ~= NeededColor
				              then joypad.set({Right=true},1)
							  else joypad.set({Down=true},1)
				  end
			 elseif i == 3
			 then if BlocksColor[18] ~= NeededColor
			      then joypad.set({Right=true},1)
				  elseif BlocksColor[7] ~= NeededColor
			          then joypad.set({Left=true},1)
			          elseif BlocksColor[8] ~= NeededColor
				          then joypad.set({Up=true},1)
						  elseif BlocksColor[17] ~= NeededColor
							  then joypad.set({Down=true},1)
							  else joypad.set({Right=true},1)
				  end
	 end	 
end;

if Pos == 13
then if i == 0
	 then if BlocksColor[8] ~= NeededColor
	      then joypad.set({Left=true},1)
		  elseif BlocksColor[9] ~= NeededColor
			  then joypad.set({Up=true},1)
			  elseif BlocksColor[18] ~= NeededColor
				  then joypad.set({Down=true},1)
				  elseif BlocksColor[19] ~= NeededColor
				      then joypad.set({Right=true},1)
					  else joypad.set({Left=true},1)
		  end
	 elseif i == 1  
		 then if BlocksColor[9] ~= NeededColor
		      then joypad.set({Up=true},1)
			  elseif BlocksColor[8] ~= NeededColor
			      then joypad.set({Left=true},1)
			      elseif BlocksColor[18] ~= NeededColor
				      then joypad.set({Down=true},1)
					  elseif BlocksColor[19] ~= NeededColor
				          then joypad.set({Right=true},1)
						  else joypad.set({Up=true},1)
			  end
		 elseif i == 2
		     then if BlocksColor[18] ~= NeededColor
			      then joypad.set({Down=true},1)
				  elseif BlocksColor[8] ~= NeededColor
			          then joypad.set({Left=true},1)
			          elseif BlocksColor[9] ~= NeededColor
				          then joypad.set({Up=true},1)
						  elseif BlocksColor[19] ~= NeededColor
				              then joypad.set({Right=true},1)
							  else joypad.set({Down=true},1)
				  end
			 elseif i == 3
			 then if BlocksColor[19] ~= NeededColor
			      then joypad.set({Right=true},1)
				  elseif BlocksColor[8] ~= NeededColor
			          then joypad.set({Left=true},1)
			          elseif BlocksColor[9] ~= NeededColor
				          then joypad.set({Up=true},1)
						  elseif BlocksColor[18] ~= NeededColor
							  then joypad.set({Down=true},1)
							  else joypad.set({Right=true},1)
				  end
	 end	 
end;

if Pos == 14
then if i == 0
	 then if BlocksColor[9] ~= NeededColor
	      then joypad.set({Left=true},1)
		  elseif BlocksColor[19] ~= NeededColor
			  then joypad.set({Down=true},1)
			  elseif BlocksColor[20] ~= NeededColor
				  then joypad.set({Right=true},1)
				  else joypad.set({Left=true},1)
		  end
	 elseif i > 1  
		 then if BlocksColor[19] ~= NeededColor
		      then joypad.set({Down=true},1)
			  elseif BlocksColor[9] ~= NeededColor
			      then joypad.set({Left=true},1)
			      elseif BlocksColor[20] ~= NeededColor
				      then joypad.set({Right=true},1)
					  else joypad.set({Down=true},1)
			  end
		 elseif i == 1
		     then if BlocksColor[20] ~= NeededColor
			      then joypad.set({Right=true},1)
				  elseif BlocksColor[9] ~= NeededColor
			          then joypad.set({Left=true},1)
			          elseif BlocksColor[19] ~= NeededColor
				          then joypad.set({Down=true},1)
						  else joypad.set({Right=true},1)
				  end
	 end	 
end;

if Pos == 15
then joypad.set({Up=true},1)
end;

if Pos == 16
then if i <= 1
	 then if BlocksColor[10] ~= NeededColor
		  then joypad.set({Left=true},1)
		  elseif BlocksColor[11] ~= NeededColor 
			  then joypad.set({Up=true},1)
			  else joypad.set({Left=true},1)
          end 		  
	 elseif i >= 2 
		 then if BlocksColor[11] ~= NeededColor
			  then joypad.set({Up=true},1)
		      elseif BlocksColor[10] ~= NeededColor 
			      then joypad.set({Left=true},1)
				  else joypad.set({Up=true},1)
			  end
	 end	 
end;

if Pos == 17
then if i <= 1
	 then if BlocksColor[11] ~= NeededColor
		  then joypad.set({Left=true},1)
		  elseif BlocksColor[12] ~= NeededColor 
			  then joypad.set({Up=true},1)
			  else joypad.set({Left=true},1)
          end 		  
	 elseif i >= 2 
		 then if BlocksColor[12] ~= NeededColor
			  then joypad.set({Up=true},1)
		      elseif BlocksColor[11] ~= NeededColor 
			      then joypad.set({Left=true},1)
				  else joypad.set({Up=true},1)
			  end
	 end	 
end;

if Pos == 18
then if i <= 1
	 then if BlocksColor[12] ~= NeededColor
		  then joypad.set({Left=true},1)
		  elseif BlocksColor[13] ~= NeededColor 
			  then joypad.set({Up=true},1)
			  else joypad.set({Left=true},1)
          end 		  
	 elseif i >= 2 
		 then if BlocksColor[13] ~= NeededColor
			  then joypad.set({Up=true},1)
		      elseif BlocksColor[12] ~= NeededColor 
			      then joypad.set({Left=true},1)
				  else joypad.set({Up=true},1)
			  end
	 end	 
end;

if Pos == 19
then if i <= 1
	 then if BlocksColor[13] ~= NeededColor
		  then joypad.set({Left=true},1)
		  elseif BlocksColor[14] ~= NeededColor 
			  then joypad.set({Up=true},1)
			  else joypad.set({Left=true},1)
          end 		  
	 elseif i >= 2 
		 then if BlocksColor[14] ~= NeededColor
			  then joypad.set({Up=true},1)
		      elseif BlocksColor[13] ~= NeededColor 
			      then joypad.set({Left=true},1)
				  else joypad.set({Up=true},1)
			  end
	 end	 
end;

if Pos == 20
then joypad.set({Left=true},1)
end;

if n == 0
then if BlocksColor[0] == NeededColor
     then if BlocksColor[1] == NeededColor
     	 then if BlocksColor[2] == NeededColor
     		  then if BlocksColor[3] == NeededColor
     			   then if BlocksColor[4] == NeededColor
     					then if BlocksColor[5] == NeededColor
     						 then if BlocksColor[6] == NeededColor
     							  then if BlocksColor[7] == NeededColor
     								   then if BlocksColor[8] == NeededColor
     										then if BlocksColor[9] == NeededColor
     											 then if BlocksColor[10] == NeededColor
     											      then if BlocksColor[11] == NeededColor
     													   then if BlocksColor[12] == NeededColor
     															then if BlocksColor[13] == NeededColor
     																 then if BlocksColor[14] == NeededColor
     																      then if BlocksColor[15] == NeededColor
     																	       then if BlocksColor[16] == NeededColor
     																		        then if BlocksColor[17] == NeededColor
     																				     then if BlocksColor[18] == NeededColor
     																					      then if BlocksColor[19] == NeededColor
     																						       then if BlocksColor[20] == NeededColor
     																							        then FastestAttempt = emu.framecount();
     																										 savestate.saveslot(9);
																											 n = 1;
     																							        end
     																							   end
     																					      end
     																					 end
     																				end
     																		   end
     																	  end
     																 end
     														    end
     													   end
     												  end
     											 end
     										end
     								   end
     							  end
     						 end
     					end
     			   end
     		   end
     	  end
     end
else n = 0;
end;

if FastestAttempt < Frame
then savestate.loadslot(0);
	 Attempts = Attempts + 1;
end;

if Lives < LivesMem
then savestate.loadslot(0);
	 Attempts = Attempts + 1;
end;

LivesMem = Lives;

gui.text(160,10,"Position: "..Pos);
gui.text(160,20,"Lives: "..Lives);
gui.text(160,30,"Bot RNG: "..i);
gui.text(160,40,"Fastest Attempt: "..FastestAttempt);
gui.text(160,50,"Attempts: "..Attempts);

emu.frameadvance();

end;