The given problem is a Constraint Satisfaction Problem. In particular (using the terminology used here):
- The set of variables X is made of the seats (in your case we have 50 seats correspond to a set of 50 variables, one for each seat)
- The sets of domain values D is a set of 50 domains (1 for each variable), each of which contains a set of 6 values (the 6 different flavours).
- The set of constraints is made up like this
C1 := (X[0,0] != X[0,1]); C2 := (X[0,0] != X[1,0]); C3 := (X[0,0] != X[1,1])
and so on.
Personally I would suggest to use Forward Checking in order to reduce complexity.
The resulting algorithm (a simplified version without rollback of the assignment as it's unnecessary for this specific problem) would look something like this:
initialize_domains_for_each_variable; // set the 6 available flavours
for(int i = 0; i < 10; i++){
for(int j = 0; j < 5; j++){
seats[i,j].flavour = seats[i,j].possible_flavours[0];
// look ahead and eliminate possible conflicts
remove_this_flavour_from_surrounding_seats_possible_flavours;
}
}
Doing it like this will ensure that no conflict arises because you'll have at least 2 available flavours for each seat. We visit the seats from left to right and from top to bottom so for each seat we have to check which assignment does not conflict with the previously completed assignments. In the general case we will have:
seat[i,j].available_flavours = available_flavours - seat[i-1,j+1].flavour - seat[i-1,j].flavour - seat[i-1,j-1].flavour - seat[i,j-1].flavour
that has 2 items. In the borders of the matrix you will have more available flavours because the items it can conflict with are 2 (in the case of a left border), 3 (in the case of a right border not in the first row), or 1 (in the case of the top right element, the right border of the first row).
Be aware that using the above algorithm will only use 5 flavours (the bare minimum). If you have the necessity of using 6 flavours you will have to adapt the algorithm.