It is currently Tue Jun 27, 2017 10:29 am



Welcome
Welcome to rfobasic

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining our free community, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content, and access many other special features. In addition, registered members also see less advertisements. Registration is fast, simple, and absolutely free, so please, join our community today. **You are not required to provide truthful information to any registration questions. Be whomever you wish to be.!


Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: Code finder game inspired by Roy's Crack the Lock's Code.
Unread postPosted: Wed Apr 05, 2017 1:51 am 
Offline

Joined: Sat Mar 02, 2013 11:04 am
Posts: 866
Location: France
Hi all

we all know that a computer will definitely be faster than the human brain to calculate... but after seeing Roy's excellent code Crack the Lock's Code, my parisian friend gege_95c and myself thought of trying to code the AI to solve the challenge proposed by Roy ( obviously under the same conditions as a human ).

My first idea was to use a big string of the 720 possibilities of code and then remove pieces according to the responses to the proposals...
gege_95c had an other idea finaly best than mine : using an logical board.

We were absolutely not sure if the AI (or to be abble to wright an AI that) will find the solution in less than 10 shots !

Here is the result ( console mode ) :

Code:
REM AI (console) pour "Code finder"  01.04.2017 by gege_95crj + Cassiope34.

dim cat[10,3], c$[3] ,co$[20], nco[20], p[20], nbco[20]
mmx =10 : ti =clock()
DO              %  principal loop
   array.fill cat[],9 : tr =0 : pr =0 : co=0 : dprop$=""
   do : a =int(rnd()*10) : b =int(rnd()*10) : c =int(rnd()*10) : until a<>b & a<>c & b<>c
   secret$ = int$(a)+int$(b)+int$(c) : s1$ =mid$(secret$,1,1) : s2$ =mid$(secret$,2,1) : s3$ =mid$(secret$,3,1)
  ?
  ? "*************************"
  ? "     Code secret "+secret$
  ? "*************************"

   do
     if pr<3 & tr<3
       prop$ =word$("012 345 678 ",pr+1)

     else
       do            % make a prop$
         do
           a =int(rnd()*len(c$[1])/2)+1 : b =int(rnd()*len(c$[2])/2)+1 : c =int(rnd()*len(c$[3])/2)+1
           p1 =val(word$(c$[1],a)) : p2 =val(word$(c$[2],b)) : p3 =val(word$(c$[3],c))
           prop$ =int$(p1)+int$(p2)+int$(p3)
         until p1<>p2 & p1<>p3 & p2<>p3 & !IS_IN(prop$,dprop$)

         ok= 1 : z =0
         if co        %  compare prop if ok against all last prop
           do
             z++ : b1= val(mid$(co$[z],1,1)) : b2= val(mid$(co$[z],2,1)) : b3= val(mid$(co$[z],3,1))
             if (b1=p1)+(b2=p2)+(b3=p3)<>nbco[z] | (b1=p1 | b1=p2 | b1=p3)+(b2=p1 | b2=p2 | b2=p3)+(b3=p1 | b3=p2 | b3=p3)<>nco[z]
               ok=0 : dprop$ += prop$ +" "
             endif
           until z=co | ok=0
         endif
       until ok

     endif

     GOSUB verif

   until rep$ ="30"

   nt++ : npr+=pr : if pr>pmx then pmx =pr
   p[pr]++ : if pr<mmx then mmx =pr
  ?
  ?"nb codes: "+int$(nt)+"    moyenne: "+int$(npr/nt)+"     ( min = ";int$(mmx);"   max = ";int$(pmx);" )       en "+int$(clock()-ti)+" ms."
  for e=2 to pmx
    ?"     ";int$(e);" =";int$(p[e]*100/nt);"\%  ";
  next
  ?
  ! ?"      Touch the screen to continue or 2x BackKey to exit."
  ! if pr>7 then do : pause 1 : until tch : tch =0    % attente relance en touchant l'écran.
UNTIL  nt=100
END

OnConsoleTouch:
  tch =1
ConsoleTouch.resume

Verif:       % control
dprop$ += prop$+" "
p1$ =mid$(prop$,1,1) : p2$ =mid$(prop$,2,1) : p3$ =mid$(prop$,3,1)
bp =(s1$=p1$) + (s2$=p2$) + (s3$=p3$)
mp =(s1$=p2$ | s1$=p3$) + (s2$=p1$ | s2$=p3$) + (s3$=p1$ | s3$=p2$)
rep$ =int$(bp)+int$(mp) : tr+=bp+mp : pr++
? int$(pr)+" - prop$ = \""+prop$+"\"  rep$ = \""+rep$+"\""

if rep$ ="30" then return

if tr=3
   if pr<4 then ca=10 : gosub cat3
   if pr<3 then ca= 9 : gosub cat3 : ca=8 : gosub cat3 : ca=7 : gosub cat3
   if pr=1 then ca= 6 : gosub cat3 : ca=5 : gosub cat3 : ca=4 : gosub cat3
