|
Post by cassiope34 on Aug 26, 2021 8:54:33 GMT
Hello,
But in 2012 I bought myself a tablet! So I looked for an equivalent (more or less) to Justbasic for Android, and I found it: RFO Basic. ( Richard Feynman Observatory Basic because Paul Laughton the creator of this language (written in Java) pays homage to the Dr Feynman. )
So I transposed a lot of codes that I had written from Jusbasic to RFOBasic.
Last week I even managed to successfully transpose an essential and very effective part of the excellent Connect4 code from B+. ( my code )
Recently I found a very interesting little game for which I thought an AI using recursion would be very suitable : Duality. ( with an APK for 2 players to install on your smartphone or tablet to test the game ) In this game, what you need to know is whether a player (and which one) can win within the next 5 or 6 moves if you play that move... I tried to code an AI very similar to the one that had worked in Rod's Chess games but without success.
The only thing is: today I wouldn't be able to code anything in JustBasic !!!
So here is finally the subject of my post: to find someone interested in programming a very simple but rather difficult to win small game: Duality.
I will then manage to transpose it into the language I use today.
Friendship to the elders who remember me.
Cheers.
Gilles, under the sun of the south of France
NB : If you take my APK from the RFOBasic forum and install it on your smartphone or tablet to test it, don't worry about the requested authorizations which are due to the use of a command that I simply use to know the native language of your device.
Moreover, be aware that the entire content of an APK file (android application) can be viewed and edited with any Zipper / Unzipper software including the *.bas file.
|
|
|
Post by tsh73 on Aug 26, 2021 15:32:41 GMT
Hello Cassiope Interesting puzzle to think on ;)
|
|
|
Post by cassiope34 on Aug 26, 2021 16:50:35 GMT
Hello tsh73, nice to read you The puzzle would be to code a little recursive AI in this case for 'Duality' Cheers, Gilles.
|
|
|
Post by tsh73 on Aug 26, 2021 18:34:18 GMT
I did interface in JB It checks win\lose, keeps turn order, allows only valid moves. Have a look - do I understand rules right?
' Duality game ' attempt by tsh73, Aug 2021
nomainwin
WindowWidth = 550 WindowHeight = 410
UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2)
button #main.button1, "", button1Click, UL, 54, 186, 40, 40 button #main.button2, "", button1Click, UL, 94, 186, 40, 40 button #main.button3, "", button1Click, UL, 134, 186, 40, 40 button #main.button4, "", button1Click, UL, 174, 186, 40, 40 button #main.button5, "", button1Click, UL, 54, 146, 40, 40 button #main.button6, "", button1Click, UL, 94, 146, 40, 40 button #main.button7, "", button1Click, UL, 134, 146, 40, 40 button #main.button8, "", button1Click, UL, 174, 146, 40, 40 button #main.button9, "", button1Click, UL, 54, 106, 40, 40 button #main.button10, "", button1Click, UL, 94, 106, 40, 40 button #main.button11, "", button1Click, UL, 134, 106, 40, 40 button #main.button12, "", button1Click, UL, 174, 106, 40, 40 button #main.button13, "", button1Click, UL, 54, 66, 40, 40 button #main.button14, "", button1Click, UL, 94, 66, 40, 40 button #main.button15, "", button1Click, UL, 134, 66, 40, 40 button #main.button16, "", button1Click, UL, 174, 66, 40, 40 statictext #main.player, "Player: #", 26, 16, 224, 20 texteditor #main.log, 254, 11, 280, 340 button #main.button19, "Restart", [button19Click], UL, 22, 241, 122, 25 menu #main, "Edit" '<--- Texteditor Menu can be moved but not removed.
open "Duality" for window_nf as #main print #main, "trapclose [quit.main]"
print #main, "font ms_sans_serif 10"
global plr, gameWon [restart] gameWon=0 plr=1 #main.player, space$(20*(plr-1));"Player: ";plr #main.log "!cls" dim fld$(15) '0..15
for i = 0 to 15 hndl$="#main.button";(i+1) 'ttl$=chr$(asc("a")+(i mod 4));(int(i/4)+1) '#hndl$, ttl$ #hndl$, "" next
r1=random(16) col1=r1 mod 4 row1=int(r1/4) hndl$="#main.button";(r1+1) #hndl$, "O" fld$(r1)="O" #main.log "Initial piece #1 is ";ttl$(r1);" (";fld$(r1);")" while 1 SCAN r2=random(16) col2=r2 mod 4 row2=int(r2/4) if not (abs(col1-col2)<2 and abs(row1-row2)<2) then exit while wend hndl$="#main.button";(r2+1) #hndl$, "O" fld$(r2)="O" #main.log "Initial piece #2 is ";ttl$(r2);" (";fld$(r2);")"
'disable all but r2 neighbours numMoves=disableButNeighbours(r2)
wait
[quit.main] Close #main END
[button19Click] goto [restart] wait
'***************************************************** 'function returns a random integer in range [0, n) function random(n) random = int(rnd(1)*n) end function
function disableButNeighbours(r2) col2=r2 mod 4 row2=int(r2/4) for i = 0 to 15 col1=i mod 4 row1=int(i/4) hndl$="#main.button";(i+1) if not (abs(col1-col2)<2 and abs(row1-row2)<2) _ or i = r2 _ or fld$(i)="#" _ then #hndl$, "!disable" else #hndl$, "!enable" disableButNeighbours=disableButNeighbours+1 end if next end function
function ttl$(i) ttl$=chr$(asc("a")+(i mod 4));(int(i/4)+1) end function
sub button1Click handle$ if gameWon then #main.log "Game already won. Do restart." exit sub end if i = val(mid$(handle$, len("#main.button")+1))-1 ttl$=ttl$(i) 'notice handle$; " ";ttl$ if fld$(i)="" then fld$(i)="O" else if fld$(i)="O" then fld$(i)="#": #handle$ "!disable" end if #handle$ fld$(i) #main.log "Player ";plr; " clicks ";ttl$;" (";fld$(i);")" 'check for win '--------------------------- 'exactly 4, so from end to end col1=i mod 4 row1=int(i/4) c$=fld$(i) winMsg$ = "" if fld$(row1*4)=c$ and fld$(row1*4+1)=c$ and fld$(row1*4+2)=c$ and fld$(row1*4+3)=c$ then _ winMsg$ = "(-)" if fld$(col1)=c$ and fld$(col1+4)=c$ and fld$(col1+8)=c$ and fld$(col1+12)=c$ then _ winMsg$ = "(|)" if col1=row1 and fld$(0)=c$ and fld$(5)=c$ and fld$(10)=c$ and fld$(15)=c$ then _ winMsg$ = "(/)" if col1+row1=3 and fld$(3)=c$ and fld$(6)=c$ and fld$(9)=c$ and fld$(12)=c$ then _ winMsg$ = "(\)" if winMsg$<>"" then gameWon=1 #main.log "Player ";plr;" wins! ";winMsg$ notice "Player ";plr;" wins! ";winMsg$ : exit sub end if '--------------------------- plr=3-plr '1<->2 '#main.player, "Player: ";plr #main.player, space$(50*(plr-1));"Player ";plr numMoves=disableButNeighbours(i) if numMoves=0 then #main.log "No more moves. Player ";plr;" lose!" notice "No more moves"+chr$(13)+"Player ";plr;" lose!" end if end sub
|
|
|
Post by cassiope34 on Aug 27, 2021 7:48:26 GMT
Hi, yes, you applied the rules perfectly, that's exactly it.
Hello cundo Cheers, Gilles.
|
|