Oui j'ai essayé le graphique mais ya pas de moyen d’accéder au récursive de la tours de Hanoi :/
Je poste ici si quelqu'un peut faire graphiquement correct comme animation si possible
Code : Tout sélectionner
;
; Created by threedslider 14/05/2023
;
; Tours de Hanoi en Purebasic v. 6.00.
Procedure rect (X.i, Y.i, width.i, heigth.i, R.i, G.i, B.i, iter.i)
For iy = 0 To heigth
For ix = 0 To width
;If ix = 0 And ix < width + 1
Plot(X+ix, Y, RGB(R, G, B))
;EndIf
Next
Next
If iter = 0
ProcedureReturn 0
Else
ProcedureReturn rect(X, Y+1, width, heigth,R, G, B, iter-1)
EndIf
EndProcedure
Procedure rectA (A.i)
rect(A, 300, 100, 100, 255, 0, 0, 10)
;ProcedureReturn A
EndProcedure
Procedure rectB (B.i)
rect(B+10, 300-10, 80, 100, 255, 255, 0, 10)
;procedureReturn B
EndProcedure
Procedure rectC (C.i)
rect(C+20, 300-20, 60, 100, 255, 0, 255, 10)
;ProcedureReturn C
EndProcedure
Procedure stick (X.i, Y.i, width.i, heigth.i, iter.i)
For iy = 0 To heigth
For ix = 0 To width
;If ix = 0 And ix < width + 1
Plot(X+ix, Y, RGB(255, 255, 255))
;EndIf
Next
Next
If iter = 0
ProcedureReturn 0
Else
ProcedureReturn stick(X, Y+1, width, heigth, iter-1)
EndIf
EndProcedure
; Move N disks to D towards to B.
Procedure Hanoi(N.i, D.i, B.i, I.i )
If N > 0
If N = 3
rectA(B)
rectB(B)
rectC(B)
EndIf
Hanoi(N-1, D, I, B)
Hanoi(N-1, I, B, D)
EndIf
EndProcedure
InitSprite()
InitKeyboard()
OpenWindow(1, 0,0,800,600,"Tours de Hanoi", #PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(1),0,0,800,600,0,0,0)
Repeat
ExamineKeyboard()
event = WindowEvent()
ClearScreen(RGB(0,0,0))
StartDrawing(ScreenOutput())
stick (200, 200, 10, 100, 100)
stick (200*2, 200, 10, 100, 100)
stick (200*3, 200, 10, 100, 100)
Hanoi(3, 155, 355, 555)
StopDrawing()
FlipBuffers()
Until event = #PB_Event_CloseWindow Or KeyboardPushed(#PB_Key_Escape)
End