The game of Ayumu

Post Reply
aguila
Posts: 2
Joined: Sun Jun 15, 2014 3:04 pm
My devices: iphone, ipad and macbook
Location: Belgium

The game of Ayumu

Post by aguila »

More info on http://en.wikipedia.org/wiki/Ayumu_(chimpanzee)
You can try to be be as good as Ayumu but you'll probably not success!

' *** Ayumu game, © Philippe Lagarrigue, 2014 ***
number = 6
milisec = 750
GOSUB init_app
GOSUB init_vars

begin:
GOSUB define_coord
GOSUB dessine_nombres
GOSUB wait_ms
GOSUB cache_nombres
nombre = 1
DO
GOSUB no_touch
GOSUB get_touch
GOSUB check_pos
UNTIL nombre > number
IF okay = 1 THEN
DRAW TEXT "Bravo !" AT 0,0
PAUSE 1
ENDIF
GOTO begin


wait_ms:
f = TIMER() + milisec
not_yet:
IF f > TIMER() THEN GOTO not_yet
RETURN


check_pos:
IF tx >= x(nombre) - 30 AND tx <= x(nombre) + 70 THEN
IF ty >= y(nombre) - 30 AND ty <= y(nombre) + 70 THEN
DRAW TEXT nombre AT x(nombre), y(nombre)
nombre = nombre + 1
okay = 1
RETURN
ENDIF
ENDIF
nombre = number + 1
okay = 0
RETURN


check_coord:
IF f > 1 THEN
FOR e = 1 TO f - 1
IF xc(e) = xx AND yc(e) = yy THEN
again = 1
RETURN
ENDIF
NEXT e
ENDIF
again = 0
RETURN


define_coord:
FOR f = 1 TO number
hasard:
xx = RND (segment - 1) + 1
yy = RND (segment - 1) + 1
GOSUB check_coord
IF again = 1 THEN GOTO hasard
xc(f) = xx
yc(f) = yy
NEXT f
GOSUB def_coord
RETURN


def_coord:
FOR f = 1 TO number
x(f) = xoffset + xc(f) * pixels
y(f) = yoffset + yc(f) * pixels
NEXT f
RETURN


dessine_nombres:
GRAPHICS CLEAR
FOR f = 1 TO number
DRAW TEXT f AT x(f), y(f)
NEXT f
RETURN

cache_nombres:
FOR f = 1 TO number
FILL CIRCLE 15 + x(f), 20 + y(f) SIZE 50
NEXT f
RETURN


new_orientation:
GET ORIENTATION p2
IF p1 <> p2 THEN
GOSUB init_vars
GOSUB def_coord
GOSUB cache_nombres
' dessine nombres trouvés
FOR f = 1 TO nombre - 1
DRAW TEXT f AT x(f), y(f)
NEXT f
ENDIF
RETURN


no_touch:
loop1:
GOSUB new_orientation
GET TOUCH 0 AS tx, ty
IF tx <> -1 THEN GOTO loop1
RETURN


get_touch:
loop2:
GOSUB new_orientation
GET TOUCH 0 AS tx, ty
IF tx = -1 THEN GOTO loop2
RETURN


init_app:
GRAPHICS
SHADOW ON
RANDOMIZE
DIM x(number+1), y(number+1)
DIM xc(number+1), yc(number+1)
segment = 6
DRAW FONT SIZE 50
DRAW COLOR 0,0,0
RETURN


init_vars:
GRAPHICS CLEAR
GET ORIENTATION p1
sw = SCREEN_WIDTH()
sh = SCREEN_HEIGHT()
xlen = INT (sw / segment)
ylen = INT (sh / segment)
IF xlen < ylen THEN
pixels = xlen
ELSE
pixels = ylen
ENDIF
xoffset = (sw - pixels * segment) / 2
yoffset = (sh - pixels * segment) / 2
RETURN

User avatar
Mr. Kibernetik
Site Admin
Posts: 4787
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPhone, iPad, MacBook
Location: Russia
Flag: Russia

Re: The game of Ayumu

Post by Mr. Kibernetik »

Nice game, thanks! :)

User avatar
Dutchman
Posts: 858
Joined: Mon May 06, 2013 9:21 am
My devices: iMac, iPad Air, iPhone
Location: Netherlands
Flag: Netherlands

Re: The game of Ayumu

Post by Dutchman »

Very nice game, once you get some experience.
Initially the short showtime is frustrating.
Ayumu got some time to learn the game and came gradually to his remarkable skills.
Therefore I changed the showtime so that it gradually decreases.
Now it is easier to become a master. :D
Success!

Code: Select all

