File tree 1 file changed +32
-0
lines changed 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change
1
+ public class MastermindAlgorithm {
2
+ private String guestCode ;
3
+ private String randomCode ;
4
+ public static final String WHITE = "\u001B [37m" ;
5
+ public static final String GREEN = "\u001B [32m" ;
6
+ public static final String YELLOW = "\u001B [33m" ;
7
+ public static final String BLUE = "\u001B [34m" ;
8
+ public static final String PURPLE = "\u001B [35m" ;
9
+ public static final String CYAN = "\u001B [36m" ;
10
+ public MastermindAlgorithm (String randomCode , String guestCode ) {
11
+ this .guestCode = guestCode ;
12
+ this .randomCode = randomCode ;
13
+ }
14
+
15
+ public void wellPiecesAlgo () {
16
+ int wp = 0 ;
17
+ for (int i =0 ; i < this .randomCode .length (); i ++) {
18
+ if (this .randomCode .charAt (i ) == this .guestCode .charAt (i ))
19
+ wp ++;
20
+ }
21
+ System .out .printf (CYAN + "--- Well placed pieces: %d ---\n " , wp );
22
+ }
23
+ public void misPiecesAlgo () {
24
+ int mp = 0 ;
25
+ for (int i =0 ; i < this .randomCode .length (); i ++) {
26
+ if (this .randomCode .contains ("" + this .guestCode .charAt (i )) && this .randomCode .charAt (i ) != this .guestCode .charAt (i ))
27
+ mp ++;
28
+ }
29
+ System .out .printf (BLUE + "---- Misplaced pieces: %d ----\n " , mp );
30
+ }
31
+ }
32
+
You can’t perform that action at this time.
0 commit comments