[Duplicate] Issue with Action Master Script

Note: Edited to correct issues after folks pointed out things I didn’t notice as it was late at night. :slight_smile:

There is an assumption that any (bowl >= 18) is the 10th frame. That is a FALSE assumption. Here is a simple example:

Frame: 1 2 3 4 5 6 7 8 9 10 10 10
Frame Score: 10 10 10 10 10 10 10 10 10 10 10 10
Bowl: 1 2 3 4 5 6 7 8 9 10 11 12

In reality, the 10th frame can have bowls between 10-21. Note: Ben’s final solution does address this issue by inserting into the data stream on the fly. There are other solutions that will work as well.

I thought my last version of the code was correct, but it wasn’t.

So I copied all the “Verification” tests from the score master tests and ported them over.

To be fair, this is a difficult problem. I have 30 years of experience as a professional Software Engineer, and this was difficult for me.

Here is an alternate solution:
https://pastebin.com/UJnm8NU6

Hope this helps,
Dan

If you look at the bottom end of the action master code it’s got this:

            if (rolls[i] == 10) {
                rolls.Insert (i, 0); // Insert virtual 0 after strike
                nextAction = Action.EndTurn;

So when you bowl a strike it updates the list from 1 to 2 rolls ie if you bowl 10, 10, 10 then what comes out is 10, 0, 10, 0, 10, 0. Meaning if you pass 9 strikes in you end up with a list that’s 18 elements long.

This is also why you need the scoreframes running BEFORE the animator runs the ActionMaster otherwise every strike will return as a spare. I spent an hour debugging that one yesterday :frowning:

1 Like

Some of the code - mine included I think - would skip a bowl on a strike but still have it in our array/list, which meant as far as the counter was concerned, frame 10 would still start at bowl 18+.

Something like:

...
		// Which bowl of the frame
		if (bowls % 2 == 1) {
			if (pins == MAX_PINS) { // Strike
				bowls += (bowls >= LAST_FRAME ? 1 : 2);
				return Action.EndTurn;
			} else { // 0-9
				bowls++;
				return Action.Tidy;
			}
		} else { // Either way, we move on
			bowls++;
			return Action.EndTurn;
		}

Yep, I missed this. It was really late when I finished. The problem is the assumption of 18+ bowls on the input data is still not true. This modifies the input stream in place and wouldn’t be my recommended solution to the problem.

But it will work.

Thanks for pointing this out.

This looks like a good solution to me. Good job! I like this solution better than inserting into the list because it doesn’t make assumptions on the input data.

I didn’t see this in any of the other code I looked at. But I didn’t look at all the posted code it was late.

Privacy & Terms