-
Notifications
You must be signed in to change notification settings - Fork 0
/
ActionMaster.cs
41 lines (36 loc) · 1.14 KB
/
ActionMaster.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public static class ActionMaster {
public enum Action {Tidy, Reset, EndTurn, EndGame, Undefined};
public static Action NextAction (List<int> rolls) {
Action nextAction = Action.Undefined;
for (int i = 0; i < rolls.Count; i++) { // Step through rolls
if (i == 20) {
nextAction = Action.EndGame;
} else if ( i >= 18 && rolls[i] == 10 ){ // Handle last-frame special cases
nextAction = Action.Reset;
} else if ( i == 19 ) {
if (rolls[18]==10 && rolls[19]==0) {
nextAction = Action.Tidy;
} else if (rolls[18] + rolls[19] == 10) {
nextAction = Action.Reset;
} else if (rolls [18] + rolls[19] >= 10) { // Roll 21 awarded
nextAction = Action.Tidy;
} else {
nextAction = Action.EndGame;
}
} else if (i % 2 == 0) { // First bowl of frame
if (rolls[i] == 10) {
rolls.Insert (i, 0); // Insert virtual 0 after strike
nextAction = Action.EndTurn;
} else {
nextAction = Action.Tidy;
}
} else { // Second bowl of frame
nextAction = Action.EndTurn;
}
}
return nextAction;
}
}