Board Logo
« Rock Paper Scissors and AI »

Welcome Guest. Please Login or Register.
Jan 16th, 2018, 3:34pm


Conforums Terms of Service | Membership Rules | Home | Search | Recent Posts | Notification | Format Your Message | Installation FAQ

Please use the forums Search feature before asking.
Please post code using the code box described in Format Your Messages.
This will keep indentation, separate it better form the message and prevent gibberish.
If the code is too long for one post or additional files are needed, upload a ZIP archive to the Just BASIC Files Archive Site.

« Previous Topic | Next Topic »
Pages: 1 2  Notify Send Topic Print
 hotthread  Author  Topic: Rock Paper Scissors and AI  (Read 1924 times)
bplus
Senior Member
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 1255
xx Re: Rock Paper Scissors and AI
« Reply #15 on: Jan 31st, 2016, 09:27am »

Ah, this is progress (for me).

I was under impression that globals had to be declared in main code. I assumed everything was lost in sub or function because all was local including the use of line labels. Oh, you can start arrays inside procedures too.
« Last Edit: Jan 31st, 2016, 09:33am by bplus » User IP Logged

B+
bluatigro
Full Member
ImageImageImageImage


member is offline

Avatar

cxio difersas el tio respondas cxio samvaloras [ thats esperanto for : everybody is different therefore everybody is equal ]


PM

Gender: Male
Posts: 229
xx Re: Rock Paper Scissors and AI
« Reply #16 on: Feb 22nd, 2016, 04:44am »

i hope this is according to the rules

i didnt test it so i dont know if it lerns

Code:
global unknown , rock , paper , sisors , z1 , z2 , z3
unknown = 3
rock = 0
paper = 1
sisors = 2
dim mem( 64 )
for i = 0 to 64
  mem( i ) = unknown
next i
z1 = unknown
z2 = unknown
z3 = unknown

for i = 0 to 200
  c = computer()
  h = human()
  if c = rock and h = sisors then
    print "you lost"
    plost = plost + 1
  end if
  if c = sisors and h = paper then
    print "you lost"
    plost = plost + 1
  end if
  if c = paper and h = rock then
    print "you lost"
    plost = plost + 1
  end if
  if c = paper and h = sisors then
    print "you won"
    plost = plost + 1
  end if
  if c = rock and h = paper then
    print "you won"
    pwon = pwon + 1
  end if
  if c = paper and h = sisors then
    print "you won"
    pwon = pwon + 1
  end if
  if c = h then
    print "tie"
    ptie = ptie + 1
  end if
  mem( index( z1 , z2 , z3 ) ) = h
  z3 = z2
  z2 = z1
  z1 = h
next i
print "score    : "
print "you won  : " ; pwon / 2 ; " %"
print "you lost : " ; plost / 2 ; " %"
print "tie      : " ; ptie / 2 ; " %"
print "[ game over ]"
end
function human()
  while instr( "rps" , move$ ) = 0
    print "r = rock , p = paper , s = sisors"
    input "you move >" ; move$
  wend
  human = instr( "rps" , move$ ) - 1
end function
function computer()
  zet = mem( index( z1 , z2 , z3 ) )
  select case zet
    case rock
      uit = paper
    case paper
      uit = sisors
    case sisors
      uit = rock
    case else ''unknown
      uit = int( rnd(0) * 3 )
  end select
  computer = uit
end function
function index( q1 , q2 , q3 )
  index = q1 * 16 + q2 * 4 + q3
end function
 

« Last Edit: Feb 22nd, 2016, 04:46am by bluatigro » User IP Logged

bluatigro
Full Member
ImageImageImageImage


member is offline

Avatar

cxio difersas el tio respondas cxio samvaloras [ thats esperanto for : everybody is different therefore everybody is equal ]


PM

Gender: Male
Posts: 229
xx Re: Rock Paper Scissors and AI
« Reply #17 on: Feb 24th, 2016, 04:34am »

update :
- les memory
Code:
global unknown , rock , paper , sisors , z1 , z2 , z3
unknown = 3
rock = 0
paper = 1
sisors = 2
dim mem( 27 )
for i = 0 to 27
  mem( i ) = unknown
next i
z$ = "rock paper sisors"
for i = 1 to 200
  print "game : " ; i
  c = computer()
  h = human()
  print "i : " ; word$( z$ , c + 1 ) ;
  print "    you : " ; word$( z$ , h + 1 ) ;
  if c = rock and h = sisors then
    print "    you lost"
    plost = plost + 1
  end if
  if c = sisors and h = paper then
    print "    you lost"
    plost = plost + 1
  end if
  if c = paper and h = rock then
    print "    you lost"
    plost = plost + 1
  end if
  if c = paper and h = sisors then
    print "    you won"
    plost = plost + 1
  end if
  if c = rock and h = paper then
    print "    you won"
    pwon = pwon + 1
  end if
  if c = paper and h = sisors then
    print "    you won"
    pwon = pwon + 1
  end if
  if c = h then
    print "    tie"
    ptie = ptie + 1
  end if
  mem( index( z1 , z2 , z3 ) ) = h
  z3 = z2
  z2 = z1
  z1 = h
next i
print "score    : "
print "you won  : " ; pwon / 2 ; " %"
print "you lost : " ; plost / 2 ; " %"
print "tie      : " ; ptie / 2 ; " %"
print "[ game over ]"
end
function human()
  while instr( "rps" , move$ ) = 0
    print "r = rock , p = paper , s = sisors"
    input "your move > " ; move$
  wend
  human = instr( "rps" , move$ ) - 1
end function
function computer()
  zet = mem( index( z1 , z2 , z3 ) )
  select case zet
    case rock
      uit = paper
    case paper
      uit = sisors
    case sisors
      uit = rock
    case else ''unknown
      uit = int( rnd(0) * 3 )
  end select
  computer = uit
end function
function index( q1 , q2 , q3 )
  index = q1 * 9 + q2 * 3 + q3
end function
 
User IP Logged

Pages: 1 2  Notify Send Topic Print
« Previous Topic | Next Topic »

Conforums Terms of Service | Membership Rules | Home | Search | Recent Posts | Notification | Format Your Message | Installation FAQ

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls