-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHandleFile.java
More file actions
95 lines (71 loc) · 1.92 KB
/
Copy pathHandleFile.java
File metadata and controls
95 lines (71 loc) · 1.92 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
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Scanner;
public class HandleFile {
public static synchronized InfoPack inputFile(String file) throws ConflictException, FileNotFoundException {
// TODO Auto-generated method stub
InfoPack info = new InfoPack();
Scanner input = new Scanner(new File(file));
MyQueue<Integer> q = new MyQueue<Integer>();
int zeros = 0;
int size = 0;
while(input.hasNext()){
String s = input.next();
int i = Integer.parseInt(s);
if(i == 0)
zeros++;
q.enqueue(i);
}
input.close();
if(q.getSize() < 3 || zeros != 2 || (size = q.dequeue()) == 0)
throw new ConflictException("Input Error");
else info.setSize(size);
for(int i = q.dequeue();q.getSize() > 0;i = q.dequeue()) {
if (i == 0)
break;
else
info.addPebble(i, Board.WHITE);
}
for(int i = 0;;) {
if ((i = q.dequeue()) == 0)
break;
else info.addPebble(i, Board.BLACK);
}
/*System.out.println("Board size: "+info.getSize());
System.out.println("Initial Whites: "+info.getWhites().toString());
System.out.println("Initial Blacks: "+info.getBlacks().toString());
*/
return info;
}
public static void outputFile(Board board,String fileName) {
//int[] iteration = board.getBoard();
int n = board.getNumbers();
PrintWriter pw;
try {
pw = new PrintWriter(fileName);
for(int i = 0; i < n; i++) {
if(board.getColor(i) == Board.WHITE) {
pw.print(i + 1);
pw.print(" ");
}
}
pw.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
System.out.println("File already exists");
e.printStackTrace();
}
//for(int i; )
}
public static void CreateErrorFile(String fileName) {
PrintWriter pw;
try {
pw = new PrintWriter(fileName);
pw.print("UNSOLVABLE");
pw.close();
}
catch(Exception ex) {
}
}
}