'The game of Ayumu
'More info on http://en.wikipedia.org/wiki/Ayumu_(chimpanzee)
'You can try to be be as good as Ayumu
'but you'll probably not success!
'version V2: decreasing showtime by Dutchman
' adapt following variables to your skills
showtime=5 ' showtime at start
endtime=1 ' minimum showtime
dtime=0.3 ' reduction of showtime per round

' *** Ayumu game, © Philippe Lagarrigue, 2014 ***
number = 6
GOSUB init_app
GOSUB init_vars

begin:
GOSUB define_coord
GOSUB dessine_nombres
PAUSE showtime
GOSUB cache_nombres
nombre = 1
DO
GOSUB no_touch
GOSUB get_touch
GOSUB check_pos
UNTIL nombre > number
IF okay = 1 THEN
DRAW TEXT "Bravo !" AT 0,0
PAUSE 1
ENDIF
IF showtime>endtime THEN showtime-=dtime
showtime=MAX(showtime,endtime)'prevent underflow
GOTO begin


check_pos:
IF tx >= x(nombre) - 30 AND tx <= x(nombre) + 70 THEN
IF ty >= y(nombre) - 30 AND ty <= y(nombre) + 70 THEN
DRAW TEXT nombre AT x(nombre), y(nombre)
nombre = nombre + 1
okay = 1
RETURN
ENDIF
ENDIF
nombre = number + 1
okay = 0
RETURN


check_coord:
IF f > 1 THEN
FOR e = 1 TO f - 1
IF xc(e) = xx AND yc(e) = yy THEN
again = 1
RETURN
ENDIF
NEXT e
ENDIF
again = 0
RETURN


define_coord:
FOR f = 1 TO number
hasard:
xx = RND (segment - 1) + 1
yy = RND (segment - 1) + 1
GOSUB check_coord
IF again = 1 THEN GOTO hasard
xc(f) = xx
yc(f) = yy
NEXT f
GOSUB def_coord
RETURN


def_coord:
FOR f = 1 TO number
x(f) = xoffset + xc(f) * pixels
y(f) = yoffset + yc(f) * pixels
NEXT f
RETURN


dessine_nombres:
GRAPHICS CLEAR
FOR f = 1 TO number
DRAW TEXT f AT x(f), y(f)
NEXT f
RETURN

cache_nombres:
FOR f = 1 TO number
FILL CIRCLE 15 + x(f), 20 + y(f) SIZE 50
NEXT f
RETURN


new_orientation:
GET ORIENTATION p2
IF p1 <> p2 THEN
GOSUB init_vars
GOSUB def_coord
GOSUB cache_nombres
' dessine nombres trouvés
FOR f = 1 TO nombre - 1
DRAW TEXT f AT x(f), y(f)
NEXT f
ENDIF
RETURN


no_touch:
loop1:
GOSUB new_orientation
GET TOUCH 0 AS tx, ty
IF tx <> -1 THEN GOTO loop1
RETURN


get_touch:
loop2:
GOSUB new_orientation
GET TOUCH 0 AS tx, ty
IF tx = -1 THEN GOTO loop2
RETURN


init_app:
GRAPHICS
SHADOW ON
RANDOMIZE
DIM x(number+1), y(number+1)
DIM xc(number+1), yc(number+1)
segment = 6
DRAW FONT SIZE 50
DRAW COLOR 0,0,0
RETURN


init_vars:
GRAPHICS CLEAR
GET ORIENTATION p1
sw = SCREEN_WIDTH()
sh = SCREEN_HEIGHT()
xlen = INT (sw / segment)
ylen = INT (sh / segment)
IF xlen < ylen THEN
pixels = xlen
ELSE
pixels = ylen
ENDIF
xoffset = (sw - pixels * segment) / 2
yoffset = (sh - pixels * segment) / 2
RETURN

User avatar
Dutchman
Posts: 858
Joined: Mon May 06, 2013 9:21 am
My devices: iMac, iPad Air, iPhone
Location: Netherlands
Flag: Netherlands

Re: The game of Ayumu

Post by Dutchman »

Will he remain the master? :lol:
See http://bit.ly/1B21iPh
Attachments
Ayumu
Ayumu
Ayumu.jpg (34.46 KiB) Viewed 2357 times

User avatar
Dutchman
Posts: 858
Joined: Mon May 06, 2013 9:21 am
My devices: iMac, iPad Air, iPhone
Location: Netherlands
Flag: Netherlands

Re: The game of Ayumu

Post by Dutchman »

The following code is fit for Launcher

Code: Select all

'The game of Ayumu
'More info on http://en.wikipedia.org/wiki/Ayumu_(chimpanzee)
'You can try to be be as good as Ayumu
'but you'll probably not success!
'version V2: decreasing showtime by Dutchman
'version v3, adapted for launcher
' adapt following variables to your skills
showtime=5 ' showtime at start
endtime=1 ' minimum showtime
dtime=0.3 ' reduction of showtime per round

