home *** CD-ROM | disk | FTP | other *** search
/ Fujiology Archive / fujiology_archive_v1_0.iso / S / SEWER_S / LANGDSK1.ZIP / LANGDSK1.MSA / POWER_DE.MOS / HANOI.BAS < prev    next >
BASIC Source File  |  1987-04-22  |  2KB  |  111 lines

  1. 'The Towers of Hanoi program in Power BASIC
  2.  
  3. ' before trying to compile to memory change the Program Buffer size
  4. ' to 25k
  5. ' doesn't work too well in low res
  6.  
  7. LIBRARY "gemvdi"
  8.  
  9. REM $option V
  10.  
  11. DEFINT a-z
  12.  
  13. CONST max_rings=25
  14. CONST left=1,middle=2,right=3
  15. CONST pole1=110,pole2=320,pole3=530
  16. CONST space=50
  17. CONST max_width=200
  18. CONST gap=10
  19.  
  20. full_height=400\peekw(systab)            'mono or medium-rez only
  21.  
  22. DIM SHARED highest(3)
  23.  
  24. SUB draw_ring(which_pole,size,type,start)
  25. SHARED ring_height,full_height
  26. STATIC xstart,ystart
  27.  
  28. VSF_INTERIOR type
  29.  
  30. SELECT CASE which_pole
  31.     CASE=1
  32.         xstart=pole1-(size)\2
  33.     CASE=2
  34.         xstart=pole2-(size)\2
  35.     CASE=3
  36.         xstart=pole3-(size)\2
  37. END SELECT
  38.  
  39. ystart=full_height-space-start*ring_height
  40.  
  41. IF type=0 THEN
  42.   VR_RECFL xstart,ystart,xstart+size,ystart+ring_height-2
  43. ELSE
  44.   V_BAR xstart,ystart,xstart+size,ystart+ring_height-2
  45. END IF      
  46.           
  47. END SUB
  48.  
  49. SUB realmove(val source, val destination)
  50. SHARED poles(2)
  51. STATIC ring_width,ystart
  52.  
  53. ring_width=poles(source,highest(source))
  54.  
  55. 'erase source ring
  56. draw_ring source,ring_width,0,highest(source)
  57.  
  58. poles(source,highest(source))=0
  59. DECR highest(source)
  60.  
  61. 'draw destination ring
  62. INCR highest(destination)
  63. poles(destination,highest(destination))=ring_width
  64. VSF_STYLE highest(destination)
  65.  
  66. draw_ring destination,ring_width,2,highest(destination)
  67.  
  68. END SUB
  69.  
  70. SUB move(val howmany, val source, val work, val destination)
  71.     IF howmany<=1 THEN
  72.        realmove source,destination
  73.     ELSE
  74.        move howmany-1,source,destination,work
  75.        realmove source,destination
  76.        move howmany-1,work,source,destination
  77.     END IF
  78. END SUB
  79.  
  80. 'The actual start
  81. DO
  82.     LOCATE 1,2
  83.     INPUT "Number of rings to move: ",num_rings
  84. LOOP UNTIL num_rings>1 AND num_rings<=max_rings
  85.  
  86. ring_height=(full_height-2*space)\max_rings
  87.  
  88. MOUSE -1                        'turn mouse off
  89. WINDOW OPEN 2,"The Towers of Hanoi in Power BASIC",0,18,640,full_height-18,1
  90.  
  91. VSF_COLOR 1
  92.  
  93. DIM SHARED poles(3,num_rings)
  94.  
  95. 'initialise first pole
  96. FOR i=1 TO num_rings
  97.     poles(1,i)=max_width-(i-1)*(max_width\num_rings)
  98. NEXT i
  99.  
  100. FOR i=1 TO num_rings
  101.     VSF_STYLE(i)
  102.     highest(1)=i
  103.     draw_ring 1,poles(1,i),2,highest(1)
  104. NEXT i
  105.  
  106. tm!=TIMER
  107.  
  108. move num_rings,left,middle,right
  109.  
  110. print num_rings;"rings moved in";TIMER-tm!;"seconds"
  111.