endif

op$ =p1$+p3$+p2$+" "+p2$+p1$+p3$+" "+p2$+p3$+p1$+" "+p3$+p1$+p2$+" "+p3$+p2$+p1$+" "

p1 =val(p1$)+1 : p2 =val(p2$)+1 : p3 =val(p3$)+1

if bp+mp then co++ : co$[co]= prop$ : nco[co]= bp+mp : nbco[co]= bp

if bp+mp=3
   for z=0 to 9
      if z<>p1-1 & z<>p2-1 & z<>p3-1 then ca=z+1 : gosub cat3
   next

elseif bp+mp=0
     ca=p1 : gosub cat3 : ca=p2 : gosub cat3 : ca=p3 : gosub cat3 : dprop$ += op$

elseif bp & !mp
     cat[p1,2]=0 : cat[p1,3]=0 : cat[p2,1]=0 : cat[p2,3]=0 : cat[p3,1]=0 : cat[p3,2]=0 : dprop$ += op$

elseif mp & !bp
     cat[p1,1]=0 : cat[p2,2]=0 : cat[p3,3]=0
     if mp<3 then dprop$ += op$

endif

for y=1 to 3      %  use the logical board (cat[] to build possibilities by numbers positions
   c$[y] =""
   for x=1 to 10
      if cat[x,y]<>0 then c$[y]+=int$(x-1)+" "
   next
next
? "   \"";c$[1]+"\",       \"";c$[2]+"\",      \"";c$[3];"\""     %  all possibilities by numbers positions
return

cat3:   % set cat[ca] =  0
  cat[ca,1]=0 : cat[ca,2]=0 : cat[ca,3]=0
return

The AI will play 100 time so with 100 secrets random codes and with a small statistic at the end...
prop$ is the AI proposal and rep$ is the response : first number = right placed numbers and last number = wrong placed numbers.
You can see below 3 strings that are all remaining possibilities for the 3 places.


and my APK to integrate this IA... http://laughton.com/basic/programs/games/CodeFinder/Code_Finder.apk
Attachment:
Code_Finder.png
Code_Finder.png [ 420.53 KiB | Viewed 649 times ]


The computer is faster than the human. :lol: :lol: :mrgreen: :twisted:

Cheers

Gilles.

_________________
"It is better to mobilize intelligence for stupid things, rather than mobilizing stupidity for intelligent things."
Galaxy TAB S 8.4, 2560x1600, Marshmallow 6.0.1
Galaxy Note II, 1280x720, JB4.1.2
Galaxy A3, 1280x720, Android 6.0.1


Last edited by Cassiope34 on Thu Apr 06, 2017 4:28 am, edited 1 time in total.

Report this post
Top
 Profile  
 
 Post subject: Re: Code finder game inspired by Roy's Crack the Lock's Code
Unread postPosted: Thu Apr 06, 2017 12:08 am 
Offline
User avatar

Joined: Mon Aug 18, 2014 1:16 pm
Posts: 1337
Hi Gilles

'after seeing Roy's excellent code Crack the Lock's Code, '
Thanks for the complement

This is real cool and and as you say 'The computer is faster than the human' :lol: :lol:

It would be good to have an option on my version for it to solve it's self. ;)

Regards Roy

BTW. Anybody know what's going on with this form.
Attachment:
Forbidden.PNG
Forbidden.PNG [ 53.27 KiB | Viewed 664 times ]


Report this post
Top
 Profile  
 
 Post subject: Re: Code finder game inspired by Roy's Crack the Lock's Code
Unread postPosted: Thu Apr 06, 2017 4:11 am 
Offline
User avatar

Joined: Tue Mar 05, 2013 5:19 am
Posts: 596
Location: Netherlands
Hi Roy,

I guess this problem is back....http://rfobasic.freeforums.org/ftp-forbidden-gou-dknt-have-access-t4987.html

I get the same error again, whereas it disappeared after dms sent a mail to Paul.

Regards, Aat

_________________
To view all my Apps in the BASIC! repository: http://laughton.com/basic/programs/Author_Index/Aat.pdf

When Sod's Law equals Murphy's Law you are bound to be on the right track....!


Report this post
Top
 Profile  
 
 Post subject: Re: Code finder game inspired by Roy's Crack the Lock's Code
Unread postPosted: Thu Apr 06, 2017 4:15 am 
Offline

Joined: Sat Mar 02, 2013 11:04 am
Posts: 866
Location: France
Hello Roy,
roy wrote:
It would be good to have an option on my version for it to solve it's self. ;)

I'm sure it will be easy to adapt and include the code I give for your code... ;)


roy wrote:
BTW. Anybody know what's going on with this form.
Attachment:
Forbidden.PNG

Same result for me... :?
It's surely an FTP access pb from http because using an other way (addon FireFTP for Firefox) the FTP is still accessible... :cry:

Cheers

Gilles

_________________
"It is better to mobilize intelligence for stupid things, rather than mobilizing stupidity for intelligent things."
Galaxy TAB S 8.4, 2560x1600, Marshmallow 6.0.1
Galaxy Note II, 1280x720, JB4.1.2
Galaxy A3, 1280x720, Android 6.0.1


Report this post
Top
 Profile  
 
 Post subject: Re: Code finder game inspired by Roy's Crack the Lock's Code
Unread postPosted: Thu Apr 06, 2017 11:00 am 
Offline
User avatar

Joined: Mon Aug 18, 2014 1:16 pm
Posts: 1337
Thanks Aat

Gilles Could you upload you CodeFinder in a zip file. I'd like a look at your graphic version

I still can't down load from the forum (Forbidden) :roll: :roll:

Thanks Roy


Report this post
Top
 Profile  
 
 Post subject: Re: Code finder game inspired by Roy's Crack the Lock's Code
Unread postPosted: Thu Apr 06, 2017 8:14 pm 
Offline
User avatar

Joined: Sat Dec 08, 2012 2:14 am
Posts: 1147
Location: From Blighty
I managed to download using f39_downloader.bas in 'Sample Programs'. Nice work gentleman! When I exit the app from the menu icon top right, in the .apk... I get an error saying "Unfortunately, Code_Finder has stopped."

?

Mog


Report this post
Top
 Profile  
 
 Post subject: Re: Code finder game inspired by Roy's Crack the Lock's Code
Unread postPosted: Thu Apr 06, 2017 11:44 pm 
Offline

Joined: Sat Mar 02, 2013 11:04 am
Posts: 866
Location: France
roy wrote:
Thanks Aat

Gilles Could you upload you CodeFinder in a zip file. I'd like a look at your graphic version

I still can't down load from the forum (Forbidden) :roll: :roll:

Thanks Roy


Yes of course Roy :)
Attachment:
Code_Finder.zip [3.39 MiB]
Downloaded 11 times



