-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathMatch.java
More file actions
37 lines (34 loc) · 1.18 KB
/
Match.java
File metadata and controls
37 lines (34 loc) · 1.18 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
package ticTacToe;
import java.util.*;
public class Match {
int m, n, k, c;
boolean log;
List<Player> players;
public Match(boolean log, int m, int n, int k, int c, Player firstPlayer, Player secondPlayer) {
this.log = log;
this.m = m;
this.n = n;
this.k = k;
this.c = c;
this.players = new ArrayList<>(List.of(firstPlayer, secondPlayer));
}
public void play() {
int[] wins = new int[players.size()];
int shift = 0;
while (wins[0 + shift] != c && wins[1 - shift] != c) {
Game game = new Game(log, players.get(0 + shift), players.get(1 - shift));
final int result = game.play(new MnkBoard(m, n, k, true));
if (result == 0) {
System.out.println("Draw");
} else if (result == 1 || result == 3) {
System.out.println("Player " + (1 + shift) + " won");
wins[0 + shift]++;
} else {
System.out.println("Player " + (2 - shift) + " won");
wins[1 - shift]++;
}
shift = (shift + 1) % 2;
}
System.out.println(wins[0] + ":" + wins[1]);
}
}