-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGame.java
More file actions
42 lines (33 loc) · 1.25 KB
/
Copy pathGame.java
File metadata and controls
42 lines (33 loc) · 1.25 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
import java.io.*;
import java.util.*;
public class Game {
public static void main(String arg[]) {
// in the game, player have the first hand by default,player always use
// white chess, AI uses black chess
System.out.println("welcome to five-in-a-row");
System.out.println("Once you put 5 consecutive pieces on one axis"+
"(could be horizontal line,vertical line or diagonal line)"+ "then you win!");
System.out.println();
Board b = new Board();
Player player = new Player();
AI ai = new AI();
b.print();
while (true) {
System.out.print("row input: ");
Scanner srow = new Scanner(System.in);
int row = srow.nextInt() -1;
System.out.print("column iput:");
Scanner scol = new Scanner(System.in);
int col = scol.nextInt() -1;
boolean checkmove = player.move(b,row,col);
if (!checkmove) {
System.out.println("invalid move! Please try again");
continue;
}
if (player.getWin() == true) break;
ai.algorithm(b);
if (ai.getWin() == true) break;
}
System.out.println("Game over");
}
}