Sign in to follow this  
vaneger

scoring an unsorted array vs a sorted one

Recommended Posts

I'm doing something wrong but I can figure out what. What is supposed to happen is I call a swap function that swaps 8 indicies in an array ( 2 blocks of 4). Then I'll update the score of the test array compared to the goal array ( goal is a sorted copy of test) with the intention of only increasing the score if the newly swapped items are in order.
float rangeScore(vector<char> &goal,vector<char> &test,float score, int x,int y)
{
	int i = 0;
	float local_score = score;
	for(i=x;i<y;i++)
		if(test[i] == goal[i])
			local_score++;
	return local_score;
	//return( score / 10.24f) ;

}
example call:
new_score = rangeScore(goal,test,current_score,i,i+4);
new_score = rangeScore(goal,test,new_score,j,j+4);


What happens is new_score keeps increasing every time , which doesn't make sense considering if you swap something like this: AADD CBCB test CBCB AADD test swapped AABB CCDD goal and score it vs the sorted goal it should score 3 but I get 4.

Share this post


Link to post
Share on other sites
yay - alot of good that does me when I don't understand assembly - maybe you do so here is what I got at the if (test[i] == goal][i]) line


0040231E mov ecx,dword ptr [ebp-4]
00402321 push ecx
00402322 mov ecx,dword ptr [ebp+0Ch]
00402325 call @ILT+365(std::vector<char,std::allocator<char> >::operator[]) (00401172)
0040232A movsx esi,byte ptr [eax]
0040232D mov edx,dword ptr [ebp-4]
00402330 push edx
00402331 mov ecx,dword ptr [ebp+8]
00402334 call @ILT+365(std::vector<char,std::allocator<char> >::operator[]) (00401172)
00402339 movsx eax,byte ptr [eax]
0040233C cmp esi,eax
0040233E jne rangeScore+6Ch (0040234c)

Share this post


Link to post
Share on other sites
Quote:
Original post by vaneger
yay - alot of good that does me when I don't understand assembly - maybe you do so here is what I got at the if (test[i] == goal][i]) line

*** Source Snippet Removed ***
Your debugger shouldn't output assembly if you invoke it correctly. What platform/environment are you using?

Share this post


Link to post
Share on other sites
Yeah, you don't need to step through assembler. Assumedly you're already running a debug build, which debugger are you using? If you're on windows you should be using visual studio's debugger, which is unmatched in usefulness

Share this post


Link to post
Share on other sites
Quote:
Original post by vaneger
I'm using msvc 6.0 .
Throw that out directly, and download a copy of Visual C++ Express, which happens to be free. Apart from being ancient, MSVC 6 had one of the worst C++ compilers in existence, and you will save yourself a world of trouble by moving on.

Share this post


Link to post
Share on other sites
Yeah as I just mentioned in my PM, the thing you're doing wrong is that you need to subtract one for each match, then modify the array, and then add one for each match.

Share this post


Link to post
Share on other sites
Quote:
Original post by vaneger
Ok so I got the express version - still don't know what settings out of the million of them to use for debugging.
Click in the margin to set a breakpoint next to the statement you want to debug, and the hit the green arrow, or choose 'run with debugger' from the menu.

Share this post


Link to post
Share on other sites
I'll place breakpoints in the code, but nothing happens when I run it with debugging.

I want to be able to look at the values of variables at certain points but I don't know how to use the debug feature much.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this