Forum Liberty Basic France
• Index
Voici un Puissance 4 qui joue contre vous, mais il n'est pas très très fort, même en mettant "Difficulty" sur "hard" 
Malheureusement je ne retrouve ni l'auteur ni l'endroit du forum où je l'avais trouvé...!
Je l'ai juste un peu modifié pour qu'on puisse y jouer uniquement à la souris, au lieu des boutons initiaux pour choisir la colonne.
Je n'ai rien retiré du code original, juste ajouté quelques lignes et mis des apostrophes devant les lignes devenus inutiles.
Si ça dit à quelqu'un de traduire correctement tout les textes de l'auteur ( il y en a pas mal
)
Code VB :
Edité par cassiope01 Le 10/05/2012 à 19h03

Malheureusement je ne retrouve ni l'auteur ni l'endroit du forum où je l'avais trouvé...!
Je l'ai juste un peu modifié pour qu'on puisse y jouer uniquement à la souris, au lieu des boutons initiaux pour choisir la colonne.
Je n'ai rien retiré du code original, juste ajouté quelques lignes et mis des apostrophes devant les lignes devenus inutiles.
Si ça dit à quelqu'un de traduire correctement tout les textes de l'auteur ( il y en a pas mal

Code VB :
'connect4GUI.bas randomize 0.5 dim ROW(12) 'arrays are larger, to hold empty margins dim B(11,12)'only indices 3-9 are used global DIFFICULTY : DIFFICULTY = 3 'default difficulty global MOVE for i = 1 to 40 : separator$ = separator$+"__" : next 'read texts global COMPUTERTHINKS read COMPUTERTHINKS dim compThink$(COMPUTERTHINKS) for i = 1 to COMPUTERTHINKS : read a$ : compThink$(i) = a$ : next global YOURTURN read YOURTURN dim makeYourMove$(YOURTURN) for i = 1 to YOURTURN : read a$ : makeYourMove$(i) = a$ : next global HUMANWIN read HUMANWIN dim youWin$(HUMANWIN) for i = 1 to HUMANWIN : read a$ : youWin$(i) = a$ : next global COMPUTERWIN read COMPUTERWIN dim compWin$(COMPUTERWIN) for i = 1 to COMPUTERWIN : read a$ : compWin$(i) = a$ : next global DRAW read DRAW dim drawMessage$(DRAW) for i = 1 to DRAW : read a$ : drawMessage$(i) = a$ : next nomainwin WindowWidth = 552 WindowHeight = 437 UpperLeftX=int((DisplayWidth-WindowWidth)/3) UpperLeftY=int((DisplayHeight-WindowHeight)/4) graphicbox #main.graph, 22, 6, 385, 330 ' button #main.button1, "1", RowButton, UL, 22, 341, 48, 25 ' button #main.button2, "2", RowButton, UL, 78, 341, 48, 25 ' button #main.button3, "3", RowButton, UL, 134, 341, 48, 25 ' button #main.button4, "4", RowButton, UL, 190, 341, 48, 25 ' button #main.button5, "5", RowButton, UL, 246, 341, 48, 25 ' button #main.button6, "6", RowButton, UL, 302, 341, 48, 25 ' button #main.button7, "7", RowButton, UL, 358, 341, 48, 25 button #main.new, "New Game", [newGame], UL, 414, 21, 112, 25 button #main.difficulty, "Difficulty", GetDifficulty, UL, 414, 56, 112, 25 button #main.quit, "Quit", quit, UL, 414, 291, 112, 25 button #main.skip, "Skip", [CompStart], UL, 430, 161, 88, 25 button #main.about, "About", About, UL, 414, 256, 112, 25 statictext #main, separator$, 1, 366, 546, 18 statictext #main.info, "", 4, 385, 548, 18 open "JB Connect4" for window_nf as #main print #main.graph,"down" print #main, "trapclose quit" print #main, "font ms_sans_serif 10" #main.graph "when leftButtonDown RowButton" ' wait [newGame] #main.info, "Select your column or press Skip to make computer start." redim ROW(12) redim B(11,12) MOVE = 0 call DrawEmptyGrid for i = 3 to 9 ROW(i) = 2 'row is "empty", 3 is first level ' h$ = "#main.button"+str$(i-2) ' #h$, "!enable" 'enable all buttons next i #main.skip, "!enable" wait sub GetDifficulty h$ WindowWidth = 208 WindowHeight = 230 ' UpperLeftX=int((DisplayWidth-WindowWidth)/2) ' UpperLeftY=int((DisplayHeight-WindowHeight)/2) groupbox #difficulty, "Select level:", 14, 11, 168, 180 radiobutton #difficulty.rb1, "Easiest", [dummy], [dummy], 38, 41, 72, 20 radiobutton #difficulty.rb2, "Easy", [dummy], [dummy], 38, 66, 48, 20 radiobutton #difficulty.rb3, "Medium", [dummy], [dummy], 38, 91, 64, 20 radiobutton #difficulty.rb4, "Hard", [dummy], [dummy], 38, 116, 48, 20 button #difficulty.default, "Ok", [difficultyOk], UL, 54, 146, 80, 25 open "" for dialog_nf_modal as #difficulty print #difficulty, "trapclose [difficultyOk]" h$ = "#difficulty.rb"+str$(DIFFICULTY) #h$, "set" wait [dummy] wait [difficultyOk] for i = 1 to 4 h$ = "#difficulty.rb"+str$(i) #h$, "value? a$" if a$ = "set" then DIFFICULTY = i next i close #difficulty end sub [CompStart] #main.skip, "!disable" call CompMove DIFFICULTY wait sub DrawEmptyGrid #main.graph, "cls; fill lightgray; color darkgray; size 2" for i = 1 to 6 #main.graph, "line "; i*55-1; " 0 "; i*55-1; " 384" next i for i = 1 to 5 #main.graph, "line 0 "; i*55-1; " 384 "; i*55-1 next i #main.graph, "flush" end sub sub DrawMove x, y x = x-2 y = 9-y #main.graph, "place "; x*55-28; " "; y*55-28 #main.graph, "circlefilled 24; flush" end sub sub RowButton handle$, mx, my #main.skip, "!disable" ' n = val(right$(handle$,1))+2 n = int(mx/(385/7))+3 ROW(n) = ROW(n)+1 B(ROW(n), n) = 1 #main.graph, "color darkblue; backcolor darkblue" MOVE = MOVE+1 call DrawMove n, ROW(n) 'check human move MOVE = CheckWin(MOVE, 1, ROW(n), n) if MOVE < 42 then call CompMove DIFFICULTY MOVE = MOVE+1 end sub sub quit handle$ close #main end end sub sub About handle$ s$ = "The aim of the game is to make a line of 4 or more balls of the";_ " player's colour (blue), and to prevent the opponent from doing the";_ " same."; chr$(13); "The lines can be either horizontal, vertical ";_ "or diagonal."; chr$(13); chr$(13);"To make a move, select the column where";_ " you want to add your ball. It will drop to the lowest possible ";_ "position in that column. Use the numbered buttons at the bottom of the ";_ "window."; chr$(13); chr$(13); "A game by uncleBen" WindowWidth = 384 WindowHeight = 336 ' UpperLeftX=int((DisplayWidth-WindowWidth)/2) ' UpperLeftY=int((DisplayHeight-WindowHeight)/2) groupbox #about.frame, "How to play", 22, 16, 336, 240 statictext #about.text, "", 38, 46, 304, 200 button #about.default, "Ok", [aboutOk], UL, 126, 270, 122, 25 open "About JB Connect4" for dialog_nf_modal as #about #about, "trapclose [aboutOk]" #about, "font ms_sans_serif 10" #about.frame, "!font ms_sans_serif 12" #about.text, s$ wait [aboutOk] close #about end sub sub CompMove depth #main.info, compThink$(int(rnd(1)*COMPUTERTHINKS)+1) ' for i = 1 to 7 ' h$ = "#main.button"+str$(i) ' #h$, "!disable" ' next i n = BestMove(-1, depth) ROW(n) = ROW(n)+1 B(ROW(n),n) = -1 ' for i = 1 to 7 ' if ROW(i+2) < 8 then ' h$ = "#main.button"+str$(i) ' ' #h$, "!enable" ' end if ' next i #main.graph, "color darkred; backcolor darkred" call DrawMove n, ROW(n) #main.info, makeYourMove$(int(rnd(1)*YOURTURN)+1) MOVE = CheckWin(MOVE, -1, ROW(n), n) end sub function IsWin$(pl, row, col) if B(row-1,col)=pl and B(row-2,col)=pl and B(row-3,col)= pl then _ IsWin$ = str$(row-1); col; str$(row-2); col; str$(row-3); col if B(row,col-1)=pl and B(row,col-2)=pl and B(row,col-3)= pl then _ IsWin$ = IsWin$; row; str$(col-1); row; str$(col-2); row; str$(col-3) if B(row,col-1)=pl and B(row,col-2)=pl and B(row,col+1)= pl then _ IsWin$ = IsWin$; row; str$(col-1); row; str$(col-2); row; str$(col+1) if B(row,col-1)=pl and B(row,col+1)=pl and B(row,col+2)= pl then _ IsWin$ = IsWin$; row; str$(col-1); row; str$(col+1); row; str$(col+2) if B(row,col+1)=pl and B(row,col+2)=pl and B(row,col+3)= pl then _ IsWin$ = IsWin$; row; str$(col+1); row; str$(col+2); row; str$(col+3) if B(row+3,col-3)=pl and B(row+2,col-2)=pl and B(row+1,col-1)= pl then _ IsWin$ = IsWin$; str$(row+3); str$(col-3); str$(row+2); str$(col-2); str$(row+1); str$(col-1) if B(row+2,col-2)=pl and B(row+1,col-1)=pl and B(row-1,col+1)= pl then _ IsWin$ = IsWin$; str$(row+2); str$(col-2); str$(row+1); str$(col-1); str$(row-1); str$(col+1) if B(row+1,col-1)=pl and B(row-1,col+1)=pl and B(row-2,col+2)= pl then _ IsWin$ = IsWin$; str$(row+1); str$(col-1); str$(row-1); str$(col+1); str$(row-2); str$(col+2) if B(row-1,col+1)=pl and B(row-2,col+2)=pl and B(row-3,col+3)= pl then _ IsWin$ = IsWin$; str$(row-1); str$(col+1); str$(row-2); str$(col+2); str$(row-3); str$(col+3) if B(row-3,col-3)=pl and B(row-2,col-2)=pl and B(row-1,col-1)= pl then _ IsWin$ = IsWin$; str$(row-3); str$(col-3); str$(row-2); str$(col-2); str$(row-1); str$(col-1) if B(row-2,col-2)=pl and B(row-1,col-1)=pl and B(row+1,col+1)= pl then _ IsWin$ = IsWin$; str$(row-2); str$(col-2); str$(row-1); str$(col-1); str$(row+1); str$(col+1) if B(row-1,col-1)=pl and B(row+1,col+1)=pl and B(row+2,col+2)= pl then _ IsWin$ = IsWin$; str$(row-1); str$(col-1); str$(row+1); str$(col+1); str$(row+2); str$(col+2) if B(row+1,col+1)=pl and B(row+2,col+2)=pl and B(row+3,col+3)= pl then _ IsWin$ = IsWin$; str$(row+1); str$(col+1); str$(row+2); str$(col+2); str$(row+3); str$(col+3) if IsWin$ <> "" then IsWin$ = str$(row); str$(col); IsWin$ end function function CheckWin(CheckWin, player, row, col) s$ = IsWin$(player, row, col) if s$ <> "" then CheckWin = 42 if player = 1 then #main.info, youWin$(int(rnd(1)*HUMANWIN)+1) #main.graph, "color blue; backcolor blue" else #main.info, compWin$(int(rnd(1)*COMPUTERWIN)+1) #main.graph, "color red; backcolor red" end if for i = 1 to len(s$) step 2 x = val(mid$(s$, i, 1)) y = val(mid$(s$, i+1, 1)) call DrawMove y, x next i else if CheckWin = 42 then #main.info, drawMessage$(int(rnd(1)*DRAW)+1) end if ' if CheckWin = 42 then ' for i = 1 to 7 ' h$ = "#main.button"+str$(i) ' ' #h$, "!disable" ' next i ' end if end function function GetValue(player, depth, row, column) pl = -1*player if (B(row-1,column)=pl and B(row-2,column)=pl and B(row-3,column)= pl) or _ (B(row,column-1)=pl and B(row,column-2)=pl and B(row,column-3)= pl) or _ (B(row,column-1)=pl and B(row,column-2)=pl and B(row,column+1)= pl) or _ (B(row,column-1)=pl and B(row,column+1)=pl and B(row,column+2)= pl) or _ (B(row,column+1)=pl and B(row,column+2)=pl and B(row,column+3)= pl) or _ (B(row+3,column-3)=pl and B(row+2,column-2)=pl and B(row+1,column-1)= pl) or _ (B(row+2,column-2)=pl and B(row+1,column-1)=pl and B(row-1,column+1)= pl) or _ (B(row+1,column-1)=pl and B(row-1,column+1)=pl and B(row-2,column+2)= pl) or _ (B(row-1,column+1)=pl and B(row-2,column+2)=pl and B(row-3,column+3)= pl) or _ (B(row-3,column-3)=pl and B(row-2,column-2)=pl and B(row-1,column-1)= pl) or _ (B(row-2,column-2)=pl and B(row-1,column-1)=pl and B(row+1,column+1)= pl) or _ (B(row-1,column-1)=pl and B(row+1,column+1)=pl and B(row+2,column+2)= pl) or _ (B(row+1,column+1)=pl and B(row+2,column+2)=pl and B(row+3,column+3)= pl) then GetValue = -128 else if depth = 0 then exit function GetValue = -1000 for i = 3 to 9 if ROW(i) < 8 then ROW(i) = ROW(i)+1 B(ROW(i), i) = player value = -1*GetValue(-1*player, depth-1, ROW(i), i)/2 B(ROW(i), i) = 0 ROW(i) = ROW(i)-1 if value > GetValue then GetValue = value if value = 64 then exit for end if end if next i end if end function function BestMove(player, depth) max = -1000 for i = 3 to 9 if ROW(i) < 8 then ROW(i) = ROW(i)+1 B(ROW(i),i) = player value = -1*GetValue(-1*player, depth, ROW(i), i) B(ROW(i), i) = 0 ROW(i) = ROW(i)-1 if value > max then max = value BestList$ = str$(i) if max = 128 then exit for else if value = max then BestList$ = BestList$+str$(i) end if end if next i 'print BestList$, max BestMove = val(mid$(BestList$, int(rnd(1)*len(BestList$))+1, 1)) end function data 11 data "Hmm... Let me think!" data "You play well... I must THINK!" data "I know, I'm going to win. Just let me think." data "Everybody be quiet! Computer thinking!" data "You can't beat me!" data "Silence please. Grandmaster is pondering his move!" data "Must... think... hard..." data "This is giving me a headache..." data "Please wait. I'll be back to you in a second." data "You have no idea what I can do. Me neither, so far." data "You surprise me. Are you sure this was a wise move?!" data 11 data "I fear nothing! Gimme your best move!" data "Wake me up when you're ready to make your move." data "Show me what you've got!" data "Your turn." data "You can't win. Prove me wrong!" data "I'll take a small nap while you figure THIS out!" data "Think carefully! One little error and you're finished!" data "Hit me real hard!" data "You think it's a draw? I don't think so!" data "I'd be surprised if you found a way to avoid defeat now!" data "Take your time. I'll be surfing the web if you need me." data 11 data "You win! Let's play again." data "May thoughts were wandering... You win!" data "I didn't see that coming!" data "I bet you can't beat me again!" data "Congratulations! You are almost as good as I." data "That's not fair! I had something in my eye." data "I can't believe it! You win!" data "There was a magnetic storm! I couldn't think straight..." data "It's impossible... Tell me how many moves you think ahead." data "Amazing! You are my superhero." data "I couldn't concentrate. You were moving the mouse all the time." data 11 data "A big applause to the winner of the game!" data "This should teach you a lesson. Never mess with me!" data "Game over! You lose!" data "We can play another one, but you're still going to lose..." data "I bet you didn't see that one coming." data "We can still be friends?!" data "Ouch! This must hurt!" data "So, what are you doing tonight?..." data "Ladies and gentlemen, we have a winner. Guess who!" data "That's another matter-over-mind victory..." data "I'm the king of the world." data 10 data "I offer draw." data "Guess what! We're all out of moves." data "Draw?! Yet, you were so close..." data "You put me under a lot of pressure, but you couldn't break me!" data "Hmm, only a draw... Surely you can do better than that!" data "Press 'New Game'! We must find out who's better at this." data "Uh, what happened?" data "I told them we were going to need a larger board for this." data "That's what I call wasted CPU cycles..." data "I promise, next time I won't let you get away so easily."
Edité par cassiope01 Le 10/05/2012 à 19h03
____________________
Devise Shadocks : "Mieux vaut mobiliser son intelligence pour des conneries, que mobiliser sa connerie pour des choses intelligentes"
Coluche disait : "C'est parce que la vitesse de la lumière est plus rapide que celle du son que certains peuvent paraîtrent brillants jusqu'à ce qu'ils ouvrent la bouche."
Devise Shadocks : "Mieux vaut mobiliser son intelligence pour des conneries, que mobiliser sa connerie pour des choses intelligentes"
Coluche disait : "C'est parce que la vitesse de la lumière est plus rapide que celle du son que certains peuvent paraîtrent brillants jusqu'à ce qu'ils ouvrent la bouche."
Web
Pour une fois qu'on arrive à gagner contre ces satanés bécanes, on va pas se plaindre.

____________________
Roro
Roro
et pas toujours encore

J'ai commencé la traduction :
Code :
( Remis à jours )
Ce n'est pas encore finis mais çà avance.
De plus, lorsque j'aurais bien compris comment il fonctionne, j'essayerais de rajouter des niveaux ( par exemple ).
J'attends vos critiques.
Edité par alex877 Le 28/07/2012 à 16h01
Code :
randomize 0.5
dim ROW(12) 'arrays are larger, to hold empty margins
dim B(11,12)'only indices 3-9 are used
global DIFFICULTY : DIFFICULTY = 3 'default difficulty
global MOVE
for i = 1 to 40 : separator$ = separator$+"__" : next
'read texts
global COMPUTERTHINKS
read COMPUTERTHINKS
dim compThink$(COMPUTERTHINKS)
for i = 1 to COMPUTERTHINKS : read a$ : compThink$(i) = a$ : next
global YOURTURN
read YOURTURN
dim makeYourMove$(YOURTURN)
for i = 1 to YOURTURN : read a$ : makeYourMove$(i) = a$ : next
global HUMANWIN
read HUMANWIN
dim youWin$(HUMANWIN)
for i = 1 to HUMANWIN : read a$ : youWin$(i) = a$ : next
global COMPUTERWIN
read COMPUTERWIN
dim compWin$(COMPUTERWIN)
for i = 1 to COMPUTERWIN : read a$ : compWin$(i) = a$ : next
global DRAW
read DRAW
dim drawMessage$(DRAW)
for i = 1 to DRAW : read a$ : drawMessage$(i) = a$ : next
nomainwin
WindowWidth = 552
WindowHeight = 437
UpperLeftX=int((DisplayWidth-WindowWidth)/3)
UpperLeftY=int((DisplayHeight-WindowHeight)/4)
graphicbox #main.graph, 22, 6, 385, 330
' button #main.button1, "1", RowButton, UL, 22, 341, 48, 25
' button #main.button2, "2", RowButton, UL, 78, 341, 48, 25
' button #main.button3, "3", RowButton, UL, 134, 341, 48, 25
' button #main.button4, "4", RowButton, UL, 190, 341, 48, 25
' button #main.button5, "5", RowButton, UL, 246, 341, 48, 25
' button #main.button6, "6", RowButton, UL, 302, 341, 48, 25
' button #main.button7, "7", RowButton, UL, 358, 341, 48, 25
button #main.new, "Nouveau jeu", [newGame], UL, 414, 21, 112, 25
button #main.difficulty, "Difficulté", GetDifficulty, UL, 414, 56, 112, 25
button #main.quit, "Quitter", quit, UL, 414, 291, 112, 25
button #main.skip, "Démarrer le jeu", [CompStart], UL, 414, 161, 112, 25
button #main.about, "Aide/A propos", About, UL, 414, 256, 112, 25
statictext #main, separator$, 1, 366, 546, 18
statictext #main.info, "", 4, 385, 548, 18
open "Puissance 4" for window_nf as #main
print #main.graph,"down"
print #main, "trapclose quit"
print #main, "font ms_sans_serif 10"
#main.graph "when leftButtonDown RowButton"
' wait
[newGame]
#main.info, "Selectionner le niveau de dificulté ou appuyez sur : démarrer le jeu "
redim ROW(12)
redim B(11,12)
MOVE = 0
call DrawEmptyGrid
for i = 3 to 9
ROW(i) = 2 'row is "empty", 3 is first level
' h$ = "#main.button"+str$(i-2)
' #h$, "!enable" 'enable all buttons
next i
#main.skip, "!enable"
wait
sub GetDifficulty h$
WindowWidth = 208
WindowHeight = 230
' UpperLeftX=int((DisplayWidth-WindowWidth)/2)
' UpperLeftY=int((DisplayHeight-WindowHeight)/2)
groupbox #difficulty, "Selectionnez le niveau de dificulté:", 14, 11, 168, 180
radiobutton #difficulty.rb1, "Très facile", [dummy], [dummy], 38, 41, 72, 20
radiobutton #difficulty.rb2, "Facile", [dummy], [dummy], 38, 66, 48, 20
radiobutton #difficulty.rb3, "Normal", [dummy], [dummy], 38, 91, 64, 20
radiobutton #difficulty.rb4, "Dificile", [dummy], [dummy], 38, 116, 60, 20
button #difficulty.default, "Valider", [difficultyOk], UL, 54, 146, 80, 25
open "Niveau" for dialog_nf_modal as #difficulty
print #difficulty, "trapclose [difficultyOk]"
h$ = "#difficulty.rb"+str$(DIFFICULTY)
#h$, "set"
wait
[dummy]
wait
[difficultyOk]
for i = 1 to 4
h$ = "#difficulty.rb"+str$(i)
#h$, "value? a$"
if a$ = "set" then DIFFICULTY = i
next i
close #difficulty
end sub
[CompStart]
#main.skip, "!disable"
call CompMove DIFFICULTY
wait
sub DrawEmptyGrid
#main.graph, "cls; fill lightgray; color darkgray; size 2"
for i = 1 to 6
#main.graph, "line "; i*55-1; " 0 "; i*55-1; " 384"
next i
for i = 1 to 5
#main.graph, "line 0 "; i*55-1; " 384 "; i*55-1
next i
#main.graph, "flush"
end sub
sub DrawMove x, y
x = x-2
y = 9-y
#main.graph, "place "; x*55-28; " "; y*55-28
#main.graph, "circlefilled 24; flush"
end sub
sub RowButton handle$, mx, my
#main.skip, "!disable"
' n = val(right$(handle$,1))+2
n = int(mx/(385/7))+3
ROW(n) = ROW(n)+1
B(ROW(n), n) = 1
#main.graph, "color darkblue; backcolor darkblue"
MOVE = MOVE+1
call DrawMove n, ROW(n)
'check human move
MOVE = CheckWin(MOVE, 1, ROW(n), n)
if MOVE < 42 then call CompMove DIFFICULTY
MOVE = MOVE+1
end sub
sub quit handle$
close #main
end
end sub
sub About handle$
s$ = "Pour jouer :"
WindowWidth = 384
WindowHeight = 336
' UpperLeftX=int((DisplayWidth-WindowWidth)/2)
' UpperLeftY=int((DisplayHeight-WindowHeight)/2)
groupbox #about.frame, "Comment jouer", 22, 16, 336, 240
statictext #about.text, "", 38, 46, 304, 200
button #about.default, "Ok", [aboutOk], UL, 126, 270, 122, 25
open "A propos de Puissance 4" for dialog_nf_modal as #about
#about, "trapclose [aboutOk]"
#about, "font ms_sans_serif 10"
#about.frame, "!font ms_sans_serif 12"
#about.text, s$
wait
[aboutOk]
close #about
end sub
sub CompMove depth
#main.info, compThink$(int(rnd(1)*COMPUTERTHINKS)+1)
' for i = 1 to 7
' h$ = "#main.button"+str$(i)
' #h$, "!disable"
' next i
n = BestMove(-1, depth)
ROW(n) = ROW(n)+1
B(ROW(n),n) = -1
' for i = 1 to 7
' if ROW(i+2) < 8 then
' h$ = "#main.button"+str$(i)
' ' #h$, "!enable"
' end if
' next i
#main.graph, "color darkred; backcolor darkred"
call DrawMove n, ROW(n)
#main.info, makeYourMove$(int(rnd(1)*YOURTURN)+1)
MOVE = CheckWin(MOVE, -1, ROW(n), n)
end sub
function IsWin$(pl, row, col)
if B(row-1,col)=pl and B(row-2,col)=pl and B(row-3,col)= pl then _
IsWin$ = str$(row-1); col; str$(row-2); col; str$(row-3); col
if B(row,col-1)=pl and B(row,col-2)=pl and B(row,col-3)= pl then _
IsWin$ = IsWin$; row; str$(col-1); row; str$(col-2); row; str$(col-3)
if B(row,col-1)=pl and B(row,col-2)=pl and B(row,col+1)= pl then _
IsWin$ = IsWin$; row; str$(col-1); row; str$(col-2); row; str$(col+1)
if B(row,col-1)=pl and B(row,col+1)=pl and B(row,col+2)= pl then _
IsWin$ = IsWin$; row; str$(col-1); row; str$(col+1); row; str$(col+2)
if B(row,col+1)=pl and B(row,col+2)=pl and B(row,col+3)= pl then _
IsWin$ = IsWin$; row; str$(col+1); row; str$(col+2); row; str$(col+3)
if B(row+3,col-3)=pl and B(row+2,col-2)=pl and B(row+1,col-1)= pl then _
IsWin$ = IsWin$; str$(row+3); str$(col-3); str$(row+2); str$(col-2); str$(row+1); str$(col-1)
if B(row+2,col-2)=pl and B(row+1,col-1)=pl and B(row-1,col+1)= pl then _
IsWin$ = IsWin$; str$(row+2); str$(col-2); str$(row+1); str$(col-1); str$(row-1); str$(col+1)
if B(row+1,col-1)=pl and B(row-1,col+1)=pl and B(row-2,col+2)= pl then _
IsWin$ = IsWin$; str$(row+1); str$(col-1); str$(row-1); str$(col+1); str$(row-2); str$(col+2)
if B(row-1,col+1)=pl and B(row-2,col+2)=pl and B(row-3,col+3)= pl then _
IsWin$ = IsWin$; str$(row-1); str$(col+1); str$(row-2); str$(col+2); str$(row-3); str$(col+3)
if B(row-3,col-3)=pl and B(row-2,col-2)=pl and B(row-1,col-1)= pl then _
IsWin$ = IsWin$; str$(row-3); str$(col-3); str$(row-2); str$(col-2); str$(row-1); str$(col-1)
if B(row-2,col-2)=pl and B(row-1,col-1)=pl and B(row+1,col+1)= pl then _
IsWin$ = IsWin$; str$(row-2); str$(col-2); str$(row-1); str$(col-1); str$(row+1); str$(col+1)
if B(row-1,col-1)=pl and B(row+1,col+1)=pl and B(row+2,col+2)= pl then _
IsWin$ = IsWin$; str$(row-1); str$(col-1); str$(row+1); str$(col+1); str$(row+2); str$(col+2)
if B(row+1,col+1)=pl and B(row+2,col+2)=pl and B(row+3,col+3)= pl then _
IsWin$ = IsWin$; str$(row+1); str$(col+1); str$(row+2); str$(col+2); str$(row+3); str$(col+3)
if IsWin$ <> "" then IsWin$ = str$(row); str$(col); IsWin$
end function
function CheckWin(CheckWin, player, row, col)
s$ = IsWin$(player, row, col)
if s$ <> "" then
CheckWin = 42
if player = 1 then
#main.info, youWin$(int(rnd(1)*HUMANWIN)+1)
#main.graph, "color blue; backcolor blue"
else
#main.info, compWin$(int(rnd(1)*COMPUTERWIN)+1)
#main.graph, "color red; backcolor red"
end if
for i = 1 to len(s$) step 2
x = val(mid$(s$, i, 1))
y = val(mid$(s$, i+1, 1))
call DrawMove y, x
next i
else
if CheckWin = 42 then #main.info, drawMessage$(int(rnd(1)*DRAW)+1)
end if
' if CheckWin = 42 then
' for i = 1 to 7
' h$ = "#main.button"+str$(i)
' ' #h$, "!disable"
' next i
' end if
end function
function GetValue(player, depth, row, column)
pl = -1*player
if (B(row-1,column)=pl and B(row-2,column)=pl and B(row-3,column)= pl) or _
(B(row,column-1)=pl and B(row,column-2)=pl and B(row,column-3)= pl) or _
(B(row,column-1)=pl and B(row,column-2)=pl and B(row,column+1)= pl) or _
(B(row,column-1)=pl and B(row,column+1)=pl and B(row,column+2)= pl) or _
(B(row,column+1)=pl and B(row,column+2)=pl and B(row,column+3)= pl) or _
(B(row+3,column-3)=pl and B(row+2,column-2)=pl and B(row+1,column-1)= pl) or _
(B(row+2,column-2)=pl and B(row+1,column-1)=pl and B(row-1,column+1)= pl) or _
(B(row+1,column-1)=pl and B(row-1,column+1)=pl and B(row-2,column+2)= pl) or _
(B(row-1,column+1)=pl and B(row-2,column+2)=pl and B(row-3,column+3)= pl) or _
(B(row-3,column-3)=pl and B(row-2,column-2)=pl and B(row-1,column-1)= pl) or _
(B(row-2,column-2)=pl and B(row-1,column-1)=pl and B(row+1,column+1)= pl) or _
(B(row-1,column-1)=pl and B(row+1,column+1)=pl and B(row+2,column+2)= pl) or _
(B(row+1,column+1)=pl and B(row+2,column+2)=pl and B(row+3,column+3)= pl) then
GetValue = -128
else
if depth = 0 then exit function
GetValue = -1000
for i = 3 to 9
if ROW(i) < 8 then
ROW(i) = ROW(i)+1
B(ROW(i), i) = player
value = -1*GetValue(-1*player, depth-1, ROW(i), i)/2
B(ROW(i), i) = 0
ROW(i) = ROW(i)-1
if value > GetValue then
GetValue = value
if value = 64 then exit for
end if
end if
next i
end if
end function
function BestMove(player, depth)
max = -1000
for i = 3 to 9
if ROW(i) < 8 then
ROW(i) = ROW(i)+1
B(ROW(i),i) = player
value = -1*GetValue(-1*player, depth, ROW(i), i)
B(ROW(i), i) = 0
ROW(i) = ROW(i)-1
if value > max then
max = value
BestList$ = str$(i)
if max = 128 then exit for
else
if value = max then BestList$ = BestList$+str$(i)
end if
end if
next i
'print BestList$, max
BestMove = val(mid$(BestList$, int(rnd(1)*len(BestList$))+1, 1))
end function
data 11
data "Hmm... Laisse moi réfléchir"
data "Tu joues bien, Je le sais!"
data "Je le sais, je vais gagner, laisse moi juste réfléchir."
data "Everybody be quiet! Computer thinking!"
data "You can't beat me!"
data "Silence please. Grandmaster is pondering his move!"
data "Must... think... hard..."
data "This is giving me a headache..."
data "Please wait. I'll be back to you in a second."
data "You have no idea what I can do. Me neither, so far."
data "You surprise me. Are you sure this was a wise move?!"
data 11
data "I fear nothing! Gimme your best move!"
data "Wake me up when you're ready to make your move."
data "Show me what you've got!"
data "Your turn."
data "You can't win. Prove me wrong!"
data "I'll take a small nap while you figure THIS out!"
data "Think carefully! One little error and you're finished!"
data "Hit me real hard!"
data "You think it's a draw? I don't think so!"
data "I'd be surprised if you found a way to avoid defeat now!"
data "Take your time. I'll be surfing the web if you need me."
data 11
data "You win! Let's play again."
data "May thoughts were wandering... You win!"
data "I didn't see that coming!"
data "I bet you can't beat me again!"
data "Congratulations! You are almost as good as I."
data "That's not fair! I had something in my eye."
data "I can't believe it! You win!"
data "There was a magnetic storm! I couldn't think straight..."
data "It's impossible... Tell me how many moves you think ahead."
data "Amazing! You are my superhero."
data "I couldn't concentrate. You were moving the mouse all the time."
data 11
data "A big applause to the winner of the game!"
data "This should teach you a lesson. Never mess with me!"
data "Game over! You lose!"
data "We can play another one, but you're still going to lose..."
data "I bet you didn't see that one coming."
data "We can still be friends?!"
data "Ouch! This must hurt!"
data "So, what are you doing tonight?..."
data "Ladies and gentlemen, we have a winner. Guess who!"
data "That's another matter-over-mind victory..."
data "I'm the king of the world."
data 10
data "I offer draw."
data "Guess what! We're all out of moves."
data "Draw?! Yet, you were so close..."
data "You put me under a lot of pressure, but you couldn't break me!"
data "Hmm, only a draw... Surely you can do better than that!"
data "Press 'New Game'! We must find out who's better at this."
data "Uh, what happened?"
data "I told them we were going to need a larger board for this."
data "That's what I call wasted CPU cycles..."
data "I promise, next time I won't let you get away so easily."
( Remis à jours )
Ce n'est pas encore finis mais çà avance.
De plus, lorsque j'aurais bien compris comment il fonctionne, j'essayerais de rajouter des niveaux ( par exemple ).
J'attends vos critiques.
Edité par alex877 Le 28/07/2012 à 16h01
____________________
Si le meilleurs langage de programmation existe, alors le Just Basic est loin devant.
Ne me tappez pas dessus ! Je débute
Si le meilleurs langage de programmation existe, alors le Just Basic est loin devant.
Ne me tappez pas dessus ! Je débute

Web
Par contre je ne trouve pas la ligne ou le programme décide quoi faire quand le joueur /l'ordinateur gagne ... Pouvez-vous m'aider s'ils vous plaient ?
____________________
Si le meilleurs langage de programmation existe, alors le Just Basic est loin devant.
Ne me tappez pas dessus ! Je débute
Si le meilleurs langage de programmation existe, alors le Just Basic est loin devant.
Ne me tappez pas dessus ! Je débute

Web
Et maintenant j'ai pleins d'erreurs de #main avec ce code
Code :
Help please

Code :
randomize 0.5
dim ROW(12) 'arrays are larger, to hold empty margins
dim B(11,12)'only indices 3-9 are used
global DIFFICULTY : DIFFICULTY = 3 'default difficulty
global MOVE
for i = 1 to 40 : separator$ = separator$+"__" : next
'read texts
global COMPUTERTHINKS
read COMPUTERTHINKS
dim compThink$(COMPUTERTHINKS)
for i = 1 to COMPUTERTHINKS : read a$ : compThink$(i) = a$ : next
global YOURTURN
read YOURTURN
dim makeYourMove$(YOURTURN)
for i = 1 to YOURTURN : read a$ : makeYourMove$(i) = a$ : next
global HUMANWIN
read HUMANWIN
dim youWin$(HUMANWIN)
for i = 1 to HUMANWIN : read a$ : youWin$(i) = a$ : next
global COMPUTERWIN
read COMPUTERWIN
dim compWin$(COMPUTERWIN)
for i = 1 to COMPUTERWIN : read a$ : compWin$(i) = a$ : next
global DRAW
read DRAW
dim drawMessage$(DRAW)
for i = 1 to DRAW : read a$ : drawMessage$(i) = a$ : next
nomainwin
WindowWidth = 552
WindowHeight = 437
UpperLeftX=int((DisplayWidth-WindowWidth)/3)
UpperLeftY=int((DisplayHeight-WindowHeight)/4)
graphicbox #main.graph, 22, 6, 385, 330
' button #main.button1, "1", RowButton, UL, 22, 341, 48, 25
' button #main.button2, "2", RowButton, UL, 78, 341, 48, 25
' button #main.button3, "3", RowButton, UL, 134, 341, 48, 25
' button #main.button4, "4", RowButton, UL, 190, 341, 48, 25
' button #main.button5, "5", RowButton, UL, 246, 341, 48, 25
' button #main.button6, "6", RowButton, UL, 302, 341, 48, 25
' button #main.button7, "7", RowButton, UL, 358, 341, 48, 25
button #main.new, "Nouveau jeu", [newGame], UL, 414, 21, 112, 25
button #main.difficulty, "Difficulté", GetDifficulty, UL, 414, 56, 112, 25
button #main.quit, "Quitter", quit, UL, 414, 291, 112, 25
button #main.skip, "Démarrer le jeu", [CompStart], UL, 414, 161, 112, 25
button #main.about, "Aide/A propos", About, UL, 414, 256, 112, 25
statictext #main, separator$, 1, 366, 546, 18
statictext #main.info, "", 4, 385, 548, 18
open "Puissance 4" for window_nf as #main
print #main.graph,"down"
print #main, "trapclose quit"
print #main, "font ms_sans_serif 10"
#main.graph "when leftButtonDown RowButton"
' wait
[newGame]
#main.info, "Selectionner le niveau de dificulté ou appuyez sur : démarrer le jeu "
redim ROW(12)
redim B(11,12)
MOVE = 0
call DrawEmptyGrid
for i = 3 to 9
ROW(i) = 2 'row is "empty", 3 is first level
' h$ = "#main.button"+str$(i-2)
' #h$, "!enable" 'enable all buttons
next i
#main.skip, "!enable"
wait
sub GetDifficulty h$
WindowWidth = 208
WindowHeight = 230
' UpperLeftX=int((DisplayWidth-WindowWidth)/2)
' UpperLeftY=int((DisplayHeight-WindowHeight)/2)
groupbox #difficulty, "Selectionnez le niveau de dificulté:", 14, 11, 168, 180
radiobutton #difficulty.rb1, "Très facile", [dummy], [dummy], 38, 41, 72, 20
radiobutton #difficulty.rb2, "Facile", [dummy], [dummy], 38, 66, 48, 20
radiobutton #difficulty.rb3, "Normal", [dummy], [dummy], 38, 91, 64, 20
radiobutton #difficulty.rb4, "Dificile", [dummy], [dummy], 38, 116, 60, 20
button #difficulty.default, "Valider", [difficultyOk], UL, 54, 146, 80, 25
open "Niveau" for dialog_nf_modal as #difficulty
print #difficulty, "trapclose [difficultyOk]"
h$ = "#difficulty.rb"+str$(DIFFICULTY)
#h$, "set"
wait
[dummy]
wait
[difficultyOk]
for i = 1 to 4
h$ = "#difficulty.rb"+str$(i)
#h$, "value? a$"
if a$ = "set" then DIFFICULTY = i
next i
close #difficulty
end sub
[CompStart]
#main.skip, "!disable"
call CompMove DIFFICULTY
wait
sub DrawEmptyGrid
#main.graph, "cls; fill lightgray; color darkgray; size 2"
for i = 1 to 6
#main.graph, "line "; i*55-1; " 0 "; i*55-1; " 384"
next i
for i = 1 to 5
#main.graph, "line 0 "; i*55-1; " 384 "; i*55-1
next i
#main.graph, "flush"
end sub
sub DrawMove x, y
x = x-2
y = 9-y
#main.graph, "place "; x*55-28; " "; y*55-28
#main.graph, "circlefilled 24; flush"
end sub
sub RowButton handle$, mx, my
#main.skip, "!disable"
' n = val(right$(handle$,1))+2
n = int(mx/(385/7))+3
ROW(n) = ROW(n)+1
B(ROW(n), n) = 1
#main.graph, "color darkblue; backcolor darkblue"
MOVE = MOVE+1
call DrawMove n, ROW(n)
'check human move
MOVE = CheckWin(MOVE, 1, ROW(n), n)
if MOVE < 42 then call CompMove DIFFICULTY
MOVE = MOVE+1
end sub
sub quit handle$
close #main
end
end sub
sub About handle$
s$ = "Pour jouer : "
s2$ = "Vous devez selectionner le niveau ou cliquer sur démarrer le jeu."
s3$ = " Puis le but sera d'aligner 4 jetons horizontalement, verticalement ou diagonalement."
s4$ = " Mais gare à l'ordinateur ..."
s6$ = " Ce logiciel est traduis par alex877"
WindowWidth = 384
WindowHeight = 336
' UpperLeftX=int((DisplayWidth-WindowWidth)/2)
' UpperLeftY=int((DisplayHeight-WindowHeight)/2)
groupbox #about.frame, "Comment jouer", 22, 16, 336, 240
statictext #about.text, "", 38, 46, 304, 200
button #about.default, "Ok", [aboutOk], UL, 126, 270, 122, 25
open "A propos de Puissance 4" for dialog_nf_modal as #about
#about, "trapclose [aboutOk]"
#about, "font ms_sans_serif 10"
#about.frame, "!font ms_sans_serif 12"
#about.text, s$ ; s2$ ; s3$ ; s4$ ; s6$
wait
[aboutOk]
close #about
end sub
sub CompMove depth
#main.info, compThink$(int(rnd(1)*COMPUTERTHINKS)+1)
' for i = 1 to 7
' h$ = "#main.button"+str$(i)
' #h$, "!disable"
' next i
n = BestMove(-1, depth)
ROW(n) = ROW(n)+1
B(ROW(n),n) = -1
' for i = 1 to 7
' if ROW(i+2) < 8 then
' h$ = "#main.button"+str$(i)
' ' #h$, "!enable"
' end if
' next i
#main.graph, "color darkred; backcolor darkred"
call DrawMove n, ROW(n)
#main.info, makeYourMove$(int(rnd(1)*YOURTURN)+1)
MOVE = CheckWin(MOVE, -1, ROW(n), n)
end sub
function IsWin$(pl, row, col)
if B(row-1,col)=pl and B(row-2,col)=pl and B(row-3,col)= pl then _
IsWin$ = str$(row-1); col; str$(row-2); col; str$(row-3); col
if B(row,col-1)=pl and B(row,col-2)=pl and B(row,col-3)= pl then _
IsWin$ = IsWin$; row; str$(col-1); row; str$(col-2); row; str$(col-3)
if B(row,col-1)=pl and B(row,col-2)=pl and B(row,col+1)= pl then _
IsWin$ = IsWin$; row; str$(col-1); row; str$(col-2); row; str$(col+1)
if B(row,col-1)=pl and B(row,col+1)=pl and B(row,col+2)= pl then _
IsWin$ = IsWin$; row; str$(col-1); row; str$(col+1); row; str$(col+2)
if B(row,col+1)=pl and B(row,col+2)=pl and B(row,col+3)= pl then _
IsWin$ = IsWin$; row; str$(col+1); row; str$(col+2); row; str$(col+3)
if B(row+3,col-3)=pl and B(row+2,col-2)=pl and B(row+1,col-1)= pl then _
IsWin$ = IsWin$; str$(row+3); str$(col-3); str$(row+2); str$(col-2); str$(row+1); str$(col-1)
if B(row+2,col-2)=pl and B(row+1,col-1)=pl and B(row-1,col+1)= pl then _
IsWin$ = IsWin$; str$(row+2); str$(col-2); str$(row+1); str$(col-1); str$(row-1); str$(col+1)
if B(row+1,col-1)=pl and B(row-1,col+1)=pl and B(row-2,col+2)= pl then _
IsWin$ = IsWin$; str$(row+1); str$(col-1); str$(row-1); str$(col+1); str$(row-2); str$(col+2)
if B(row-1,col+1)=pl and B(row-2,col+2)=pl and B(row-3,col+3)= pl then _
IsWin$ = IsWin$; str$(row-1); str$(col+1); str$(row-2); str$(col+2); str$(row-3); str$(col+3)
if B(row-3,col-3)=pl and B(row-2,col-2)=pl and B(row-1,col-1)= pl then _
IsWin$ = IsWin$; str$(row-3); str$(col-3); str$(row-2); str$(col-2); str$(row-1); str$(col-1)
if B(row-2,col-2)=pl and B(row-1,col-1)=pl and B(row+1,col+1)= pl then _
IsWin$ = IsWin$; str$(row-2); str$(col-2); str$(row-1); str$(col-1); str$(row+1); str$(col+1)
if B(row-1,col-1)=pl and B(row+1,col+1)=pl and B(row+2,col+2)= pl then _
IsWin$ = IsWin$; str$(row-1); str$(col-1); str$(row+1); str$(col+1); str$(row+2); str$(col+2)
if B(row+1,col+1)=pl and B(row+2,col+2)=pl and B(row+3,col+3)= pl then _
IsWin$ = IsWin$; str$(row+1); str$(col+1); str$(row+2); str$(col+2); str$(row+3); str$(col+3)
if IsWin$ <> "" then IsWin$ = str$(row); str$(col); IsWin$
end function
function CheckWin(CheckWin, player, row, col)
s$ = IsWin$(player, row, col)
if s$ <> "" then
CheckWin = 42
if player = 1 then
#main.info, youWin$(int(rnd(1)*HUMANWIN)+1)
#main.graph, "color blue; backcolor blue"
else
#main.info, compWin$(int(rnd(1)*COMPUTERWIN)+1)
#main.graph, "color red; backcolor red"
end if
for i = 1 to len(s$) step 2
x = val(mid$(s$, i, 1))
y = val(mid$(s$, i+1, 1))
call DrawMove y, x
next i
else
if CheckWin = 42 then #main.info, drawMessage$(int(rnd(1)*DRAW)+1)
end if
' if CheckWin = 42 then
' for i = 1 to 7
' h$ = "#main.button"+str$(i)
' ' #h$, "!disable"
' next i
' end if
end function
function GetValue(player, depth, row, column)
pl = -1*player
if (B(row-1,column)=pl and B(row-2,column)=pl and B(row-3,column)= pl) or _
(B(row,column-1)=pl and B(row,column-2)=pl and B(row,column-3)= pl) or _
(B(row,column-1)=pl and B(row,column-2)=pl and B(row,column+1)= pl) or _
(B(row,column-1)=pl and B(row,column+1)=pl and B(row,column+2)= pl) or _
(B(row,column+1)=pl and B(row,column+2)=pl and B(row,column+3)= pl) or _
(B(row+3,column-3)=pl and B(row+2,column-2)=pl and B(row+1,column-1)= pl) or _
(B(row+2,column-2)=pl and B(row+1,column-1)=pl and B(row-1,column+1)= pl) or _
(B(row+1,column-1)=pl and B(row-1,column+1)=pl and B(row-2,column+2)= pl) or _
(B(row-1,column+1)=pl and B(row-2,column+2)=pl and B(row-3,column+3)= pl) or _
(B(row-3,column-3)=pl and B(row-2,column-2)=pl and B(row-1,column-1)= pl) or _
(B(row-2,column-2)=pl and B(row-1,column-1)=pl and B(row+1,column+1)= pl) or _
(B(row-1,column-1)=pl and B(row+1,column+1)=pl and B(row+2,column+2)= pl) or _
(B(row+1,column+1)=pl and B(row+2,column+2)=pl and B(row+3,column+3)= pl) then
GetValue = -128
else
if depth = 0 then exit function
GetValue = -1000
for i = 3 to 9
if ROW(i) < 8 then
ROW(i) = ROW(i)+1
B(ROW(i), i) = player
value = -1*GetValue(-1*player, depth-1, ROW(i), i)/2
B(ROW(i), i) = 0
ROW(i) = ROW(i)-1
if value > GetValue then
GetValue = value
if value = 64 then exit for
end if
end if
next i
end if
end function
function BestMove(player, depth)
max = -1000
for i = 3 to 9
if ROW(i) < 8 then
ROW(i) = ROW(i)+1
B(ROW(i),i) = player
value = -1*GetValue(-1*player, depth, ROW(i), i)
B(ROW(i), i) = 0
ROW(i) = ROW(i)-1
if value > max then
max = value
BestList$ = str$(i)
if max = 128 then exit for
else
if value = max then BestList$ = BestList$+str$(i)
end if
end if
next i
'print BestList$, max
BestMove = val(mid$(BestList$, int(rnd(1)*len(BestList$))+1, 1))
end function
data 11
data "Hmm... Laisse moi réfléchir"
data "Tu joues bien, Je le sais!"
data "Je le sais, je vais gagner, laisse moi juste réfléchir."
data "Silence ! Je réfléchis"
data "Ne me frappe pas !"
data "Silence s'il vous plait, je gagne."
data "Je suis sur... je pense... dur..."
data "Alors tu n'y arrive pas ? x)"
data "Arrete d'aller trop vite, je ne suis plus."
data 11
data "I fear nothing! Gimme your best move!"
data "Wake me up when you're ready to make your move."
data "Show me what you've got!"
data "Your turn."
data "You can't win. Prove me wrong!"
data "I'll take a small nap while you figure THIS out!"
data "Think carefully! One little error and you're finished!"
data "Hit me real hard!"
data "You think it's a draw? I don't think so!"
data "I'd be surprised if you found a way to avoid defeat now!"
data "Take your time. I'll be surfing the web if you need me."
data 11
data "You win! Let's play again."
data "May thoughts were wandering... You win!"
data "I didn't see that coming!"
data "I bet you can't beat me again!"
data "Congratulations! You are almost as good as I."
data "That's not fair! I had something in my eye."
data "I can't believe it! You win!"
data "There was a magnetic storm! I couldn't think straight..."
data "It's impossible... Tell me how many moves you think ahead."
data "Amazing! You are my superhero."
data "I couldn't concentrate. You were moving the mouse all the time."
data 11
data "A big applause to the winner of the game!"
data "This should teach you a lesson. Never mess with me!"
data "Game over! You lose!"
data "We can play another one, but you're still going to lose..."
data "I bet you didn't see that one coming."
data "We can still be friends?!"
data "Ouch! This must hurt!"
data "So, what are you doing tonight?..."
data "Ladies and gentlemen, we have a winner. Guess who!"
data "That's another matter-over-mind victory..."
data "I'm the king of the world."
data 10
data "I offer draw."
data "Guess what! We're all out of moves."
data "Draw?! Yet, you were so close..."
data "You put me under a lot of pressure, but you couldn't break me!"
data "Hmm, only a draw... Surely you can do better than that!"
data "Press 'New Game'! We must find out who's better at this."
data "Uh, what happened?"
data "I told them we were going to need a larger board for this."
data "That's what I call wasted CPU cycles..."
data "I promise, next time I won't let you get away so easily."
Help please
____________________
Si le meilleurs langage de programmation existe, alors le Just Basic est loin devant.
Ne me tappez pas dessus ! Je débute
Si le meilleurs langage de programmation existe, alors le Just Basic est loin devant.
Ne me tappez pas dessus ! Je débute

Web
alex877:
Ce serait dans la function CheckWin( ).
Les couleurs durant le jeu sont darkblue et darkred.
Lorsque l'un des joueurs gagne, il affiche la chaine gagnante en blue ou red.
Mais c'est pas trop bien géré puisqu'on peut continuer de placer des pions malgrès la fin de partie... et surtout en cas d'égalité, si on clique ça plente !
@+
Edité par cassiope01 Le 28/07/2012 à 17h36
Par contre je ne trouve pas la ligne ou le programme décide quoi faire quand le joueur /l'ordinateur gagne ... Pouvez-vous m'aider s'ils vous plaient ?
Ce serait dans la function CheckWin( ).
Les couleurs durant le jeu sont darkblue et darkred.
Lorsque l'un des joueurs gagne, il affiche la chaine gagnante en blue ou red.
Mais c'est pas trop bien géré puisqu'on peut continuer de placer des pions malgrès la fin de partie... et surtout en cas d'égalité, si on clique ça plente !
@+
Edité par cassiope01 Le 28/07/2012 à 17h36
____________________
Devise Shadocks : "Mieux vaut mobiliser son intelligence pour des conneries, que mobiliser sa connerie pour des choses intelligentes"
Coluche disait : "C'est parce que la vitesse de la lumière est plus rapide que celle du son que certains peuvent paraîtrent brillants jusqu'à ce qu'ils ouvrent la bouche."
Devise Shadocks : "Mieux vaut mobiliser son intelligence pour des conneries, que mobiliser sa connerie pour des choses intelligentes"
Coluche disait : "C'est parce que la vitesse de la lumière est plus rapide que celle du son que certains peuvent paraîtrent brillants jusqu'à ce qu'ils ouvrent la bouche."
Web
alex877:
Le chiffre 11 ou 10 en tête des DATA est le nombre de lignes qu'il y a en dessous.
Tu en as que 9 dans le premier groupe.
@+
Edité par cassiope01 Le 28/07/2012 à 17h36
Et maintenant j'ai pleins d'erreurs de #main avec ce code
...
Help please

...
Help please
Le chiffre 11 ou 10 en tête des DATA est le nombre de lignes qu'il y a en dessous.
Tu en as que 9 dans le premier groupe.
@+
Edité par cassiope01 Le 28/07/2012 à 17h36
____________________
Devise Shadocks : "Mieux vaut mobiliser son intelligence pour des conneries, que mobiliser sa connerie pour des choses intelligentes"
Coluche disait : "C'est parce que la vitesse de la lumière est plus rapide que celle du son que certains peuvent paraîtrent brillants jusqu'à ce qu'ils ouvrent la bouche."
Devise Shadocks : "Mieux vaut mobiliser son intelligence pour des conneries, que mobiliser sa connerie pour des choses intelligentes"
Coluche disait : "C'est parce que la vitesse de la lumière est plus rapide que celle du son que certains peuvent paraîtrent brillants jusqu'à ce qu'ils ouvrent la bouche."
Web
Merci bien
____________________
Si le meilleurs langage de programmation existe, alors le Just Basic est loin devant.
Ne me tappez pas dessus ! Je débute
Si le meilleurs langage de programmation existe, alors le Just Basic est loin devant.
Ne me tappez pas dessus ! Je débute

Web
Deux derniere choses :
- Pourquoi le jeu à l'air plus dur en "Tres facile" qu'en "Dificile" ? ( je l'ai fat testé à quelqu'un d'autre, il le trouve aussi ). A moins que ce n'est qu'une impression ?
- Comment fait on pour "griser un bouton" et le dégriser apres ? ( j'aimerais griser le bouton "Nouveau jeu" tant qu'on a pas cliqué sur "Démarrer le jeu" )
- Pourquoi le jeu à l'air plus dur en "Tres facile" qu'en "Dificile" ? ( je l'ai fat testé à quelqu'un d'autre, il le trouve aussi ). A moins que ce n'est qu'une impression ?
- Comment fait on pour "griser un bouton" et le dégriser apres ? ( j'aimerais griser le bouton "Nouveau jeu" tant qu'on a pas cliqué sur "Démarrer le jeu" )
____________________
Si le meilleurs langage de programmation existe, alors le Just Basic est loin devant.
Ne me tappez pas dessus ! Je débute
Si le meilleurs langage de programmation existe, alors le Just Basic est loin devant.
Ne me tappez pas dessus ! Je débute

Web
A oui et :
- Est il possible de faire un système de "sauvegarde" de la partie ?
( je sais j'en demande beaucoup )
- Est il possible de faire un système de "sauvegarde" de la partie ?
( je sais j'en demande beaucoup )
____________________
Si le meilleurs langage de programmation existe, alors le Just Basic est loin devant.
Ne me tappez pas dessus ! Je débute
Si le meilleurs langage de programmation existe, alors le Just Basic est loin devant.
Ne me tappez pas dessus ! Je débute

Web
Command réference....A-B....Button
print #handle.ext, "!enable"
This causes the control to be enabled.-----Cela provoque le contrôle doit être activé.
print #handle.ext, "!disable"
This causes the control to be inactive and grayed-out.-----Cela provoque le contrôle d'être inactifs et grisés.
le print un coup il le faut, un coup il le faut pas....à tester
print #handle.ext, "!enable"
This causes the control to be enabled.-----Cela provoque le contrôle doit être activé.
print #handle.ext, "!disable"
This causes the control to be inactive and grayed-out.-----Cela provoque le contrôle d'être inactifs et grisés.
le print un coup il le faut, un coup il le faut pas....à tester
____________________
Roro
Roro
alex877:
Oui.
Regarde mon post du 25/07/12 à 18h56 où ncx est le nombre de cases en x et ncy est le nombre de cases en y.
Si tu veux vraiment programmer en JustBasic fait un effort pour trouver un minimum d'infos dans l'aide de JB : liste des commandes disponibles en JB, leur syntaxe, etc...
Edité par cassiope01 Le 29/07/2012 à 07h30
A oui et :
- Est il possible de faire un système de "sauvegarde" de la partie ?
( je sais j'en demande beaucoup )
- Est il possible de faire un système de "sauvegarde" de la partie ?
( je sais j'en demande beaucoup )
Oui.
Regarde mon post du 25/07/12 à 18h56 où ncx est le nombre de cases en x et ncy est le nombre de cases en y.
Si tu veux vraiment programmer en JustBasic fait un effort pour trouver un minimum d'infos dans l'aide de JB : liste des commandes disponibles en JB, leur syntaxe, etc...
Edité par cassiope01 Le 29/07/2012 à 07h30
____________________
Devise Shadocks : "Mieux vaut mobiliser son intelligence pour des conneries, que mobiliser sa connerie pour des choses intelligentes"
Coluche disait : "C'est parce que la vitesse de la lumière est plus rapide que celle du son que certains peuvent paraîtrent brillants jusqu'à ce qu'ils ouvrent la bouche."
Devise Shadocks : "Mieux vaut mobiliser son intelligence pour des conneries, que mobiliser sa connerie pour des choses intelligentes"
Coluche disait : "C'est parce que la vitesse de la lumière est plus rapide que celle du son que certains peuvent paraîtrent brillants jusqu'à ce qu'ils ouvrent la bouche."
Web
Merci bien. Et c'est une erreur ou le jeu à l'air plus dur en très facile qu'en dur ?
____________________
Si le meilleurs langage de programmation existe, alors le Just Basic est loin devant.
Ne me tappez pas dessus ! Je débute
Si le meilleurs langage de programmation existe, alors le Just Basic est loin devant.
Ne me tappez pas dessus ! Je débute

Web
Je ne peux pas te répondre : ce n'ai pas moi qui ai écrit ce jeu
Je ne sais même pas en quoi peuvent bien consister les différences de niveau
@+
Edité par cassiope01 Le 29/07/2012 à 10h33


Je ne sais même pas en quoi peuvent bien consister les différences de niveau

@+
Edité par cassiope01 Le 29/07/2012 à 10h33
____________________
Devise Shadocks : "Mieux vaut mobiliser son intelligence pour des conneries, que mobiliser sa connerie pour des choses intelligentes"
Coluche disait : "C'est parce que la vitesse de la lumière est plus rapide que celle du son que certains peuvent paraîtrent brillants jusqu'à ce qu'ils ouvrent la bouche."
Devise Shadocks : "Mieux vaut mobiliser son intelligence pour des conneries, que mobiliser sa connerie pour des choses intelligentes"
Coluche disait : "C'est parce que la vitesse de la lumière est plus rapide que celle du son que certains peuvent paraîtrent brillants jusqu'à ce qu'ils ouvrent la bouche."
Web
Ok.
Voilà le jeu avec système de sauvegarde ( qui marche pas ).
Code :
J'espère que vous pourrez m'aider.
Voilà le jeu avec système de sauvegarde ( qui marche pas ).
Code :
randomize 0.5
dim ROW(12) 'arrays are larger, to hold empty margins
dim B(11,12)'only indices 3-9 are used
global DIFFICULTY : DIFFICULTY = 3 'default difficulty
global MOVE
for i = 1 to 40 : separator$ = separator$+"__" : next
'read texts
global COMPUTERTHINKS
read COMPUTERTHINKS
dim compThink$(COMPUTERTHINKS)
for i = 1 to COMPUTERTHINKS : read a$ : compThink$(i) = a$ : next
global YOURTURN
read YOURTURN
dim makeYourMove$(YOURTURN)
for i = 1 to YOURTURN : read a$ : makeYourMove$(i) = a$ : next
global HUMANWIN
read HUMANWIN
dim youWin$(HUMANWIN)
for i = 1 to HUMANWIN : read a$ : youWin$(i) = a$ : next
global COMPUTERWIN
read COMPUTERWIN
dim compWin$(COMPUTERWIN)
for i = 1 to COMPUTERWIN : read a$ : compWin$(i) = a$ : next
global DRAW
read DRAW
dim drawMessage$(DRAW)
for i = 1 to DRAW : read a$ : drawMessage$(i) = a$ : next
nomainwin
WindowWidth = 552
WindowHeight = 437
UpperLeftX=int((DisplayWidth-WindowWidth)/3)
UpperLeftY=int((DisplayHeight-WindowHeight)/4)
graphicbox #main.graph, 22, 6, 385, 330
button #main.new, "Nouveau jeu", [newGame], UL, 414, 21, 112, 25
button #main.difficulty, "Difficulté", GetDifficulty, UL, 414, 56, 112, 25
button #main.sav, "Sauvegarde", [save], UL, 414, 90, 112, 2
button #main.sav, "Charger une partie", [load], UL, 414, 200, 112, 25
button #main.quit, "Quitter", quit, UL, 414, 291, 112, 25
button #main.skip, "Démarrer le jeu", [CompStart], UL, 414, 161, 112, 25
button #main.about, "Aide/A propos", About, UL, 414, 256, 112, 25
statictext #main, separator$, 1, 366, 546, 18
statictext #main.info, "", 4, 385, 548, 18
open "Puissance 4" for window_nf as #main
print #main.graph,"down"
print #main, "trapclose quit"
print #main, "font ms_sans_serif 10"
#main.graph "when leftButtonDown RowButton"
' wait
[newGame]
#main.info, "Selectionner le niveau de dificulté ou appuyez sur : démarrer le jeu "
redim ROW(12)
redim B(11,12)
MOVE = 0
call DrawEmptyGrid
for i = 3 to 9
ROW(i) = 2 'row is "empty", 3 is first level
' h$ = "#main.button"+str$(i-2)
' #h$, "!enable" 'enable all buttons
next i
#main.skip, "!enable"
wait
sub GetDifficulty h$
WindowWidth = 208
WindowHeight = 230
' UpperLeftX=int((DisplayWidth-WindowWidth)/2)
' UpperLeftY=int((DisplayHeight-WindowHeight)/2)
groupbox #difficulty, "Selectionnez le niveau de dificulté:", 14, 11, 168, 180
radiobutton #difficulty.rb1, "Très facile", [dummy], [dummy], 38, 41, 72, 20
radiobutton #difficulty.rb2, "Facile", [dummy], [dummy], 38, 66, 48, 20
radiobutton #difficulty.rb3, "Normal", [dummy], [dummy], 38, 91, 64, 20
radiobutton #difficulty.rb4, "Dificile", [dummy], [dummy], 38, 116, 60, 20
button #difficulty.default, "Valider", [difficultyOk], UL, 54, 146, 80, 25
open "Niveau" for dialog_nf_modal as #difficulty
print #difficulty, "trapclose [difficultyOk]"
h$ = "#difficulty.rb"+str$(DIFFICULTY)
#h$, "set"
wait
[dummy]
wait
[difficultyOk]
for i = 1 to 4
h$ = "#difficulty.rb"+str$(i)
#h$, "value? a$"
if a$ = "set" then DIFFICULTY = i
next i
close #difficulty
end sub
[CompStart]
#main.skip, "!disable"
call CompMove DIFFICULTY
wait
sub DrawEmptyGrid
#main.graph, "cls; fill lightgray; color darkgray; size 2"
for i = 1 to 6
#main.graph, "line "; i*55-1; " 0 "; i*55-1; " 384"
next i
for i = 1 to 5
#main.graph, "line 0 "; i*55-1; " 384 "; i*55-1
next i
#main.graph, "flush"
end sub
sub DrawMove x, y
x = x-2
y = 9-y
#main.graph, "place "; x*55-28; " "; y*55-28
#main.graph, "circlefilled 24; flush"
end sub
sub RowButton handle$, mx, my
#main.skip, "!disable"
' n = val(right$(handle$,1))+2
n = int(mx/(385/7))+3
ROW(n) = ROW(n)+1
B(ROW(n), n) = 1
#main.graph, "color darkblue; backcolor darkblue"
MOVE = MOVE+1
call DrawMove n, ROW(n)
'check human move
MOVE = CheckWin(MOVE, 1, ROW(n), n)
if MOVE < 42 then call CompMove DIFFICULTY
MOVE = MOVE+1
end sub
sub quit handle$
close #main
end
end sub
sub About handle$
s$ = "Pour jouer : "
s2$ = "Vous devez selectionner le niveau ou cliquer sur démarrer le jeu."
s3$ = " Puis le but sera d'aligner 4 jetons horizontalement, verticalement ou diagonalement."
s4$ = " Mais gare à l'ordinateur ..."
s6$ = " Ce logiciel est traduis par alex877"
WindowWidth = 384
WindowHeight = 336
' UpperLeftX=int((DisplayWidth-WindowWidth)/2)
' UpperLeftY=int((DisplayHeight-WindowHeight)/2)
groupbox #about.frame, "Comment jouer", 22, 16, 336, 240
statictext #about.text, "", 38, 46, 304, 200
button #about.default, "Ok", [aboutOk], UL, 126, 270, 122, 25
open "A propos de Puissance 4" for dialog_nf_modal as #about
#about, "trapclose [aboutOk]"
#about, "font ms_sans_serif 10"
#about.frame, "!font ms_sans_serif 12"
#about.text, s$ ; s2$ ; s3$ ; s4$ ; s6$
wait
[aboutOk]
close #about
end sub
sub CompMove depth
#main.info, compThink$(int(rnd(1)*COMPUTERTHINKS)+1)
' for i = 1 to 7
' h$ = "#main.button"+str$(i)
' #h$, "!disable"
' next i
n = BestMove(-1, depth)
ROW(n) = ROW(n)+1
B(ROW(n),n) = -1
' for i = 1 to 7
' if ROW(i+2) < 8 then
' h$ = "#main.button"+str$(i)
' ' #h$, "!enable"
' end if
' next i
#main.graph, "color darkred; backcolor darkred"
call DrawMove n, ROW(n)
#main.info, makeYourMove$(int(rnd(1)*YOURTURN)+1)
MOVE = CheckWin(MOVE, -1, ROW(n), n)
end sub
function IsWin$(pl, row, col)
if B(row-1,col)=pl and B(row-2,col)=pl and B(row-3,col)= pl then _
IsWin$ = str$(row-1); col; str$(row-2); col; str$(row-3); col
if B(row,col-1)=pl and B(row,col-2)=pl and B(row,col-3)= pl then _
IsWin$ = IsWin$; row; str$(col-1); row; str$(col-2); row; str$(col-3)
if B(row,col-1)=pl and B(row,col-2)=pl and B(row,col+1)= pl then _
IsWin$ = IsWin$; row; str$(col-1); row; str$(col-2); row; str$(col+1)
if B(row,col-1)=pl and B(row,col+1)=pl and B(row,col+2)= pl then _
IsWin$ = IsWin$; row; str$(col-1); row; str$(col+1); row; str$(col+2)
if B(row,col+1)=pl and B(row,col+2)=pl and B(row,col+3)= pl then _
IsWin$ = IsWin$; row; str$(col+1); row; str$(col+2); row; str$(col+3)
if B(row+3,col-3)=pl and B(row+2,col-2)=pl and B(row+1,col-1)= pl then _
IsWin$ = IsWin$; str$(row+3); str$(col-3); str$(row+2); str$(col-2); str$(row+1); str$(col-1)
if B(row+2,col-2)=pl and B(row+1,col-1)=pl and B(row-1,col+1)= pl then _
IsWin$ = IsWin$; str$(row+2); str$(col-2); str$(row+1); str$(col-1); str$(row-1); str$(col+1)
if B(row+1,col-1)=pl and B(row-1,col+1)=pl and B(row-2,col+2)= pl then _
IsWin$ = IsWin$; str$(row+1); str$(col-1); str$(row-1); str$(col+1); str$(row-2); str$(col+2)
if B(row-1,col+1)=pl and B(row-2,col+2)=pl and B(row-3,col+3)= pl then _
IsWin$ = IsWin$; str$(row-1); str$(col+1); str$(row-2); str$(col+2); str$(row-3); str$(col+3)
if B(row-3,col-3)=pl and B(row-2,col-2)=pl and B(row-1,col-1)= pl then _
IsWin$ = IsWin$; str$(row-3); str$(col-3); str$(row-2); str$(col-2); str$(row-1); str$(col-1)
if B(row-2,col-2)=pl and B(row-1,col-1)=pl and B(row+1,col+1)= pl then _
IsWin$ = IsWin$; str$(row-2); str$(col-2); str$(row-1); str$(col-1); str$(row+1); str$(col+1)
if B(row-1,col-1)=pl and B(row+1,col+1)=pl and B(row+2,col+2)= pl then _
IsWin$ = IsWin$; str$(row-1); str$(col-1); str$(row+1); str$(col+1); str$(row+2); str$(col+2)
if B(row+1,col+1)=pl and B(row+2,col+2)=pl and B(row+3,col+3)= pl then _
IsWin$ = IsWin$; str$(row+1); str$(col+1); str$(row+2); str$(col+2); str$(row+3); str$(col+3)
if IsWin$ <> "" then IsWin$ = str$(row); str$(col); IsWin$
end function
function CheckWin(CheckWin, player, row, col)
s$ = IsWin$(player, row, col)
if s$ <> "" then
CheckWin = 42
if player = 1 then
#main.info, youWin$(int(rnd(1)*HUMANWIN)+1)
#main.graph, "color blue; backcolor blue"
else
#main.info, compWin$(int(rnd(1)*COMPUTERWIN)+1)
#main.graph, "color red; backcolor red"
end if
for i = 1 to len(s$) step 2
x = val(mid$(s$, i, 1))
y = val(mid$(s$, i+1, 1))
call DrawMove y, x
next i
else
if CheckWin = 42 then #main.info, drawMessage$(int(rnd(1)*DRAW)+1)
end if
' if CheckWin = 42 then
' for i = 1 to 7
' h$ = "#main.button"+str$(i)
' ' #h$, "!disable"
' next i
' end if
end function
function GetValue(player, depth, row, column)
pl = -1*player
if (B(row-1,column)=pl and B(row-2,column)=pl and B(row-3,column)= pl) or _
(B(row,column-1)=pl and B(row,column-2)=pl and B(row,column-3)= pl) or _
(B(row,column-1)=pl and B(row,column-2)=pl and B(row,column+1)= pl) or _
(B(row,column-1)=pl and B(row,column+1)=pl and B(row,column+2)= pl) or _
(B(row,column+1)=pl and B(row,column+2)=pl and B(row,column+3)= pl) or _
(B(row+3,column-3)=pl and B(row+2,column-2)=pl and B(row+1,column-1)= pl) or _
(B(row+2,column-2)=pl and B(row+1,column-1)=pl and B(row-1,column+1)= pl) or _
(B(row+1,column-1)=pl and B(row-1,column+1)=pl and B(row-2,column+2)= pl) or _
(B(row-1,column+1)=pl and B(row-2,column+2)=pl and B(row-3,column+3)= pl) or _
(B(row-3,column-3)=pl and B(row-2,column-2)=pl and B(row-1,column-1)= pl) or _
(B(row-2,column-2)=pl and B(row-1,column-1)=pl and B(row+1,column+1)= pl) or _
(B(row-1,column-1)=pl and B(row+1,column+1)=pl and B(row+2,column+2)= pl) or _
(B(row+1,column+1)=pl and B(row+2,column+2)=pl and B(row+3,column+3)= pl) then
GetValue = -128
else
if depth = 0 then exit function
GetValue = -1000
for i = 3 to 9
if ROW(i) < 8 then
ROW(i) = ROW(i)+1
B(ROW(i), i) = player
value = -1*GetValue(-1*player, depth-1, ROW(i), i)/2
B(ROW(i), i) = 0
ROW(i) = ROW(i)-1
if value > GetValue then
GetValue = value
if value = 64 then exit for
end if
end if
next i
end if
end function
function BestMove(player, depth)
max = -1000
for i = 3 to 9
if ROW(i) < 8 then
ROW(i) = ROW(i)+1
B(ROW(i),i) = player
value = -1*GetValue(-1*player, depth, ROW(i), i)
B(ROW(i), i) = 0
ROW(i) = ROW(i)-1
if value > max then
max = value
BestList$ = str$(i)
if max = 128 then exit for
else
if value = max then BestList$ = BestList$+str$(i)
end if
end if
next i
'print BestList$, max
BestMove = val(mid$(BestList$, int(rnd(1)*len(BestList$))+1, 1))
end function
data 9
data "Hmm... Laisse moi réfléchir"
data "Tu joues bien, Je le sais!"
data "Je le sais, je vais gagner, laisse moi juste réfléchir."
data "Silence ! Je réfléchis"
data "Ne me frappe pas !"
data "Silence s'il vous plait, je gagne."
data "Je suis sur... je pense... dur..."
data "Alors tu n'y arrive pas ? x)"
data "Arrete d'aller trop vite, je ne suis plus."
data 11
data "I fear nothing! Gimme your best move!"
data "Wake me up when you're ready to make your move."
data "Show me what you've got!"
data "Your turn."
data "You can't win. Prove me wrong!"
data "I'll take a small nap while you figure THIS out!"
data "Think carefully! One little error and you're finished!"
data "Hit me real hard!"
data "You think it's a draw? I don't think so!"
data "I'd be surprised if you found a way to avoid defeat now!"
data "Take your time. I'll be surfing the web if you need me."
data 11
data "You win! Let's play again."
data "May thoughts were wandering... You win!"
data "I didn't see that coming!"
data "I bet you can't beat me again!"
data "Congratulations! You are almost as good as I."
data "That's not fair! I had something in my eye."
data "I can't believe it! You win!"
data "There was a magnetic storm! I couldn't think straight..."
data "It's impossible... Tell me how many moves you think ahead."
data "Amazing! You are my superhero."
data "I couldn't concentrate. You were moving the mouse all the time."
data 11
data "A big applause to the winner of the game!"
data "This should teach you a lesson. Never mess with me!"
data "Game over! You lose!"
data "We can play another one, but you're still going to lose..."
data "I bet you didn't see that one coming."
data "We can still be friends?!"
data "Ouch! This must hurt!"
data "So, what are you doing tonight?..."
data "Ladies and gentlemen, we have a winner. Guess who!"
data "That's another matter-over-mind victory..."
data "I'm the king of the world."
data 10
data "I offer draw."
data "Guess what! We're all out of moves."
data "Draw?! Yet, you were so close..."
data "You put me under a lot of pressure, but you couldn't break me!"
data "Hmm, only a draw... Surely you can do better than that!"
data "Press 'New Game'! We must find out who's better at this."
data "Uh, what happened?"
data "I told them we were going to need a larger board for this."
data "That's what I call wasted CPU cycles..."
data "I promise, next time I won't let you get away so easily."
[load]
if fileExists(DefaultDir$, "save.txt") then
open "save.txt" for input as #grid
for y=7 to ncy
LINE INPUT #grid, grid$
for x=6 to ncx
cas(x,y)=val(mid$(grid$,x,1))
next
next
close #grid
else
notice "No file 'Map.txt'...!"
end if
function fileExists(path$, filename$)
'DIM info$(10,10) 'must have been declared at the start of the code.
files path$, filename$, info$() ' path$ = DefaultDir$ generally...
fileExists = val(info$(7, 6)) '<> 0 if true
end function
[save]
open "save.txt" for output as #grid
for y=7 to ncy
grid$=""
for x=6 to ncx
grid$ = grid$+str$(cas(x,y))
next
#grid, grid$
next
close #grid
return
J'espère que vous pourrez m'aider.
____________________
Si le meilleurs langage de programmation existe, alors le Just Basic est loin devant.
Ne me tappez pas dessus ! Je débute
Si le meilleurs langage de programmation existe, alors le Just Basic est loin devant.
Ne me tappez pas dessus ! Je débute

Web
Et voilà le jeu avec le boutton Sauvegarde pas écrasé et les niveaux "rereglé" ( je pense ).
Code :
Mais toujours la sauvegarde qui marche pas
Code :
randomize 0.5
dim ROW(12) 'arrays are larger, to hold empty margins
dim B(11,12)'only indices 3-9 are used
global DIFFICULTY : DIFFICULTY = 3 'default difficulty
global MOVE
for i = 1 to 40 : separator$ = separator$+"__" : next
'read texts
global COMPUTERTHINKS
read COMPUTERTHINKS
dim compThink$(COMPUTERTHINKS)
for i = 1 to COMPUTERTHINKS : read a$ : compThink$(i) = a$ : next
global YOURTURN
read YOURTURN
dim makeYourMove$(YOURTURN)
for i = 1 to YOURTURN : read a$ : makeYourMove$(i) = a$ : next
global HUMANWIN
read HUMANWIN
dim youWin$(HUMANWIN)
for i = 1 to HUMANWIN : read a$ : youWin$(i) = a$ : next
global COMPUTERWIN
read COMPUTERWIN
dim compWin$(COMPUTERWIN)
for i = 1 to COMPUTERWIN : read a$ : compWin$(i) = a$ : next
global DRAW
read DRAW
dim drawMessage$(DRAW)
for i = 1 to DRAW : read a$ : drawMessage$(i) = a$ : next
nomainwin
WindowWidth = 552
WindowHeight = 437
UpperLeftX=int((DisplayWidth-WindowWidth)/3)
UpperLeftY=int((DisplayHeight-WindowHeight)/4)
graphicbox #main.graph, 22, 6, 385, 330
button #main.new, "Nouveau jeu", [newGame], UL, 414, 21, 112, 25
button #main.difficulty, "Difficulté", GetDifficulty, UL, 414, 56, 112, 25
button #main.sav, "Sauvegarde", [save], UL, 414, 90, 112, 25
button #main.sav, "Charger une partie", [load], UL, 414, 200, 112, 25
button #main.quit, "Quitter", quit, UL, 414, 291, 112, 25
button #main.skip, "Démarrer le jeu", [CompStart], UL, 414, 161, 112, 25
button #main.about, "Aide/A propos", About, UL, 414, 256, 112, 25
statictext #main, separator$, 1, 366, 546, 18
statictext #main.info, "", 4, 385, 548, 18
open "Puissance 4" for window_nf as #main
print #main.graph,"down"
print #main, "trapclose quit"
print #main, "font ms_sans_serif 10"
#main.graph "when leftButtonDown RowButton"
' wait
[newGame]
#main.info, "Selectionner le niveau de dificulté ou appuyez sur : démarrer le jeu "
redim ROW(12)
redim B(11,12)
MOVE = 0
call DrawEmptyGrid
for i = 3 to 9
ROW(i) = 2 'row is "empty", 3 is first level
' h$ = "#main.button"+str$(i-2)
' #h$, "!enable" 'enable all buttons
next i
#main.skip, "!enable"
wait
sub GetDifficulty h$
WindowWidth = 208
WindowHeight = 230
' UpperLeftX=int((DisplayWidth-WindowWidth)/2)
' UpperLeftY=int((DisplayHeight-WindowHeight)/2)
groupbox #difficulty, "Selectionnez le niveau de dificulté:", 14, 11, 168, 180
radiobutton #difficulty.rb4, "Très facile", [dummy], [dummy], 38, 41, 72, 20
radiobutton #difficulty.rb2, "Facile", [dummy], [dummy], 38, 66, 48, 20
radiobutton #difficulty.rb3, "Normal", [dummy], [dummy], 38, 91, 64, 20
radiobutton #difficulty.rb1, "Dificile", [dummy], [dummy], 38, 116, 60, 20
button #difficulty.default, "Valider", [difficultyOk], UL, 54, 146, 80, 25
open "Niveau" for dialog_nf_modal as #difficulty
print #difficulty, "trapclose [difficultyOk]"
h$ = "#difficulty.rb"+str$(DIFFICULTY)
#h$, "set"
wait
[dummy]
wait
[difficultyOk]
for i = 1 to 4
h$ = "#difficulty.rb"+str$(i)
#h$, "value? a$"
if a$ = "set" then DIFFICULTY = i
next i
close #difficulty
end sub
[CompStart]
#main.skip, "!disable"
call CompMove DIFFICULTY
wait
sub DrawEmptyGrid
#main.graph, "cls; fill lightgray; color darkgray; size 2"
for i = 1 to 6
#main.graph, "line "; i*55-1; " 0 "; i*55-1; " 384"
next i
for i = 1 to 5
#main.graph, "line 0 "; i*55-1; " 384 "; i*55-1
next i
#main.graph, "flush"
end sub
sub DrawMove x, y
x = x-2
y = 9-y
#main.graph, "place "; x*55-28; " "; y*55-28
#main.graph, "circlefilled 24; flush"
end sub
sub RowButton handle$, mx, my
#main.skip, "!disable"
' n = val(right$(handle$,1))+2
n = int(mx/(385/7))+3
ROW(n) = ROW(n)+1
B(ROW(n), n) = 1
#main.graph, "color darkblue; backcolor darkblue"
MOVE = MOVE+1
call DrawMove n, ROW(n)
'check human move
MOVE = CheckWin(MOVE, 1, ROW(n), n)
if MOVE < 42 then call CompMove DIFFICULTY
MOVE = MOVE+1
end sub
sub quit handle$
close #main
end
end sub
sub About handle$
s$ = "Pour jouer : "
s2$ = "Vous devez selectionner le niveau ou cliquer sur démarrer le jeu."
s3$ = " Puis le but sera d'aligner 4 jetons horizontalement, verticalement ou diagonalement."
s4$ = " Mais gare à l'ordinateur ..."
s6$ = " Ce logiciel est traduis par alex877"
WindowWidth = 384
WindowHeight = 336
' UpperLeftX=int((DisplayWidth-WindowWidth)/2)
' UpperLeftY=int((DisplayHeight-WindowHeight)/2)
groupbox #about.frame, "Comment jouer", 22, 16, 336, 240
statictext #about.text, "", 38, 46, 304, 200
button #about.default, "Ok", [aboutOk], UL, 126, 270, 122, 25
open "A propos de Puissance 4" for dialog_nf_modal as #about
#about, "trapclose [aboutOk]"
#about, "font ms_sans_serif 10"
#about.frame, "!font ms_sans_serif 12"
#about.text, s$ ; s2$ ; s3$ ; s4$ ; s6$
wait
[aboutOk]
close #about
end sub
sub CompMove depth
#main.info, compThink$(int(rnd(1)*COMPUTERTHINKS)+1)
' for i = 1 to 7
' h$ = "#main.button"+str$(i)
' #h$, "!disable"
' next i
n = BestMove(-1, depth)
ROW(n) = ROW(n)+1
B(ROW(n),n) = -1
' for i = 1 to 7
' if ROW(i+2) < 8 then
' h$ = "#main.button"+str$(i)
' ' #h$, "!enable"
' end if
' next i
#main.graph, "color darkred; backcolor darkred"
call DrawMove n, ROW(n)
#main.info, makeYourMove$(int(rnd(1)*YOURTURN)+1)
MOVE = CheckWin(MOVE, -1, ROW(n), n)
end sub
function IsWin$(pl, row, col)
if B(row-1,col)=pl and B(row-2,col)=pl and B(row-3,col)= pl then _
IsWin$ = str$(row-1); col; str$(row-2); col; str$(row-3); col
if B(row,col-1)=pl and B(row,col-2)=pl and B(row,col-3)= pl then _
IsWin$ = IsWin$; row; str$(col-1); row; str$(col-2); row; str$(col-3)
if B(row,col-1)=pl and B(row,col-2)=pl and B(row,col+1)= pl then _
IsWin$ = IsWin$; row; str$(col-1); row; str$(col-2); row; str$(col+1)
if B(row,col-1)=pl and B(row,col+1)=pl and B(row,col+2)= pl then _
IsWin$ = IsWin$; row; str$(col-1); row; str$(col+1); row; str$(col+2)
if B(row,col+1)=pl and B(row,col+2)=pl and B(row,col+3)= pl then _
IsWin$ = IsWin$; row; str$(col+1); row; str$(col+2); row; str$(col+3)
if B(row+3,col-3)=pl and B(row+2,col-2)=pl and B(row+1,col-1)= pl then _
IsWin$ = IsWin$; str$(row+3); str$(col-3); str$(row+2); str$(col-2); str$(row+1); str$(col-1)
if B(row+2,col-2)=pl and B(row+1,col-1)=pl and B(row-1,col+1)= pl then _
IsWin$ = IsWin$; str$(row+2); str$(col-2); str$(row+1); str$(col-1); str$(row-1); str$(col+1)
if B(row+1,col-1)=pl and B(row-1,col+1)=pl and B(row-2,col+2)= pl then _
IsWin$ = IsWin$; str$(row+1); str$(col-1); str$(row-1); str$(col+1); str$(row-2); str$(col+2)
if B(row-1,col+1)=pl and B(row-2,col+2)=pl and B(row-3,col+3)= pl then _
IsWin$ = IsWin$; str$(row-1); str$(col+1); str$(row-2); str$(col+2); str$(row-3); str$(col+3)
if B(row-3,col-3)=pl and B(row-2,col-2)=pl and B(row-1,col-1)= pl then _
IsWin$ = IsWin$; str$(row-3); str$(col-3); str$(row-2); str$(col-2); str$(row-1); str$(col-1)
if B(row-2,col-2)=pl and B(row-1,col-1)=pl and B(row+1,col+1)= pl then _
IsWin$ = IsWin$; str$(row-2); str$(col-2); str$(row-1); str$(col-1); str$(row+1); str$(col+1)
if B(row-1,col-1)=pl and B(row+1,col+1)=pl and B(row+2,col+2)= pl then _
IsWin$ = IsWin$; str$(row-1); str$(col-1); str$(row+1); str$(col+1); str$(row+2); str$(col+2)
if B(row+1,col+1)=pl and B(row+2,col+2)=pl and B(row+3,col+3)= pl then _
IsWin$ = IsWin$; str$(row+1); str$(col+1); str$(row+2); str$(col+2); str$(row+3); str$(col+3)
if IsWin$ <> "" then IsWin$ = str$(row); str$(col); IsWin$
end function
function CheckWin(CheckWin, player, row, col)
s$ = IsWin$(player, row, col)
if s$ <> "" then
CheckWin = 42
if player = 1 then
#main.info, youWin$(int(rnd(1)*HUMANWIN)+1)
#main.graph, "color blue; backcolor blue"
else
#main.info, compWin$(int(rnd(1)*COMPUTERWIN)+1)
#main.graph, "color red; backcolor red"
end if
for i = 1 to len(s$) step 2
x = val(mid$(s$, i, 1))
y = val(mid$(s$, i+1, 1))
call DrawMove y, x
next i
else
if CheckWin = 42 then #main.info, drawMessage$(int(rnd(1)*DRAW)+1)
end if
' if CheckWin = 42 then
' for i = 1 to 7
' h$ = "#main.button"+str$(i)
' ' #h$, "!disable"
' next i
' end if
end function
function GetValue(player, depth, row, column)
pl = -1*player
if (B(row-1,column)=pl and B(row-2,column)=pl and B(row-3,column)= pl) or _
(B(row,column-1)=pl and B(row,column-2)=pl and B(row,column-3)= pl) or _
(B(row,column-1)=pl and B(row,column-2)=pl and B(row,column+1)= pl) or _
(B(row,column-1)=pl and B(row,column+1)=pl and B(row,column+2)= pl) or _
(B(row,column+1)=pl and B(row,column+2)=pl and B(row,column+3)= pl) or _
(B(row+3,column-3)=pl and B(row+2,column-2)=pl and B(row+1,column-1)= pl) or _
(B(row+2,column-2)=pl and B(row+1,column-1)=pl and B(row-1,column+1)= pl) or _
(B(row+1,column-1)=pl and B(row-1,column+1)=pl and B(row-2,column+2)= pl) or _
(B(row-1,column+1)=pl and B(row-2,column+2)=pl and B(row-3,column+3)= pl) or _
(B(row-3,column-3)=pl and B(row-2,column-2)=pl and B(row-1,column-1)= pl) or _
(B(row-2,column-2)=pl and B(row-1,column-1)=pl and B(row+1,column+1)= pl) or _
(B(row-1,column-1)=pl and B(row+1,column+1)=pl and B(row+2,column+2)= pl) or _
(B(row+1,column+1)=pl and B(row+2,column+2)=pl and B(row+3,column+3)= pl) then
GetValue = -128
else
if depth = 0 then exit function
GetValue = -1000
for i = 3 to 9
if ROW(i) < 8 then
ROW(i) = ROW(i)+1
B(ROW(i), i) = player
value = -1*GetValue(-1*player, depth-1, ROW(i), i)/2
B(ROW(i), i) = 0
ROW(i) = ROW(i)-1
if value > GetValue then
GetValue = value
if value = 64 then exit for
end if
end if
next i
end if
end function
function BestMove(player, depth)
max = -1000
for i = 3 to 9
if ROW(i) < 8 then
ROW(i) = ROW(i)+1
B(ROW(i),i) = player
value = -1*GetValue(-1*player, depth, ROW(i), i)
B(ROW(i), i) = 0
ROW(i) = ROW(i)-1
if value > max then
max = value
BestList$ = str$(i)
if max = 128 then exit for
else
if value = max then BestList$ = BestList$+str$(i)
end if
end if
next i
'print BestList$, max
BestMove = val(mid$(BestList$, int(rnd(1)*len(BestList$))+1, 1))
end function
data 9
data "Hmm... Laisse moi réfléchir"
data "Tu joues bien, Je le sais!"
data "Je le sais, je vais gagner, laisse moi juste réfléchir."
data "Silence ! Je réfléchis"
data "Ne me frappe pas !"
data "Silence s'il vous plait, je gagne."
data "Je suis sur... je pense... dur..."
data "Alors tu n'y arrive pas ? x)"
data "Arrete d'aller trop vite, je ne suis plus."
data 11
data "I fear nothing! Gimme your best move!"
data "Wake me up when you're ready to make your move."
data "Show me what you've got!"
data "Your turn."
data "You can't win. Prove me wrong!"
data "I'll take a small nap while you figure THIS out!"
data "Think carefully! One little error and you're finished!"
data "Hit me real hard!"
data "You think it's a draw? I don't think so!"
data "I'd be surprised if you found a way to avoid defeat now!"
data "Take your time. I'll be surfing the web if you need me."
data 11
data "You win! Let's play again."
data "May thoughts were wandering... You win!"
data "I didn't see that coming!"
data "I bet you can't beat me again!"
data "Congratulations! You are almost as good as I."
data "That's not fair! I had something in my eye."
data "I can't believe it! You win!"
data "There was a magnetic storm! I couldn't think straight..."
data "It's impossible... Tell me how many moves you think ahead."
data "Amazing! You are my superhero."
data "I couldn't concentrate. You were moving the mouse all the time."
data 11
data "A big applause to the winner of the game!"
data "This should teach you a lesson. Never mess with me!"
data "Game over! You lose!"
data "We can play another one, but you're still going to lose..."
data "I bet you didn't see that one coming."
data "We can still be friends?!"
data "Ouch! This must hurt!"
data "So, what are you doing tonight?..."
data "Ladies and gentlemen, we have a winner. Guess who!"
data "That's another matter-over-mind victory..."
data "I'm the king of the world."
data 10
data "I offer draw."
data "Guess what! We're all out of moves."
data "Draw?! Yet, you were so close..."
data "You put me under a lot of pressure, but you couldn't break me!"
data "Hmm, only a draw... Surely you can do better than that!"
data "Press 'New Game'! We must find out who's better at this."
data "Uh, what happened?"
data "I told them we were going to need a larger board for this."
data "That's what I call wasted CPU cycles..."
data "I promise, next time I won't let you ge et away so easily."
Mais toujours la sauvegarde qui marche pas

____________________
Si le meilleurs langage de programmation existe, alors le Just Basic est loin devant.
Ne me tappez pas dessus ! Je débute
Si le meilleurs langage de programmation existe, alors le Just Basic est loin devant.
Ne me tappez pas dessus ! Je débute

Web
casiope01 s'il te plait peux tu m'aider pour le système de sauvegarde ? ( ou quelqu'un d'autre qui sait ).
____________________
Si le meilleurs langage de programmation existe, alors le Just Basic est loin devant.
Ne me tappez pas dessus ! Je débute
Si le meilleurs langage de programmation existe, alors le Just Basic est loin devant.
Ne me tappez pas dessus ! Je débute

Web
Et voilà une petite mise à jour ( mais toujours sans la sauvegarde ) :
Code :
Code :
randomize 0.5
dim ROW(12) 'arrays are larger, to hold empty margins
dim B(11,12)'only indices 3-9 are used
global DIFFICULTY : DIFFICULTY = 3 'default difficulty
global MOVE
for i = 1 to 40 : separator$ = separator$+"__" : next
'read texts
global COMPUTERTHINKS
read COMPUTERTHINKS
dim compThink$(COMPUTERTHINKS)
for i = 1 to COMPUTERTHINKS : read a$ : compThink$(i) = a$ : next
global YOURTURN
read YOURTURN
dim makeYourMove$(YOURTURN)
for i = 1 to YOURTURN : read a$ : makeYourMove$(i) = a$ : next
global HUMANWIN
read HUMANWIN
dim youWin$(HUMANWIN)
for i = 1 to HUMANWIN : read a$ : youWin$(i) = a$ : next
global COMPUTERWIN
read COMPUTERWIN
dim compWin$(COMPUTERWIN)
for i = 1 to COMPUTERWIN : read a$ : compWin$(i) = a$ : next
global DRAW
read DRAW
dim drawMessage$(DRAW)
for i = 1 to DRAW : read a$ : drawMessage$(i) = a$ : next
nomainwin
WindowWidth = 552
WindowHeight = 437
UpperLeftX=int((DisplayWidth-WindowWidth)/3)
UpperLeftY=int((DisplayHeight-WindowHeight)/4)
graphicbox #main.graph, 22, 6, 385, 330
button #main.new, "Nouveau jeu", [newGame], UL, 414, 21, 112, 25
button #main.difficulty, "Difficulté", GetDifficulty, UL, 414, 56, 112, 25
button #main.sav, "Aide", About, UL, 414, 200, 112, 25
button #main.quit, "Quitter", quit, UL, 414, 291, 112, 25
button #main.skip, "Démarrer le jeu", [CompStart], UL, 414, 161, 112, 25
button #main.about, "A propos", [apropos], UL, 414, 246, 112, 25
statictext #main, separator$, 1, 366, 546, 18
statictext #main.info, "", 4, 385, 548, 18
open "Puissance 4" for window_nf as #main
print #main.graph,"down"
print #main, "trapclose quit"
print #main, "font ms_sans_serif 10"
#main.graph "when leftButtonDown RowButton"
' wait
[newGame]
#main.info, "Selectionner le niveau de dificulté ou appuyez sur : démarrer le jeu "
redim ROW(12)
redim B(11,12)
MOVE = 0
call DrawEmptyGrid
for i = 3 to 9
ROW(i) = 2 'row is "empty", 3 is first level
' h$ = "#main.button"+str$(i-2)
' #h$, "!enable" 'enable all buttons
next i
#main.skip, "!enable"
wait
sub GetDifficulty h$
WindowWidth = 208
WindowHeight = 230
' UpperLeftX=int((DisplayWidth-WindowWidth)/2)
' UpperLeftY=int((DisplayHeight-WindowHeight)/2)
groupbox #difficulty, "Selectionnez le niveau de dificulté:", 14, 11, 168, 180
radiobutton #difficulty.rb4, "Très facile", [dummy], [dummy], 38, 41, 72, 20
radiobutton #difficulty.rb2, "Facile", [dummy], [dummy], 38, 66, 48, 20
radiobutton #difficulty.rb3, "Normal", [dummy], [dummy], 38, 91, 64, 20
radiobutton #difficulty.rb1, "Dificile", [dummy], [dummy], 38, 116, 60, 20
button #difficulty.default, "Valider", [difficultyOk], UL, 54, 146, 80, 25
open "Niveau" for dialog_nf_modal as #difficulty
print #difficulty, "trapclose [difficultyOk]"
h$ = "#difficulty.rb"+str$(DIFFICULTY)
#h$, "set"
wait
[dummy]
wait
[difficultyOk]
for i = 1 to 4
h$ = "#difficulty.rb"+str$(i)
#h$, "value? a$"
if a$ = "set" then DIFFICULTY = i
next i
close #difficulty
end sub
[CompStart]
#main.skip, "!disable"
call CompMove DIFFICULTY
wait
sub DrawEmptyGrid
#main.graph, "cls; fill lightgray; color darkgray; size 2"
for i = 1 to 6
#main.graph, "line "; i*55-1; " 0 "; i*55-1; " 384"
next i
for i = 1 to 5
#main.graph, "line 0 "; i*55-1; " 384 "; i*55-1
next i
#main.graph, "flush"
end sub
sub DrawMove x, y
x = x-2
y = 9-y
#main.graph, "place "; x*55-28; " "; y*55-28
#main.graph, "circlefilled 24; flush"
end sub
sub RowButton handle$, mx, my
#main.skip, "!disable"
' n = val(right$(handle$,1))+2
n = int(mx/(385/7))+3
ROW(n) = ROW(n)+1
B(ROW(n), n) = 1
#main.graph, "color darkblue; backcolor darkblue"
MOVE = MOVE+1
call DrawMove n, ROW(n)
'check human move
MOVE = CheckWin(MOVE, 1, ROW(n), n)
if MOVE < 42 then call CompMove DIFFICULTY
MOVE = MOVE+1
end sub
sub quit handle$
close #main
end
end sub
sub About handle$
s$ = "Pour jouer : "
s2$ = "Vous devez selectionner le niveau ou cliquer sur démarrer le jeu."
s3$ = " Puis le but sera d'aligner 4 jetons horizontalement, verticalement ou diagonalement."
s4$ = " Mais gare à l'ordinateur ..."
WindowWidth = 384
WindowHeight = 336
' UpperLeftX=int((DisplayWidth-WindowWidth)/2)
' UpperLeftY=int((DisplayHeight-WindowHeight)/2)
groupbox #about.frame, "Comment jouer", 22, 16, 336, 240
statictext #about.text, "", 38, 46, 304, 200
button #about.default, "Ok", [aboutOk], UL, 126, 270, 122, 25
open "Aide" for dialog_nf_modal as #about
#about, "trapclose [aboutOk]"
#about, "font ms_sans_serif 10"
#about.frame, "!font ms_sans_serif 12"
#about.text, s$ ; s2$ ; s3$ ; s4$
wait
[aboutOk]
close #about
end sub
sub CompMove depth
#main.info, compThink$(int(rnd(1)*COMPUTERTHINKS)+1)
' for i = 1 to 7
' h$ = "#main.button"+str$(i)
' #h$, "!disable"
' next i
n = BestMove(-1, depth)
ROW(n) = ROW(n)+1
B(ROW(n),n) = -1
' for i = 1 to 7
' if ROW(i+2) < 8 then
' h$ = "#main.button"+str$(i)
' ' #h$, "!enable"
' end if
' next i
#main.graph, "color darkred; backcolor darkred"
call DrawMove n, ROW(n)
#main.info, makeYourMove$(int(rnd(1)*YOURTURN)+1)
MOVE = CheckWin(MOVE, -1, ROW(n), n)
end sub
function IsWin$(pl, row, col)
if B(row-1,col)=pl and B(row-2,col)=pl and B(row-3,col)= pl then _
IsWin$ = str$(row-1); col; str$(row-2); col; str$(row-3); col
if B(row,col-1)=pl and B(row,col-2)=pl and B(row,col-3)= pl then _
IsWin$ = IsWin$; row; str$(col-1); row; str$(col-2); row; str$(col-3)
if B(row,col-1)=pl and B(row,col-2)=pl and B(row,col+1)= pl then _
IsWin$ = IsWin$; row; str$(col-1); row; str$(col-2); row; str$(col+1)
if B(row,col-1)=pl and B(row,col+1)=pl and B(row,col+2)= pl then _
IsWin$ = IsWin$; row; str$(col-1); row; str$(col+1); row; str$(col+2)
if B(row,col+1)=pl and B(row,col+2)=pl and B(row,col+3)= pl then _
IsWin$ = IsWin$; row; str$(col+1); row; str$(col+2); row; str$(col+3)
if B(row+3,col-3)=pl and B(row+2,col-2)=pl and B(row+1,col-1)= pl then _
IsWin$ = IsWin$; str$(row+3); str$(col-3); str$(row+2); str$(col-2); str$(row+1); str$(col-1)
if B(row+2,col-2)=pl and B(row+1,col-1)=pl and B(row-1,col+1)= pl then _
IsWin$ = IsWin$; str$(row+2); str$(col-2); str$(row+1); str$(col-1); str$(row-1); str$(col+1)
if B(row+1,col-1)=pl and B(row-1,col+1)=pl and B(row-2,col+2)= pl then _
IsWin$ = IsWin$; str$(row+1); str$(col-1); str$(row-1); str$(col+1); str$(row-2); str$(col+2)
if B(row-1,col+1)=pl and B(row-2,col+2)=pl and B(row-3,col+3)= pl then _
IsWin$ = IsWin$; str$(row-1); str$(col+1); str$(row-2); str$(col+2); str$(row-3); str$(col+3)
if B(row-3,col-3)=pl and B(row-2,col-2)=pl and B(row-1,col-1)= pl then _
IsWin$ = IsWin$; str$(row-3); str$(col-3); str$(row-2); str$(col-2); str$(row-1); str$(col-1)
if B(row-2,col-2)=pl and B(row-1,col-1)=pl and B(row+1,col+1)= pl then _
IsWin$ = IsWin$; str$(row-2); str$(col-2); str$(row-1); str$(col-1); str$(row+1); str$(col+1)
if B(row-1,col-1)=pl and B(row+1,col+1)=pl and B(row+2,col+2)= pl then _
IsWin$ = IsWin$; str$(row-1); str$(col-1); str$(row+1); str$(col+1); str$(row+2); str$(col+2)
if B(row+1,col+1)=pl and B(row+2,col+2)=pl and B(row+3,col+3)= pl then _
IsWin$ = IsWin$; str$(row+1); str$(col+1); str$(row+2); str$(col+2); str$(row+3); str$(col+3)
if IsWin$ <> "" then IsWin$ = str$(row); str$(col); IsWin$
end function
function CheckWin(CheckWin, player, row, col)
s$ = IsWin$(player, row, col)
if s$ <> "" then
CheckWin = 42
if player = 1 then
#main.info, youWin$(int(rnd(1)*HUMANWIN)+1)
#main.graph, "color blue; backcolor blue"
else
#main.info, compWin$(int(rnd(1)*COMPUTERWIN)+1)
#main.graph, "color red; backcolor red"
end if
for i = 1 to len(s$) step 2
x = val(mid$(s$, i, 1))
y = val(mid$(s$, i+1, 1))
call DrawMove y, x
next i
else
if CheckWin = 42 then #main.info, drawMessage$(int(rnd(1)*DRAW)+1)
end if
' if CheckWin = 42 then
' for i = 1 to 7
' h$ = "#main.button"+str$(i)
' ' #h$, "!disable"
' next i
' end if
end function
function GetValue(player, depth, row, column)
pl = -1*player
if (B(row-1,column)=pl and B(row-2,column)=pl and B(row-3,column)= pl) or _
(B(row,column-1)=pl and B(row,column-2)=pl and B(row,column-3)= pl) or _
(B(row,column-1)=pl and B(row,column-2)=pl and B(row,column+1)= pl) or _
(B(row,column-1)=pl and B(row,column+1)=pl and B(row,column+2)= pl) or _
(B(row,column+1)=pl and B(row,column+2)=pl and B(row,column+3)= pl) or _
(B(row+3,column-3)=pl and B(row+2,column-2)=pl and B(row+1,column-1)= pl) or _
(B(row+2,column-2)=pl and B(row+1,column-1)=pl and B(row-1,column+1)= pl) or _
(B(row+1,column-1)=pl and B(row-1,column+1)=pl and B(row-2,column+2)= pl) or _
(B(row-1,column+1)=pl and B(row-2,column+2)=pl and B(row-3,column+3)= pl) or _
(B(row-3,column-3)=pl and B(row-2,column-2)=pl and B(row-1,column-1)= pl) or _
(B(row-2,column-2)=pl and B(row-1,column-1)=pl and B(row+1,column+1)= pl) or _
(B(row-1,column-1)=pl and B(row+1,column+1)=pl and B(row+2,column+2)= pl) or _
(B(row+1,column+1)=pl and B(row+2,column+2)=pl and B(row+3,column+3)= pl) then
GetValue = -128
else
if depth = 0 then exit function
GetValue = -1000
for i = 3 to 9
if ROW(i) < 8 then
ROW(i) = ROW(i)+1
B(ROW(i), i) = player
value = -1*GetValue(-1*player, depth-1, ROW(i), i)/2
B(ROW(i), i) = 0
ROW(i) = ROW(i)-1
if value > GetValue then
GetValue = value
if value = 64 then exit for
end if
end if
next i
end if
end function
function BestMove(player, depth)
max = -1000
for i = 3 to 9
if ROW(i) < 8 then
ROW(i) = ROW(i)+1
B(ROW(i),i) = player
value = -1*GetValue(-1*player, depth, ROW(i), i)
B(ROW(i), i) = 0
ROW(i) = ROW(i)-1
if value > max then
max = value
BestList$ = str$(i)
if max = 128 then exit for
else
if value = max then BestList$ = BestList$+str$(i)
end if
end if
next i
'print BestList$, max
BestMove = val(mid$(BestList$, int(rnd(1)*len(BestList$))+1, 1))
end function
data 9
data "Hmm... Laisse moi réfléchir"
data "Tu joues bien, Je le sais!"
data "Je le sais, je vais gagner, laisse moi juste réfléchir."
data "Silence ! Je réfléchis"
data "Ne me frappe pas !"
data "Silence s'il vous plait, je gagne."
data "Je suis sur... je pense... dur..."
data "Alors tu n'y arrive pas ? x)"
data "Arrete d'aller trop vite, je ne suis plus."
data 11
data "I fear nothing! Gimme your best move!"
data "Wake me up when you're ready to make your move."
data "Show me what you've got!"
data "Your turn."
data "You can't win. Prove me wrong!"
data "I'll take a small nap while you figure THIS out!"
data "Think carefully! One little error and you're finished!"
data "Hit me real hard!"
data "You think it's a draw? I don't think so!"
data "I'd be surprised if you found a way to avoid defeat now!"
data "Take your time. I'll be surfing the web if you need me."
data 11
data "You win! Let's play again."
data "May thoughts were wandering... You win!"
data "I didn't see that coming!"
data "I bet you can't beat me again!"
data "Congratulations! You are almost as good as I."
data "That's not fair! I had something in my eye."
data "I can't believe it! You win!"
data "There was a magnetic storm! I couldn't think straight..."
data "It's impossible... Tell me how many moves you think ahead."
data "Amazing! You are my superhero."
data "I couldn't concentrate. You were moving the mouse all the time."
data 11
data "A big applause to the winner of the game!"
data "This should teach you a lesson. Never mess with me!"
data "Game over! You lose!"
data "We can play another one, but you're still going to lose..."
data "I bet you didn't see that one coming."
data "We can still be friends?!"
data "Ouch! This must hurt!"
data "So, what are you doing tonight?..."
data "Ladies and gentlemen, we have a winner. Guess who!"
data "That's another matter-over-mind victory..."
data "I'm the king of the world."
data 10
data "I offer draw."
data "Guess what! We're all out of moves."
data "Draw?! Yet, you were so close..."
data "You put me under a lot of pressure, but you couldn't break me!"
data "Hmm, only a draw... Surely you can do better than that!"
data "Press 'New Game'! We must find out who's better at this."
data "Uh, what happened?"
data "I told them we were going to need a larger board for this."
data "That's what I call wasted CPU cycles..."
data "I promise, next time I won't let you get away so easily."
[apropos]
s$ = "Version : 1.0"
s2$ = "Editeur : casiope01, alex877, Roland"
WindowWidth = 384
WindowHeight = 336
groupbox #about.frame, "Version/Editeur", 22, 16, 336, 240
statictext #about.text, "", 38, 46, 304, 200
button #about.default, "Ok", [aboutOk], UL, 126, 270, 122, 25
open "A propos" for dialog_nf_modal as #about
#about, "trapclose [aboutOk]"
#about, "font ms_sans_serif 10"
#about.frame, "!font ms_sans_serif 12"
#about.text, s$ ; s2$
wait
[aboutOk]
close #about
____________________
Si le meilleurs langage de programmation existe, alors le Just Basic est loin devant.
Ne me tappez pas dessus ! Je débute
Si le meilleurs langage de programmation existe, alors le Just Basic est loin devant.
Ne me tappez pas dessus ! Je débute

Web
Plus personne ?
____________________
Si le meilleurs langage de programmation existe, alors le Just Basic est loin devant.
Ne me tappez pas dessus ! Je débute
Si le meilleurs langage de programmation existe, alors le Just Basic est loin devant.
Ne me tappez pas dessus ! Je débute

Web
• Index
1 Utilisateur en ligne : 0 Administrateur, 0 Modérateur, 0 Membre et 1 Visiteur
Utilisateur en ligne : Aucun membre connecté
Utilisateur en ligne : Aucun membre connecté
Répondre
Vous n'êtes pas autorisé à écrire dans cette catégorie