-
Notifications
You must be signed in to change notification settings - Fork 174
Expand file tree
/
Copy pathReferee.java
More file actions
41 lines (35 loc) · 1.14 KB
/
Referee.java
File metadata and controls
41 lines (35 loc) · 1.14 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
package model;
public class Referee {
private static int OFFSET = 3;
public int[] judgeGameScore(int[] userNumberArray, int[] computerNumberArray) {
int[] score = {0, 0}; // ball, strike
score[0] = countBall(userNumberArray, computerNumberArray);
score[1] = countStrike(userNumberArray, computerNumberArray);
return score;
}
public boolean judgeGameOver(int[] score) {
return score[1] == OFFSET;
}
private int countStrike(int[] userNumberArray, int[] computerNumberArray) {
int cnt = 0;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (userNumberArray[i] == computerNumberArray[j] && i == j) {
cnt++;
}
}
}
return cnt;
}
private int countBall(int[] userNumberArray, int[] computerNumberArray) {
int cnt = 0;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (userNumberArray[i] == computerNumberArray[j] && i != j) {
cnt++;
}
}
}
return cnt;
}
}