:-
dynamic numero/
1
.
:-
dynamic parametres/
3
.
xpce_mastermind :-
retractall(
numero(
_
)
)
,
retractall(
parametres(
_
,
_
,
_
)
)
,
make_dialog(
D,
'
Mastermind
XPCE
'
)
,
get(
D,
member,
resultat,
Name)
,
init_connexion(
Name)
,
send(
D,
open
)
.
dialog(
'
Mastermind
XPCE
'
,
[
object
:
=
Client_d,
parts :=
[
Client_d
:
=
dialog
(
'
Client
de
mastermind
'
)
,
Mastermind_Item :=
text_item(
text_item)
,
Resultat :=
label(
resultat,
'
'
)
,
Liste :=
browser(
resultats)
,
Button1 :=
button(
'
Envoi
'
)
,
Button2 :=
button(
'
Encore
'
)
,
Button3 :=
button(
'
Terminé
'
)
],
modifications :=
[
Button1
:
=
[
default_button
:
=
true
]
,
Mastermind_Item :=
[
label
:
=
'
Tapez
votre
proposition
:
'
]
],
layout :=
[
area
(
Mastermind_Item
,
area(
12
,
18
,
400
,
24
)
)
,
area(
Resultat,
area(
12
,
67
,
184
,
18
)
)
,
area(
Button1,
area(
420
,
16
,
80
,
24
)
)
,
area(
Button2,
area(
420
,
62
,
80
,
24
)
)
,
area(
Button3,
area(
420
,
108
,
80
,
24
)
)
,
area(
Liste,
area(
12
,
95
,
400
,
200
)
)
],
behaviour :=
[
Button1
:
=
[
message
:
=
message
(
@
prolog
,
lance_calcul
,
Mastermind_Item
?
selection
,
Resultat
,
Liste
)
],
Button2 :=
[
message
:
=
and
(
message
(
@
prolog
,
init_connexion
,
Resultat
)
,
message(
Mastermind_Item,
clear)
,
message(
Liste,
clear)
)
],
Button3 :=
[
message
:
=
message
(
Client_d
,
destroy
)
]
]
])
.
init_connexion(
Label)
:-
tcp_socket(
Socket)
,
Host=
'
localhost
'
,
Port=
5000
,
tcp_connect(
Socket,
Host:Port)
,
tcp_open_socket(
Socket,
ReadFd,
WriteFd)
,
format(
WriteFd,
'
~w~n
'
,
[
init_connexion
]
)
,
flush_output(
WriteFd)
,
read_line_to_codes(
ReadFd,
Lst)
,
close
(
ReadFd)
,
close
(
WriteFd)
,
atom_codes
(
Atom,
Lst)
,
term_to_atom(
Term,
Atom)
,
Term =
[
Num
,
[
Len_Proposition
,
Lettres
,
Doubles
]
]
,
assert(
parametres(
Len_Proposition,
Lettres,
Doubles)
)
,
assert(
numero(
Num)
)
,
Max is
0
'
a
+Lettres
-
1,
atom_codes
(
A,
[
Max
]
)
,
(
Doubles =
non
->
sformat(
Str,
'
\'La
proposition
est
composée
de
~w
lettres
de
a
à
~w,
sans
doublons.\'
'
,
[
Len_Proposition
,
A
]
)
;
sformat(
Str,
'
\'La
proposition
est
composée
de
~w
lettres
de
a
à
~w,
avec
doublons.\'
'
,
[
Len_Proposition
,
A
]
)
)
,
send(
Label,
selection,
Str)
.
lance_calcul(
Expr,
Resultat,
Liste)
:-
numero(
Num)
,
tcp_socket(
Socket)
,
Host=
'
localhost
'
,
Port=
5000
,
tcp_connect(
Socket,
Host:Port)
,
tcp_open_socket(
Socket,
ReadFd,
WriteFd)
,
format(
WriteFd,
'
[~w,~w]~n
'
,
[
Num
,
Expr
]
)
,
flush_output(
WriteFd)
,
read_line_to_codes(
ReadFd,
Lst)
,
close
(
ReadFd)
,
close
(
WriteFd)
,
atom_codes
(
Atom,
Lst)
,
term_to_atom(
Term,
Atom)
,
etudie_resultat(
Expr,
Term,
Resultat,
Liste)
.
etudie_resultat(
Expr,
[
-
1
,
[
Len_Proposition
,
Cows
]
]
,
Resultat,
List)
:-
parametres(
Len_Proposition,
_
,
_
)
,
sformat(
Atom,
'
~w
:
Bulls
~w
Cows
~w
'
,
[
Expr
,
Len_Proposition
,
Cows
]
)
,
send(
List,
append,
Atom)
,
send(
Resultat,
selection,
'
Bravo
!!!
'
)
.
etudie_resultat(
Expr,
[
-
1
,
[
Bulls
,
Cows
]
]
,
_Resultat,
List)
:-
sformat(
Atom,
'
~w
:
Bulls
~w
Cows
~w
'
,
[
Expr
,
Bulls
,
Cows
]
)
,
send(
List,
append,
Atom)
.
etudie_resultat(
_Expr,
[
-
2
,
Mess
]
,
Resultat,
_List)
:-
send(
Resultat,
selection,
Mess)
.