' *** Ayumu game, © Philippe Lagarrigue, 2014 ***
'SET TOOLBAR OFF
CALL ExitButton
FILL COLOR 0.3,1,0.3
number = 6
GOSUB init_app
GOSUB init_vars

DO
  GOSUB define_coord
  GOSUB dessine_nombres
  FOR n=1 to 10
    IF BUTTON_PRESSED("Exit") THEN Finish
    PAUSE showtime/10
  NEXT n
  GOSUB cache_nombres
  nombre = 1
  DO
    GOSUB no_touch
    GOSUB get_touch
    GOSUB check_pos
  UNTIL nombre > number OR Quit
  IF okay = 1 THEN
    DRAW TEXT "Bravo !" AT 0,0
    PAUSE 1
  ENDIF
  IF showtime>endtime THEN showtime-=dtime
  showtime=MAX(showtime,endtime)'prevent underflow
UNTIL Quit
Finish:
IF Launch$="launcher" THEN
  {/- Launcher.sb}
ENDIF
SET TOOLBAR ON
END

'======= Subroutines and Functions ===========
DEF ExitButton
Fsize=20
GET SCREEN SIZE sw,sh
sw=SCREEN_WIDTH()
sh=SCREEN_HEIGHT()
SET BUTTONS CUSTOM
SET BUTTONS FONT SIZE Fsize
DRAW COLOR 1,1,0
FILL COLOR 1,0,0
t$="Exit"
BUTTON t$ TEXT t$ AT sw-3*fsize,0 SIZE 3*fsize,1.5*Fsize
END DEF
'
check_pos:
IF tx >= x(nombre) - 30 AND tx <= x(nombre) + 70 THEN
IF ty >= y(nombre) - 30 AND ty <= y(nombre) + 70 THEN
DRAW TEXT nombre AT x(nombre), y(nombre)
nombre = nombre + 1
okay = 1
RETURN
ENDIF
ENDIF
nombre = number + 1
okay = 0
RETURN
'
check_coord:
IF f > 1 THEN
FOR e = 1 TO f - 1
IF xc(e) = xx AND yc(e) = yy THEN
again = 1
RETURN
ENDIF
NEXT e
ENDIF
again = 0
RETURN
'
define_coord:
FOR f = 1 TO number
hasard:
Quit=BUTTON_PRESSED("Exit") 
IF Quit THEN Finish
xx = RND (segment - 1) + 1
yy = RND (segment - 1) + 1
GOSUB check_coord
IF again = 1 THEN GOTO hasard
xc(f) = xx
yc(f) = yy
NEXT f
GOSUB def_coord
RETURN
'
def_coord:
FOR f = 1 TO number
x(f) = xoffset + xc(f) * pixels
y(f) = yoffset + yc(f) * pixels
NEXT f
RETURN
'
dessine_nombres:
GRAPHICS CLEAR
FOR f = 1 TO number
DRAW TEXT f AT x(f), y(f)
NEXT f
RETURN
'
cache_nombres:
FOR f = 1 TO number
FILL CIRCLE 15 + x(f), 20 + y(f) SIZE 50
NEXT f
RETURN
'
new_orientation:
GET ORIENTATION p2
IF p1 <> p2 THEN
GOSUB init_vars
GOSUB def_coord
GOSUB cache_nombres
' dessine nombres trouvés
FOR f = 1 TO nombre - 1
DRAW TEXT f AT x(f), y(f)
NEXT f
ENDIF
RETURN
'
no_touch:
loop1:
Quit=BUTTON_PRESSED("Exit") 
IF Quit THEN Finish
GOSUB new_orientation
GET TOUCH 0 AS tx, ty
IF tx <> -1 THEN GOTO loop1
RETURN
'
get_touch:
loop2:
Quit=BUTTON_PRESSED("Exit") 
IF Quit THEN Finish
GOSUB new_orientation
GET TOUCH 0 AS tx, ty
IF tx = -1 THEN GOTO loop2
RETURN
'
init_app:
GRAPHICS
SHADOW ON
RANDOMIZE
DIM x(number+1), y(number+1)
DIM xc(number+1), yc(number+1)
segment = 6
DRAW FONT SIZE 50
DRAW COLOR 0,0,0
RETURN
'
init_vars:
GRAPHICS CLEAR
GET ORIENTATION p1
sw = SCREEN_WIDTH()
sh = SCREEN_HEIGHT()
xlen = INT (sw / segment)
ylen = INT (sh / segment)
IF xlen < ylen THEN
pixels = xlen
ELSE
pixels = ylen
ENDIF
xoffset = (sw - pixels * segment) / 2
yoffset = (sh - pixels * segment) / 2
RETURN

Post Reply