Mog wrote:
I managed to download using f39_downloader.bas in 'Sample Programs'. Nice work gentleman! When I exit the app from the menu icon top right, in the .apk... I get an error saying "Unfortunately, Code_Finder has stopped."

?

Mog

Same pb as here ? aMAZEing Labirynth : using the EXIT command with Android 6.0.1 Marshmallow crashes BASIC! ? ( and maybe just on some devices...! ) :oops: :evil: :?

Cheers

Gilles

_________________
"It is better to mobilize intelligence for stupid things, rather than mobilizing stupidity for intelligent things."
Galaxy TAB S 8.4, 2560x1600, Marshmallow 6.0.1
Galaxy Note II, 1280x720, JB4.1.2
Galaxy A3, 1280x720, Android 6.0.1


Report this post
Top
 Profile  
 
 Post subject: Re: Code finder game inspired by Roy's Crack the Lock's Code
Unread postPosted: Fri Apr 07, 2017 8:59 am 
Offline
User avatar

Joined: Mon Aug 18, 2014 1:16 pm
Posts: 1337
Excellent, Gilles

Also like the fonts ;)

Regards Roy


Report this post
Top
 Profile  
 
 Post subject: Re: Code finder game inspired by Roy's Crack the Lock's Code
Unread postPosted: Fri Apr 07, 2017 9:13 am 
Offline
User avatar

Joined: Mon Aug 18, 2014 1:16 pm
Posts: 1337
Mog wrote:
I managed to download using f39_downloader.bas in 'Sample Programs'. Nice work gentleman! When I exit the app from the menu icon top right, in the .apk... I get an error saying "Unfortunately, Code_Finder has stopped."

?

Mog


Thanks for that Mog

I managed to download using f39_downloader.bas, but it's more convenient to use the forum. So can someone fix it.

Thanks Roy


Report this post
Top
 Profile  
 
 Post subject: Re: Code finder game inspired by Roy's Crack the Lock's Code
Unread postPosted: Fri Apr 07, 2017 10:29 am 
Offline

Joined: Sat Mar 02, 2013 11:04 am
Posts: 866
Location: France
roy wrote:
Excellent, Gilles

Also like the fonts ;)

Regards Roy

Thanks a lot Roy.

Maybe I'll throw myself in that Le CAMINO ...

Cheers

Gilles

_________________
"It is better to mobilize intelligence for stupid things, rather than mobilizing stupidity for intelligent things."
Galaxy TAB S 8.4, 2560x1600, Marshmallow 6.0.1
Galaxy Note II, 1280x720, JB4.1.2
Galaxy A3, 1280x720, Android 6.0.1


Report this post
Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
suspicion-preferred