more tic tac toe

Started by
30 comments, last by alvaro 11 years, 5 months ago
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.

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

Advertisement

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

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

[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 smile.png

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

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." sad.png

An array[n] only has valid indices between 0 inclusive and n [color=#ff0000]exclusive.

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”


[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." sad.png

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 :)
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

[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." sad.png

An array[n] only has valid indices between 0 inclusive and n [color=#ff0000]exclusive.
[/quote]

Well you learn something new everyday smile.png I'm not sure why this wasn't mentioned in my C++ book but thank you smile.png
[/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.

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.


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

This topic is closed to new replies.

Advertisement