I'm trying to create a program that reads a txt file that has over 1000 lines of the format below and stores the data in two separate two dimensional arrays:
b14 b15 b12 y4:y11 r7 y1 b2
r15 y13 y12 b14:g9 r2 b8 b7
The file stores the results of a game where there are two players and they both choose four tokens out of a bag. An example token as can be seen above is 'b15' which means it is the colour blue and it has the number 15 on it. The colon signifies that the tokens thereafter are for the 2nd player.
Each line is a game. I need to store the colour and number of each token into two dimensional arrays with 4 rows and 2 columns, I have one for each player e.g.
player1[0][0] = 'b'
player1[0][1] = 14
player1[1][0] = 'b'
player1[1][1] = 15
This stores the first two tokens for player 1, after I've stored the rest of the tokens for this player and the 2nd player in a separate two dimensional array for a single game (single line in text file), I'll be processing the data then overwriting the arrays again for the next line (game) in the text file.
My main question is how do I do the following:
- Split the letter and number so I can store them in the separate array positions
- Recognise a white space meaning a new token
- Recognise that the colon means that player's tokens have all been chosen and it's player 2 next.
Thanks for reading and I'm happy to answer any questions to clarify further.