-
Notifications
You must be signed in to change notification settings - Fork 1
/
Mancala.java
86 lines (74 loc) · 2.99 KB
/
Mancala.java
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
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package mancala;
import java.io.*;
/**
*
* @author Neelam
*/
public class Mancala {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException{
// TODO code application logic here
FileInputStream fileInputStream=null;
InputStreamReader inputStreamReader=null;
BufferedReader bufferedReader=null;
try{
fileInputStream=new FileInputStream(args[2]);
inputStreamReader=new InputStreamReader(fileInputStream);
bufferedReader=new BufferedReader(inputStreamReader);
//Read input file
int task=Integer.parseInt(bufferedReader.readLine().trim());
int player=Integer.parseInt(bufferedReader.readLine().trim());
int cuttingDepth=Integer.parseInt(bufferedReader.readLine().trim());
String[] boardPlayer2=bufferedReader.readLine().trim().split(" ");
String[] boardPlayer1=bufferedReader.readLine().trim().split(" ");
int boardSize=boardPlayer2.length;
int[] board2=new int[boardSize];
int[] board1=new int[boardSize];
for(int i=0;i<boardSize;i++){
board2[i]=Integer.parseInt(boardPlayer2[i].trim());
board1[i]=Integer.parseInt(boardPlayer1[i].trim());
}
int mancala2=Integer.parseInt(bufferedReader.readLine().trim());
int mancala1=Integer.parseInt(bufferedReader.readLine().trim());
Game g=new Game(player, board2, board1, mancala2, mancala1);
Utility util=new Utility();
//Call Greedy or Minimax or AlphaBeta method based on value specified in input
if(!util.GameOver(g)){
switch(task){
case 1:
Greedy gr=new Greedy();
gr.greedy(g);
break;
case 2:
Minimax mm=new Minimax(cuttingDepth);
mm.minimax(g);
//mm.writerNextState();
//mm.writeTraverseLog();
break;
case 3:
AlphaBeta ab=new AlphaBeta(cuttingDepth);
ab.alphabeta(g);
break;
case 4:
//competition
break;
}
}
}
catch(Exception ex){
System.out.println("Exception occured : "+ex.getMessage());
}
finally{
bufferedReader.close();
inputStreamReader.close();
fileInputStream.close();
}
}
}