more tic tac toe
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.
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.
[quote name='dAND3h' timestamp='1350857927' post='4992596']
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.
[/quote]
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.
[quote name='dAND3h' timestamp='1350857927' post='4992596']
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.
[/quote]
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
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
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."
An array[n] only has valid indices between 0 inclusive and n [color=#ff0000]exclusive.
[quote name='littletray26' timestamp='1350965907' post='4992977']
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."
An array[n] only has valid indices between 0 inclusive and n [color=#ff0000]exclusive.
[/quote]
Well you learn something new everyday I'm not sure why this wasn't mentioned in my C++ book but thank you
[quote name='Bacterius' timestamp='1350966220' post='4992978']
[quote name='littletray26' timestamp='1350965907' post='4992977']
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."
An array[n] only has valid indices between 0 inclusive and n [color=#ff0000]exclusive.
[/quote]
Well you learn something new everyday I'm not sure why this wasn't mentioned in my C++ book but thank you
[/quote]
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 [color=#ff0000]inclusive. The main thing is that the dereferencable range of A is A to A + n [color=#ff0000]exclusive.
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement