-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrules.cs
More file actions
151 lines (126 loc) · 4.54 KB
/
rules.cs
File metadata and controls
151 lines (126 loc) · 4.54 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SAPQuiz
{
class rules
{
private char[] availableColors = { 'y', 'g', 'b', 'r' };
private int[] ygbrQuantity = { 0, 0, 0, 0 };
//Implements rule 1.
public int rule1(char[] playerColors)
{
//Resets ygbrQuantity.
for (int i = 0; i < 4; i++)
{
ygbrQuantity[i] = 0;
}
separateColors(playerColors);
return getScore();
}
//Counts the number or red, green, yellow, and blue tokens.
private void separateColors(char[] playerColors)
{
//Loops through letters to compare.
for (int i = 0; i < availableColors.Length; i++)
{
//Loops through the players colors.
for (int j = 0; j < playerColors.Length; j++)
{
// Compares the chars.
if (playerColors[j].Equals(availableColors[i]))
{
ygbrQuantity[i]++;
}
}
}
}
//Returns a points value for each match combination.
private int getScore()
{
//Score will represent the value of the players color match combination.
int score = 0;
//Loops through the ygbtQuantity array. Assigns a score for each combination.
for (int j = 0; j < ygbrQuantity.Length; j++)
{
//3 of a kind gets 3 points.
if (ygbrQuantity[j] == 3)
{
score = 3;
break;
}
//2 of a kind gets 1 point unless there is another pair.
else if (ygbrQuantity[j] == 2)
{
score = 1;
//Checks the remaining tokens for a pair.
for (int k = j + 1; k < ygbrQuantity.Length; k++)
{
//2 pairs gets 2 points.
if (ygbrQuantity[k] == 2)//
{
score = 2;
}
}
break;
}
//4 of a kind gets 4 points.
else if (ygbrQuantity[j] == 4)
{
score = 4;
break;
}
}
return score;
}
//returns the produt of the player's drawn numbers.
public int rule2(int[] playerNumbers)
{
int product = 1;
//Loops through the player's token numbers.
for (int i = 0; i < playerNumbers.Length; i++)
{
//Multiplys the current product value by the value of the current token.
product = product * playerNumbers[i];
}
return product;
}
//Checks each of the player's tokens and assigns a pints value.
public int rule3(int[] playerNumbers, char[] playerColors)
{
//Stores the highest points value.
int score = 0;
//Loops through both arrays
for (int i = 0; i < 4; i++)
{
//Stores the points value of the current token.
int tokenNumber = 0;
//Checks the current tokens color and number and uses them to assign points.
switch (playerColors[i])
{
case 'r':
tokenNumber = playerNumbers[i];
break;
case 'g':
tokenNumber = 16 + playerNumbers[i];
break;
case 'b':
tokenNumber = 32 + playerNumbers[i];
break;
case 'y':
tokenNumber = 48 + playerNumbers[i];
break;
}
//If the current token's points value is more than the current round's
//highest value, the new highest points value is stored.
if (tokenNumber > score)
{
score = tokenNumber;
}
}
return score;
}
}
}