Find field borders

Started by
-1 comments, last by stejkenzie 13 years, 4 months ago
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 isfor(int i = 0; i < pole.size(); ++i){		if((i + 1) % 20 == 0){			pole = 'x';		}		if(i % 20 == 0){			pole = 'x';		}	}


Thanks for any ideas.

This topic is closed to new replies.

Advertisement