This sounds like an interesting programming problem!
I'd like to be sure I understand the conditions set by your 4 given rules. I'll refer to them in the order given.
It seems that rule #1 and rule #2 imply that no child may play in more than 3 innings - twice infield (1st base, 2nd base, 3rd base, shortstop, pitcher and catcher) and once outfield (left field, center field and right field). To fill all 9 positions in all 9 innings you would need 3 full sets of players. You have at least 27 players? Big team!!
If your team has more than 27 players then some players could be excluded from play altogether in a random assignment. Should the program seek to avoid this, perhaps by assigning all players at least one position during the game then filling the rest of the positions in accordance with your 4 rules?
Would you really want to assign all players as a pitcher? I recall from my little league days that only a few can play this position well. Should a sub list of the players be applied here?
I'm afraid I haven't learned to use the vector or string classes yet so I would have to base a solution on more basic methods, although I'm sure the methods recommended by Albatross are superior.
As far as just getting the position assignments filled it seems that working in terms of indexes may work. If there are N players then the numbers 1 through N could be used to refer to them. Also, since the # of innings and positions are fixed, a 2 dimensional array of integers may work to organize it all in.
|
int PositionAssigns[9][9] = {0};// this initializes all values to zero - indicating unfilled positions
|
Here the 1st index is the inning # and the 2nd index is the position #. If the pitcher is position=0
then this:
|
PositionAssigns[x][0] = y;
|
Would correspond to assigning player y the position of pitcher in inning x. Player y would be skipped over in filling PositionAssigns[x+1] as rule #4 requires the benching of the last innings pitcher.
Compliance with rule #3 should be fairly easy. When filling positions for inning x:
1 2
|
if( PositionAssigns[x-1][j] != y)// if player y was not assigned position j last inning
PositionAssigns[x][j] = y;// it is ok to assign player y position j this inning
|
But, do I have the rules right? They seem to imply a very large team.