Sign in to follow this  

Find field borders

Recommended Posts

Hello guys,

once again I'm here to ask you for help. The last task with operator overloading was done in time (it was not about operator overloading, but about my inability to work with arrays ;/)
so I got paid (pack of cigarettes, I feel like a pro programmer now^_^) and now the task is simple representation of Conway's Game of Life. I've completed the task, but there's one thing that lies in my mind - one of the tasks is, that borders of the array (2D or vector, I've done in with vector) have to stay empty (or dead, if you wish) all the time. It's 20x20 array, so I decided to do it the old-fashioned way and wrote down all the coordinates which are at the borders (I guess 72)... but what if I want to multiply the size of my array by two? Then I would have to write down another 72 numbers and I would need to do this every time I change the size. That's why I've been thinking about some function, that would find the borders by itself and store them somewhere, so no matter how the array is big, it will always find them for me. Any ideas?

So far I've been able to detect only vertical ones with something like:

//I'm printing 'x' where the border is
for(int i = 0; i < pole.size(); ++i){
if((i + 1) % 20 == 0){
pole[i] = 'x';
if(i % 20 == 0){
pole[i] = 'x';

Thanks for any ideas.

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