Jump to content

  • Log In with Google      Sign In   
  • Create Account

more tic tac toe


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
31 replies to this topic

#21 Bacterius   Crossbones+   -  Reputation: 9282

Like
0Likes
Like

Posted 21 October 2012 - 07:14 PM

The code doesn't actually make sense. player_O=array[t]; specifically - once the array is shuffled, you want to pick each element one after the other to get a list of numbers which don't repeat. Obviously this means you need to store the shuffled array somewhere, and use it for all 9 numbers (or 10.. why is it 10?) because if you just generate a new array each time and pick one element from this array, well, you've basically done nothing.

Edited by Bacterius, 21 October 2012 - 07:14 PM.

The slowsort algorithm is a perfect illustration of the multiply and surrender paradigm, which is perhaps the single most important paradigm in the development of reluctant algorithms. The basic multiply and surrender strategy consists in replacing the problem at hand by two or more subproblems, each slightly simpler than the original, and continue multiplying subproblems and subsubproblems recursively in this fashion as long as possible. At some point the subproblems will all become so simple that their solution can no longer be postponed, and we will have to surrender. Experience shows that, in most cases, by the time this point is reached the total work will be substantially higher than what could have been wasted by a more direct approach.

 

- Pessimal Algorithms and Simplexity Analysis


Sponsor:

#22 littletray26   Members   -  Reputation: 267

Like
0Likes
Like

Posted 22 October 2012 - 07:50 AM

How can there be 9 spaces in an array of size 8? That makes no sense.


If we have for example
int banana[5];

There is in fact 6 spaces.

banana[0] = 1;
banana[1] = 2;
banana[2] = 3;
banana[3] = 4;
banana[4] = 5;
banana[5] = 6;

Arrays start off at zero, so in an 8 space array there is 9 spaces.
The majority of Internet Explorer users don't understand the concept of a browsing application, or that there are options.
They just see the big blue 'e' and think "Internet". The thought process usually does not get much deeper than that.

Worms are the weirdest and nicest creatures, and will one day prove themselves to the world.

I love the word Clicky :)

#23 littletray26   Members   -  Reputation: 267

Like
0Likes
Like

Posted 22 October 2012 - 07:52 AM

Otherwise, you can change the < sign to <= .


This was the confusion. Sorry.
The majority of Internet Explorer users don't understand the concept of a browsing application, or that there are options.
They just see the big blue 'e' and think "Internet". The thought process usually does not get much deeper than that.

Worms are the weirdest and nicest creatures, and will one day prove themselves to the world.

I love the word Clicky :)

#24 Álvaro   Crossbones+   -  Reputation: 13912

Like
0Likes
Like

Posted 22 October 2012 - 08:12 AM


How can there be 9 spaces in an array of size 8? That makes no sense.


If we have for example
int banana[5];

There is in fact 6 spaces.

banana[0] = 1;
banana[1] = 2;
banana[2] = 3;
banana[3] = 4;
banana[4] = 5;
banana[5] = 6;

Arrays start off at zero, so in an 8 space array there is 9 spaces.


No, that's not how it works. Array indices do start at zero, so in an array of size 8, the last valid entry has index 7.

#25 dAND3h   Members   -  Reputation: 214

Like
0Likes
Like

Posted 22 October 2012 - 10:01 AM


How can there be 9 spaces in an array of size 8? That makes no sense.


If we have for example
int banana[5];

There is in fact 6 spaces.

banana[0] = 1;
banana[1] = 2;
banana[2] = 3;
banana[3] = 4;
banana[4] = 5;
banana[5] = 6;

Arrays start off at zero, so in an 8 space array there is 9 spaces.


See Alvaro's response. But please try to take advice onboard , or at least make sure you are correct before you end up giving wrong advice. I probably should have explained it when I said it. Alas, No harm done Posted Image

Edited by dAND3h, 22 October 2012 - 10:03 AM.


#26 littletray26   Members   -  Reputation: 267

Like
0Likes
Like

Posted 22 October 2012 - 10:18 PM

No, that's not how it works. Array indices do start at zero, so in an array of size 8, the last valid entry has index 7.


When I made my TicTacToe game my board was an array[8] and I never had a problem with using all 9 spaces in it, so I'm not sure what you mean...
I'm confused :P
The majority of Internet Explorer users don't understand the concept of a browsing application, or that there are options.
They just see the big blue 'e' and think "Internet". The thought process usually does not get much deeper than that.

Worms are the weirdest and nicest creatures, and will one day prove themselves to the world.

I love the word Clicky :)

#27 Bacterius   Crossbones+   -  Reputation: 9282

Like
2Likes
Like

Posted 22 October 2012 - 10:23 PM

When I made my TicTacToe game my board was an array[8] and I never had a problem with using all 9 spaces in it, so I'm not sure what you mean...
I'm confused

