'{$STAMP BS2} 'Learning Robot Code by Mike Ball, 2002 'mikeball@gliderpilot.net 'http://headphones.solarbotics.net 'This program will go, in roughly random order, through the choices. Each incorect answer is eventually eliminated by 'decreasing it's probablity, while the correct answer will have it's probability increased via a timer system 'in the main loop. It's not very "clean" but it works! a var byte b var byte c var byte d var byte t var byte fate var word choice var byte 'start, set all timers for each agent to 30 "loops" We will call the agents Alpha, Bravo, Charlie, and Delta a = 30 b = 30 c = 30 d = 30 main: 'if in1=1 then main 'this line was omitted because it didn't seem to increase the functinality or randomness. The idea 'was that if the pulse was still present by the time the program had picked an agent, tried it, and 'returned, the program would wait until it disappeared before continuing. Several captures of the program's 'output were studied and no apparent difference was discovered. random fate 'Pick a Random Number choice = fate & %11 'limit the size of that number and call it choice branch choice,[alpha,bravo,charlie,delta] 'use this number to decide which agent to try 'agent picker alpha: if a = 0 then bravo 'if this choice is eliminated (ie: 0) then skip it and go to the next for t = 0 to a 'establish a timer for "a" number of loops. This is effectively a timer, which If in0 = 1 then doalpha 'will be interupted when a pulse is detected on pin zero. The program next 'will then execute that agent. 'randomly picking the next loop was tried by returning to the main label at this point 'but it seemed to try everything three times in a row instead of making it more random bravo: if b = 0 then charlie for t = 0 to b If in0 = 1 then dobravo next charlie: if c = 0 then delta for t = 0 to c If in0 = 1 then docharlie next delta: if d = 0 then main for t = 0 to d If in0 = 1 then dodelta next goto main 'Agents doalpha: debug cr, "Alpha" 'Write "Alpha" to the debug screen on the computer so we know which agent was picked a = a-10 'We have defined this agent, for the purposes of experimentation, as unsuccessful 'We will decrease its timer by 10 loops goto bravo 'Restart the agent picker on the next loop. This ensures that the program will cycle, 'rather than trying each agent 3 times in a row dobravo: debug cr, "Bravo" b = b-10 'this loop is also "unsuccesful", so it's duration is also decreased. When any loop has been 'tried without success 3 times, it is eliminated permenantly. Note that when we encorporate 'a method to qualify the success of the machine, a change in the conditions for success can 'cause the machine to remember this particular agent and try it again. More on this later goto charlie docharlie: debug cr, "Charlie" c = c+20 'We have selected this agent to be "the one." It's duration is increased by 20 loops instead 'of 10 because we know it succeded once, so it will probably do so again. It makes sense that 'that a success would be weighted more than a failure in changing the probability it will 'be picked again. goto delta dodelta: debug cr, "Delta" d = d-10 goto main