repl.it
@WilliamPenrod/

bulls-and-cows

Java

Server building in progress...

fork
loading
Files
  • Main.java
  • .metadata
  • .tooling
  • Main.class
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import java.util.Scanner;
import java.net.Socket;
import java.util.Random;
class Main {
  private static Scanner sci = new Scanner(System.in);
  public static void main(String[] args) {
    System.out.println("_______BULLS AND COWS______"/*+rn*/);
    while(true){
    System.out.print("Choose a mode: ");
    String control = sci.nextLine();
    switch(control){
    case "wai" :
    gamewithai();
    break;
    case "socks" :
    break;
    default :
      System.out.println("Modes: wai[`With ai`] wah[`With another human`]");
    break;
    }
    }
  }
  public static void gamewithai(){
    Random random = new Random();
    int rnon = random.nextInt(9);
    int rntw = random.nextInt(9);
    int rnth = random.nextInt(9);
    int rnfo = random.nextInt(9);
    System.out.print("Your 4 digit number(must be four digits)> ");
    String unum = sci.nextLine();
    String ss[] = unum.split("");
    System.out.println("Your number: "+Integer.parseInt(ss[0]) +" "+ Integer.parseInt(ss[1]) +" "+ Integer.parseInt(ss[2]) +" "+ Integer.parseInt(ss[3]));
    System.out.println("AI difficulty: INSANE (jk its stupid rn)");
    int i = 0;
    int b = 0;
    String guess;
    boolean no = false;
    boolean ntw = false;
    boolean nth = false;
    boolean nfo = false;
    String c1 = "\u001B[31m";
    String c2 = "\u001B[31m";
    String c3 = "\u001B[31m";
    String c4 = "\u001B[31m";
    String rt = "\u001B[0m";
    int rngon = 0;
    int rngtw = 0;
    int rngth = 0;
    int rngfo = 0;
    int arcont = 0;
    boolean run = true;
    while(run){
      i++;
      System.out.print("[user/"+i+"/] ");
      guess = sci.nextLine();
      System.out.print("[resu/"+i+"/] ");
      if(Integer.parseInt(guess) > 1000 && Integer.parseInt(guess) < 10000){
      String gs[] = guess.split("");
      if(Integer.parseInt(gs[0]) == rnon){System.out.print("B");}else{System.out.print("C");}
      if(Integer.parseInt(gs[1]) == rntw){System.out.print("B");}else{System.out.print("C");}
      if(Integer.parseInt(gs[2]) == rnth){System.out.print("B");}else{System.out.print("C");}
      if(Integer.parseInt(gs[3]) == rnfo){System.out.print("B");}else{System.out.print("C");}
      if(Integer.parseInt(gs[3]) == rnfo && Integer.parseInt(gs[2]) == rnth && Integer.parseInt(gs[1]) == rntw && Integer.parseInt(gs[0]) == rnon){System.out.println(" ");System.out.println("User has won!!");System.exit(0);}
    }else{System.out.print("\u001B[41m"+"error"+rt);}
    System.out.println("");
      if(no == false){rngon = random.nextInt(9);}
      if(ntw == false){rngtw = random.nextInt(9);}
      if(nth == false){rngth = random.nextInt(9);}
      if(nfo == false){rngfo = random.nextInt(9);}
      if(Integer.parseInt(ss[0]) == rngon){no = true; c1 = "\u001B[32m";}
      if(Integer.parseInt(ss[1]) == rngtw){ntw = true; c2 = "\u001B[32m";}
      if(Integer.parseInt(ss[2]) == rngth){nth = true; c3 = "\u001B[32m";}
      if(Integer.parseInt(ss[3]) == rngfo){nfo = true; c4 = "\u001B[32m";}
      if(no == true && ntw == true && nth == true && nfo == true){
        System.out.println("\u001B[31m"+"{computer} "+rt+""+c1+""+rngon+""+rt+""+c2+""+rngtw+""+rt+""+c3+""+rngth+""+rt+""+c4+""+rngfo+""+rt);

        System.out.println("COMPUTER HAS WON!");
        System.out.println("COMPUTER HAS WON!");
        System.out.println("COMPUTER HAS WON!");
        System.out.println("COMPUTER HAS WON!");
        System.out.println("COMPUTER HAS WON!");
        System.out.println("COMPUTER HAS WON!");
        System.out.println("COMPUTER HAS WON!");
        System.out.println("COMPUTER HAS WON!");
        run = false;
      }else{
      System.out.println("\u001B[31m"+"{computer} "+rt+""+c1+""+rngon+""+rt+""+c2+""+rngtw+""+rt+""+c3+""+rngth+""+rt+""+c4+""+rngfo+""+rt);
      arcont++;
      }
    }
  }
  //Ai will be made better(no repeating numbers) at a later date.
  public static int arnumo(){
    int[] n1;

    return 1;
  }
  public static int arnumtw(){
    int[] n2;

    return 1;
  }
  public static int arnumth(){
    int[] n3;

    return 1;
  }
  public static int arnumfo(){
    int[] n4;

    return 1;
  }
  public static void socks(){
  String hostName;
  int portNumber;

try {
    Socket echoSocket = new Socket("https://repl.it/@WilliamPenrod/bulls-and-cows", 5500);
    echoSocket.sendUrgentData(3202);
}catch(Exception e){

}

  }
}
?