Original Post
Just finished my first game in C++. It's a '4 in a row' console game with a little help from conio.h. It works(only for 2 human players) but I'm not so happy with how I did it. Besides my terrible design I am particularly unhappy with one function. It's called CheckVictory, a member of class Bord, and it checks for a victory (duh). Maybe someones cares to give some critique or suggestions how it should be done? I'm also interested in general pointers (no pun intended) to the proper way of implementing algorithms. To parafrase (the code itself is somewhat lengthy): CheckVictory does a lot of checking on a vector of ints, where each int can represent an empty position or one that is filled by a particular player. This vector is always of size 42, and represents a bord of 7 columns and 6 rows. First row goes from 0 to 6, second from 7 to 13, etc. The checking happens in a for-loop which is nested in another for-loop, which contains 4 more loops, 18 if-statements (including boundery-checking for the vector), 6 else-statements, and a bunch of simple expressions like assignments. It is based on the fact that vector[i-7] gives the above row, similiar stuff for diagonals and (ugh) that if (i+1)%7 == 0, it means that the position (i) is on the right side of the bord. I don't like that it's so complicated. I can't even parafrase the idea well in a couple of sentences. Maybe it should not have been an vector to represent the bord? Maybe seven vectors to represent the columns which can grow with .push_back? I think I lack some mathematical skills. I also think there should be a more elegant solution.