Closed snowfrogdev closed 7 years ago
it is the default copy contructor.
it is equivalent to: Position P2 = P;
Pascal.
2017-06-20 11:53 GMT-07:00 Philippe Vaillancourt notifications@github.com:
Hi,
I'm working on a JavaScript port of your Connect4 solver and I'm a bit confused by one line of code. Line 69 in the solver.cpp, inside the negamax algorithm code: ... Position P2(P); ...
seems to be creating an instance of the Position class. What I don't get is that it looks like you are passing the parameter P to the constructor and P is itself an instance of the Position class. What's more, the default constructor function for the Position class does not seem to accept parameters. I'm not proficient in C++ and this maybe why I don't get what is going on here. Could you help. Thanks.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/PascalPons/connect4/issues/1, or mute the thread https://github.com/notifications/unsubscribe-auth/AF_Lg1M8Ckj48pRZxKKz2Ki0mPUE4_5Aks5sGBUWgaJpZM4OAAag .
Wow, good thing you told me about it, I had no idea what it was. So, if I understand correctly, you are basically making a copy of P. Which means that P2 will have the same values as P in its board array? Now I just have to figure the best way to do that in JavaScript. Actually, looking at the code, is a hard copy (clone) really necessary or could P be simply passed by reference? Would it screw up the algorithm?
Man, looking through your code makes me realize that C++ is a very succinct language compared to JavaScript. I especially like the way you populate the entire matrix board with 0s... with one simple line of code. I had to write a whole nested for loop function to do the same thing in JavaScript.
C++
board{0}
vs. JavaScript
this.board = ((numrows, numcols, initial) => {
const arr = [];
for (let i = 0; i < numrows; ++i) {
const columns: number[] = [];
for (let j = 0; j < numcols; ++j) {
columns[j] = initial;
}
arr[i] = columns;
}
return arr;
})(Position.WIDTH, Position.HEIGHT, 0);
Neoflash1979 is your code available anywhere?
@MeMeMax Sorry, I did not complete this project.
Hi,
I'm working on a JavaScript port of your Connect4 solver and I'm a bit confused by one line of code. Line 69 in the solver.cpp, inside the negamax algorithm code: ... Position P2(P); ...
seems to be creating an instance of the Position class. What I don't get is that it looks like you are passing the parameter
P
to the constructor andP
is itself an instance of the Position class. What's more, the default constructor function for the Position class does not seem to accept parameters. I'm not proficient in C++ and this maybe why I don't get what is going on here. Could you help. Thanks.