I need help setting up the prototype, the actual function header, and the code used to modify the structure being sent to the function. I need to pass the array of this structure by reference so that any changes made change the original data sent in.
THis is what I have so far.
VB Code:
'My prototype
int getlegalmoves(struct postype pos, struct movetype *movelist[]);
'The function code
int getlegalmoves(struct postype pos, struct movetype *movelist[])
{
movelist[0].from = 1;
movelist[0].to = 2;
movelist[1].from = 3;
movelist[1].to = 4;
}
Last edited by ae_jester; Dec 21st, 2003 at 04:36 PM.
I am pretty sure it is a pointer....so you don't need the ? in front of it...that will just make it a pointer to a pointer...and if you have a pointer you are maybe copying the pointer....but that is no work at all. But you are still working on the same struckt as before using that pointer....Thats at least what I would have written on my exam........hehe
Ok, I changed it to the following, but I still get an error (same one) on the line where I'm calling this function ("local function definitions are illegal")...here is all the relevant code...
VB Code:
struct postype
{
int blacks;
int whites;
int kings;
int colour;
int hashval;
}game;
struct movetype
{
int blacks;
int whites;
int kings;
short from;
short to;
};
'prototypes
int getlegalmoves(struct postype pos, struct movetype movelist[20]);
int alphabeta(struct postype pos, int depth, int alpha, int beta);
int alphabeta(struct postype pos, int depth, int alpha, int beta)
{
struct movetype movelist[20];
int i, j, n, value, localalpha, bestvalue, hashvalue, hashtype, lookupvalue;
struct postype localpos;
short sqrfrom, sqrto;
bestvalue = -1000;
localpos = pos;
localalpha = alpha;
if (depth==0)
{
value=evaluation(pos);
return value;
}
//n = getlegaljumps(pos, movelist);
if (n==0)
{
n = getlegalmoves(pos, movelist); '<-- ERROR OCCURS HERE
}
for(i=0; i<n; i++)
{
pos.blacks = movelist[i].blacks;
pos.whites = movelist[i].whites;
pos.kings = movelist[i].kings;
pos.colour = abs(pos.colour - 3);
value = -alphabeta(pos, depth-1, -beta, -localalpha);
pos = localpos;
bestvalue = max(value, bestvalue);
if (bestvalue>=beta)
{
break;
}
if (bestvalue>localalpha)
{
localalpha = bestvalue;
}
}
return bestvalue;
}
int getlegalmoves(struct postype pos, struct movetype movelist[20])
{
int i, j;
int totalmoves;
int sqrfrom, sqrto;
totalmoves=0;
if(pos.colour == BLACK)
{
for(i=0;i<32;i++)
{
sqrfrom=i;
if((pos.blacks & i) && !(pos.kings & i))
{
for(j=0; j<movecounts[bp][sqrfrom]; j++)
{
sqrto = legalmoves[bp][sqrfrom][j];
if (!(pos.blacks & sqrto) && !(pos.whites & sqrto))
Hehe...now I am having problems here....those folders are added to the directory list so the compiler should have no problem of finding them....stupid C++...
Hehehe...I moved the protoyupe at the top of the prototypes, and the function over the last one...and then everything worked.......no idea why tho'.....
C:\struct.cpp(468) : fatal error C1004: unexpected end of file found
error....not sure what is causing that but I commented out the #include "STDAFX.H" becuase I have no idea why C++ could not find it...and I have no idea what you are using it for...so that may couase that error...I don't know...
And you have to initialise n in the alphabeta function....and ther is some error in the evaluation function...can't see the problem...looks like you have missed out a } but I can't find where....and it sais that not all paths have a return value....
FOUND IT....your BIG problem was that the evaluation function has two {{ in the last if test....so try to take away one of them and initialise n then you are ready to rumble....just ignore all other posts from me...
[Edit]Now I have deserved the date I am on my way too....hitting the shower...happy C++ programming[/Edit]
Originally posted by ae_jester I'm using Microsoft Visual C++ 6.0
STDAFX.H was automatically included when I started a new project. I have no idea why either.
I am always starting with a clean project...so nothing else then what I want is added....but if you want it there no worries....even if I can't see whee you are using anything from it...
Hehe...wasn't I fast enough.......no sorry....I havn't had time to look yet....I have only been doing C++ for 4 months....so this was more or less the first non school C++ app I have ever seen...