-4

I am working on this Chess bot code, in Java which is new to me. While I understand most of the what the code does, I am not sure I do understand it a full extent. In addition to that there is few things that confuses me in the code. for example this private d a; I thought we need to specify the type of every variable in Java. also this

private static final b h = new b((State)null, 1.0D / 0.0);

are we declaring b or h? and what doies 1.0D / 0.0 ? doesn't sound like a normal variable.

here is the full code:

public abstract class AIBot extends Bot {
    private d a;
    private int b;
    private int c;
    private boolean d;
    private boolean e;
    private c f;
    private static final Comparator g = new a();
    private static final b h = new b((State)null, 1.0D / 0.0);
    private static final b i = new b((State)null, -1.0D / 0.0);

    public AIBot(String var1, d var2, int var3, boolean var4, boolean var5, InputStream var6) {
        super(var1);
        this.c = 0;
        this.a = var2;
        this.b = var3 << 1;
        this.d = var4;
        this.e = var5;
        if (var6 == null) {
            this.f = null;
        } else {
            try {
                this.f = new c(var6);
            } catch (IOException var7) {
                throw new RuntimeException("Failed to read opening book", var7);
            }
        }
    }

    public AIBot(String var1, d var2, int var3, boolean var4, boolean var5) {
        this(var1, var2, var3, false, false, (InputStream)null);
    }

    protected State chooseMove(State var1) {
        State var2 = null;
        if (this.f != null) {
            var2 = this.f.a(var1);
        }

        if (var2 == null) {
            State var3 = var1;
            Player var8 = var1.player;
            AIBot var7 = this;
            b var4 = null;

            for(int var6 = 2; var6 <= var7.b; var6 += 2) {
                var7.c = var6;
                b var5 = var7.a(var8, var3, 0, -1.0D / 0.0, 1.0D / 0.0);
                if (var4 == null) {
                    var4 = var5;
                }

                if (var3.searchLimitReached()) {
                    break;
                }

                var4 = var5;
            }

            State var9;
            for(var9 = var4.a; var9.previous != var3; var9 = var9.previous) {
            }

            var2 = var9;
        }

        return var2;
    }

    private final Iterable a(Iterable var1) {
        if (!this.d) {
            return var1;
        } else {
            PriorityQueue var2 = new PriorityQueue(g);
            Iterator var3 = var1.iterator();

            while(var3.hasNext()) {
                State var4 = (State)var3.next();
                var2.add(var4);
                if (var4.searchLimitReached()) {
                    break;
                }
            }

            return var2;
        }
    }

    private final b a(Player var1, State var2, int var3, double var4, double var6) {
        if (this.a(var2, var3)) {
            return new b(var2, this.a.a(var2, var1));
        } else {
            b var8 = i;
            Iterator var10 = this.a(var2.next()).iterator();

            while(var10.hasNext()) {
                State var9 = (State)var10.next();
                b var10000 = var8;
                int var10004 = var3 + 1;
                double var17 = var6;
                double var15 = var4;
                int var12 = var10004;
                State var11 = var9;
                Player var21 = var1;
                AIBot var20 = this;
                b var10001;
                if (this.a(var11, var12)) {
                    var10001 = new b(var11, this.a.a(var11, var1));
                } else {
                    b var13 = h;
                    Iterator var19 = this.a(var11.next()).iterator();

                    while(var19.hasNext()) {
                        State var14 = (State)var19.next();
                        b var23 = var20.a(var21, var14, var12 + 1, var15, var17);
                        if ((var13 = var23.b < var13.b ? var23 : var13).b <= var15) {
                            break;
                        }

                        var17 = Math.min(var17, var13.b);
                        if (var11.searchLimitReached()) {
                            break;
                        }
                    }

                    var10001 = var13;
                }

                b var22 = var10001;
                var8 = var10000;
                if ((var8 = var22.b > var8.b ? var22 : var8).b >= var6) {
                    break;
                }

                var4 = Math.max(var4, var8.b);
                if (var2.searchLimitReached()) {
                    break;
                }
            }

            return var8;
        }
    }

    private final boolean a(State var1, int var2) {
        if (var1.over) {
            return true;
        } else if (var1.searchLimitReached()) {
            return true;
        } else if (var2 < this.c) {
            return false;
        } else if (this.e) {
            return var1.board.countPieces() == var1.previous.board.countPieces() || var2 >= this.c * 3;
        } else {
            return true;
        }
    }
}
  • `I thought we need to specify the type of every variable in Java`—So if you see a declaration `private d a`, then `d` must be the type. – khelwood Jan 22 '20 at 14:17
  • Please explain what you *do* understand. – Scott Hunter Jan 22 '20 at 14:18
  • 4
    It looks like some of the code is obfuscated - this is why you have one letter var names and var types – DanielM Jan 22 '20 at 14:18
  • 1
    Trying to understand this code is a waste of time. – Kayaman Jan 22 '20 at 14:19
  • Regarding `private d a;` - the fact that **d** or anything is in lowercase doesn't mean it has to variable. **d** is valid class name. You must remember that first you have object type - **d** and then variable name - **a** – Piotr Niewinski Jan 23 '20 at 13:16
  • As some suggested, this is decompiled code which was previously obfuscated to make the code unreadable. This is done to protect the property from being stolen or hacked via reverse engineering. Copyright protection. To understand this code is very difficult. For complex code it is impossible. Your posted snippet defines a `private static final` field of type `b` named h. `d` and `h` are both replacement of the original type names and variable names. – BionicCode May 08 '20 at 23:55

1 Answers1

1

private d a; - the fact that d or anything is in lowercase doesn't mean it has to variable. d is valid class name. You must remember that first you have object type - d and then variable name - a.

1.0D / 0.0 is also ok. D at the end of literal means that its type is double. Therefore something like this is ok: double d = 1.0D;, but float d = 1.0D; will rise an error. Dividing Double by ZERO will result is something called positive infinity, see constant: Double.POSITIVE_INFINITY.

Piotr Niewinski
  • 1,298
  • 2
  • 15
  • 27
  • Nitpicking, but Double.POSITIVE_INFINITY or Double.NEGATIVE_INFINITY. It made me actually run a test :) – Scratte Jan 23 '20 at 13:35