That's because memory is allocated in pages and you got lucky with the last element having been allocated as a side effect, especially in debug mode, or some other reason. But it is technically undefined behaviour and using it is a big no-no, as it is (quite literally) not supposed to work.

It's like saying "I need 9 elements in my array but I'm only going to allocate 8 because I like taking risks and playing with factors which are out of my control." Posted Image

An array[n] only has valid indices between 0 inclusive and n exclusive.

Edited by Bacterius, 22 October 2012 - 10:39 PM.

The slowsort algorithm is a perfect illustration of the multiply and surrender paradigm, which is perhaps the single most important paradigm in the development of reluctant algorithms. The basic multiply and surrender strategy consists in replacing the problem at hand by two or more subproblems, each slightly simpler than the original, and continue multiplying subproblems and subsubproblems recursively in this fashion as long as possible. At some point the subproblems will all become so simple that their solution can no longer be postponed, and we will have to surrender. Experience shows that, in most cases, by the time this point is reached the total work will be substantially higher than what could have been wasted by a more direct approach.

 

- Pessimal Algorithms and Simplexity Analysis


#28 littletray26   Members   -  Reputation: 267

Like
0Likes
Like

Posted 22 October 2012 - 11:59 PM


When I made my TicTacToe game my board was an array[8] and I never had a problem with using all 9 spaces in it, so I'm not sure what you mean...
I'm confused

That's because memory is allocated in pages and you got lucky with the last element having been allocated as a side effect, especially in debug mode, or some other reason. But it is technically undefined behaviour and using it is a big no-no, as it is (quite literally) not supposed to work.

It's like saying "I need 9 elements in my array but I'm only going to allocate 8 because I like taking risks and playing with factors which are out of my control." Posted Image

An array[n] only has valid indices between 0 inclusive and n exclusive.


Well you learn something new everyday :) I'm not sure why this wasn't mentioned in my C++ book but thank you :)
The majority of Internet Explorer users don't understand the concept of a browsing application, or that there are options.
They just see the big blue 'e' and think "Internet". The thought process usually does not get much deeper than that.

Worms are the weirdest and nicest creatures, and will one day prove themselves to the world.

I love the word Clicky :)

#29 Washu   Senior Moderators   -  Reputation: 5423

Like
1Likes
Like

Posted 23 October 2012 - 12:05 AM



When I made my TicTacToe game my board was an array[8] and I never had a problem with using all 9 spaces in it, so I'm not sure what you mean...
I'm confused

That's because memory is allocated in pages and you got lucky with the last element having been allocated as a side effect, especially in debug mode, or some other reason. But it is technically undefined behaviour and using it is a big no-no, as it is (quite literally) not supposed to work.

It's like saying "I need 9 elements in my array but I'm only going to allocate 8 because I like taking risks and playing with factors which are out of my control." Posted Image

An array[n] only has valid indices between 0 inclusive and n exclusive.


Well you learn something new everyday Posted Image I'm not sure why this wasn't mentioned in my C++ book but thank you Posted Image


Get a better C++ book then, because whatever one you have probably should just be burned.

It should also be noted that the valid range of pointers to an array A with a size n is A to A + n inclusive. The main thing is that the dereferencable range of A is A to A + n exclusive.

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.
ScapeCode - Blog | SlimDX


#30 littletray26   Members   -  Reputation: 267

Like
0Likes
Like

Posted 23 October 2012 - 12:16 AM

Get a better C++ book then, because whatever one you have probably should just be burned.


Beginning C++ Game Programming by Michael Dawson. Burn away
The majority of Internet Explorer users don't understand the concept of a browsing application, or that there are options.
They just see the big blue 'e' and think "Internet". The thought process usually does not get much deeper than that.

Worms are the weirdest and nicest creatures, and will one day prove themselves to the world.

I love the word Clicky :)

#31 giobs111   Members   -  Reputation: 98

Like
-1Likes
Like

Posted 23 October 2012 - 02:04 AM

I have tried fisherYates shuffle but it still does not work.here is my code
void Computer::move_player_O()
{
srand(time(NULL));
const int length=10;
int array[length];
for(int t=1;t<=9;t++)
array[t]=t;
fisherYates(array,length);
player_O=array[t];
t++;
}
void Computer::check_player_O()
{
board[player_O]='O';
}


int array[length]; this will not work try

int *array=new int[length];

and after you have done working

delete[] array;

#32 Álvaro   Crossbones+   -  Reputation: 13912

Like
0Likes
Like

Posted 23 October 2012 - 03:49 AM


I have tried fisherYates shuffle but it still does not work.here is my code
[...]
const int length=10;
int array[length];
[...]


int array[length]; this will not work try


Why wouldn't it work? `length' is a compile-time constant and using it as an array length is perfectly kosher.

int *array=new int[length];

and after you have done working

delete[] array;

You only need to do that if `length' is not known at compile time. Even in that case, some compilers (e.g., gcc) do support variable-length arrays. VLAs are part of the C99 standard and they almost made it to the C++11 standard.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS