I’m getting an error that I really can’t explain when trying to compile my Java code:
error: constructor MinimaxThread in class MinimaxThread cannot be applied to given types;
MinimaxThread mmt = new MinimaxThread(board.clone(), 2, true);
^
required: no arguments
found: MCBoard,int,boolean
reason: actual and formal argument lists differ in length
The error makes no sense, as I have a constructor that takes an MCBoard, int, and boolean:
public class MinimaxThread implements Runnable {
public MCBoard board;
public int depth;
public HashMap<Tuple, Integer> moveEvals;
boolean cont = true;
boolean verbose = false;
public MinimaxThread(MCBoard board, int initialDepth, boolean verbose) {
this.board = board;
depth = initialDepth;
moveEvals = new HashMap<Tuple, Integer>();
for (Tuple t : board.legalMoves) {
moveEvals.put(t, new Integer(0));
}
this.verbose = verbose;
}
It’s an overloaded constructor (there is one with just MCBoard and one with MCBoard and int), but I don’t see how that would matter. Any ideas? Here’s the calling code:
public static void testMinimax(){
MCBoard board = new MCBoard();
board.move(5,0);
board.move(4,0);
board.move(5,2);
MinimaxThread mmt = new MinimaxThread(board.clone(), 2, true);
mmt.run();
}
edit: board.clone() is overridden:
public MCBoard clone() {
// irrelevant code removed
return new MCBoard(gridClone, turn, legalMovesClone, moveListClone);
}
edit #2: Here is my git repository, for reproducibility:
https://github.com/cowpig/MagneticCave
EDIT: Now that you’ve given us your github URL, we can see what
MinimaxThreadreally looks like – at least in the latest pushed code:Yup, I can see why the compiler would complain at that constructor call…
EDIT: Before we knew that
MCBoard.clone()was overridden, the answer below made sense. Now, however, I can see no reason why the compiler should complain. Indeed, using the code you’ve given (but ignoring the actual implementation, which is irrelevant) it all compiles fine:MinimaxThread.java:
MCBoard.java:
Test.java:
So I suspect you’re not building the code you’ve presented. Try to build the code above, and if that works, see if you can figure out the difference between that and your actual code.
Original answer
Presumably the compiler “thinks” that
board.clone()returnsObject, because that’s what’s declared byObject.clone(). So you need to cast the result toMCBoard:Alternatively, you could override
clone()withinMCBoard, declaring that it returnsMCBoardrather thanObject.