all stats

minecalftree's stats

guessed the most

namecorrect guessesgames togetherratio

were guessed the most by

namecorrect guessesgames togetherratio

entries

round #58

submitted at
0 likes

guesses
comments 2
at *known at the time as [author of #9]

owo whats this


at *known at the time as [author of #9]

owo whats this


post a comment


Board.java ASCII text
 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
import java.util.List;
public class Board extends Piece{
  private Piece[][] layout;
  private int side, depth;
  public Board(int num){
    layout = new Piece[3][3];
    side = (int)Math.pow(3, num);
    depth = num;
    for(int i = 0; i<3; i++){ //<3
      for(int j = 0; j<3; j++){ //<3
        //reccursion in the constructor lets go
        if(depth<=1)
          layout[i][j] = new Piece();
        else
          layout[i][j] = new Board(depth-1);
      }
    }
  }
  //basically toString() would be way too hard without this
  protected String lineToString(int line){
    String result = "";
    for(int i = 0; i<3; i++){ //<3
        result+=layout[3*line/side][i].lineToString(line-(3*line/side)*side/3)+" "; //sort of gross math, huh
    }
    return result;
  }
  public String toString(){
    String result = "";
    for(int i = (int) Math.log10(side); i>=0; i--){
      for(int j = 0; j < Math.log(25*side+25)/Math.log(26); j++)
        result+=" ";
      for(int j = 1; j <= side; j++){
        result+=j/(int)Math.pow(10, i)%10+" ";
        for(double temp = j; temp%3==0; temp/=3)
          result+=" ";
      }
      result+="\n";
    }
    for(int i = 0; i<side; i++){
      result+=Coords.intToString(i+1);
      for(int j = 0; j < Math.log(25*side+25)/Math.log(26)-Coords.intToString(i+1).length(); j++)
        result+= " ";
      result+=lineToString(i)+"\n";
      for(double temp = i+1; temp%3==0; temp/=3)
        result+="\n";
    }
    return result;
  }
  public void changePiece(char player, List<Coords> route, int depthMeter){
    layout[route.get(depthMeter).getY()-1][route.get(depthMeter).getX()-1].changePiece(player, route, depthMeter+1);
  }
  protected String show(){
    return super.toString();
  }
  public void setWinnerDeep(char w){
    super.setWinner(w);
    for(Piece[] r : layout){
      for(Piece c : r)
        c.setWinnerDeep(w);
    }
  }
  public void setWinner(char w){
    if(depth>1){
      for(int i = 0; i<3; i++){ //<3
        for(int j = 0; j<3; j++) //<3
          layout[i][j].setWinner(w);
      }
    }
    boolean diag1Check = true, diag2Check = true;
    for(int i = 0; i<3; i++){ //<3
      boolean horiCheck = true, vertiCheck = true;
      for(int j = 0; j<3; j++){ //<3
        if(layout[i][j].show().charAt(0)!=w)
          horiCheck = false;
        if(layout[j][i].show().charAt(0)!=w)
          vertiCheck = false;
      }
      if(layout[i][i].show().charAt(0)!=w)
        diag1Check = false;
      if(layout[2-i][2-i].show().charAt(0)!=w)
        diag2Check = false;
      if(horiCheck||vertiCheck)
        setWinnerDeep(w);
    }
    if(diag1Check||diag2Check)
      setWinnerDeep(w);
  }
  public boolean isOccupied(List<Coords> route, int depthMeter){
    if(depthMeter==route.size())
      return super.isOccupied(route, depthMeter);
    if((route.get(depthMeter).getX()>3||route.get(depthMeter).getX()<1)||(route.get(depthMeter).getY()>3||route.get(depthMeter).getY()<1))
      return true;
    return layout[route.get(depthMeter).getY()-1][route.get(depthMeter).getX()-1].isOccupied(route, depthMeter+1);
  }
}
Coords.java ASCII text, with CRLF line terminators
 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
public class Coords {
    int x, y;
    public Coords(int xc, int yc){
        x = xc;
        y = yc;
    }
    public Coords(String str){
        String temp = str.toLowerCase();
        String tempIntString = ""; //silly variable name
        for(int i = 0; i<10; i++){
            if(temp.indexOf('0'+i)>=0){
                tempIntString = temp.substring(temp.indexOf('0'+i));
                temp = temp.substring(0, temp.indexOf('0'+i));
            }
        }
        int sum = 0;
        for(int i = 0;temp.length()>0; i++){
            sum+=(int)Math.pow(26, i)*(temp.charAt(temp.length()-1)-'`');
            temp = temp.substring(0, temp.length()-1);
        }
        y = sum;
        if(tempIntString.length()>0)
            x = Integer.parseInt(tempIntString);
        else
            x = -1;
    }
    public int getX(){
        return x;
    }
    public int getY(){
        return y;
    }
    public static String intToString(int i){
        if(i<=0)
            return "";
        if(i%26==0)
            return intToString((i-26)/26)+'z';
        return intToString(i/26)+(char)(i%26+'`'); 
    }
    public String toString(){
        
        return intToString(y)+x;
    }
}
Main.java ASCII text
 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
import java.util.Scanner;
import java.util.ArrayList;
public class Main {
  static Scanner sc = new Scanner(System.in);
  public static void main(String[] args) {
    System.out.println("Enter board depth");
    play(sc.nextInt());
  }
  public static void play(int size){
    Board b = new Board(size);
    ArrayList<Coords> moves = new ArrayList<Coords>();
    for(int i = 1; i<size; i++)
      moves.add(new Coords((int) (Math.random()*3)+1, (int) (Math.random()*3)+1));
    while(true){
      turn(size, 'X', moves, b);
      turn(size, 'O', moves, b);
    }
  }
  public static void turn(int size, char player, ArrayList<Coords> moves, Board b){
    System.out.println(b);
    if(b.isOccupied(moves, 0)){
      for(int i = 0; i<moves.size(); i++)
        moves.set(i, new Coords((int) (Math.random()*3)+1, (int) (Math.random()*3)+1));
    }
    int x = 2, y = 2;
    for(int j = 0; j<moves.size(); j++){
      x+=(moves.get(j).getX()-1)*Math.pow(3, size-j-1);
      y+=(moves.get(j).getY()-1)*Math.pow(3, size-j-1);
    }
    Coords place = new Coords(x, y);
    System.out.println(player+" turn in square centered at "+place);
    moves.add(new Coords(sc.next()));
    while(b.isOccupied(moves, 0)){
      System.out.println(player+" turn in square centered at "+place);
      moves.set(size-1, new Coords(sc.next()));
    }
    b.changePiece(player, moves, 0);
    b.setWinner(player);
    moves.remove(0);
  }
}
Piece.java ASCII text
 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
import java.util.List;

public class Piece{
  private boolean winner, won;
  public Piece(){
    winner = true;
    won = false;
  }
  public String toString(){
    if(!won)
      return ".";
    return winner? "X":"O";
  }
  protected String lineToString(int line){
    return toString();
  }
  protected String show(){
    return toString();
  }
  public void setWinnerDeep(char w){
    setWinner(w);
  }
  public void setWinner(char w){
    if(w=='X'){
      winner = true;
      won = true;
      return;
    }
    if(w=='O'){
      winner = false;
      won = true;
    }
  }
  public void changePiece(char player, List<Coords> route, int depthMeter){
    setWinner(player);
  }
  public boolean isOccupied(List<Coords> route, int depthMeter){
    return won;
  }
}