Skip to content

Instantly share code, notes, and snippets.

@kirarpit
Created August 5, 2018 02:55
Show Gist options
  • Save kirarpit/3acfbc55db3a62010457aaacdef13950 to your computer and use it in GitHub Desktop.
Save kirarpit/3acfbc55db3a62010457aaacdef13950 to your computer and use it in GitHub Desktop.
package c4;
import java.io.IOException;
import openingBook.Book;
import openingBook.BookSum;
import java.util.Scanner;
import java.io.File;
import java.io.FileWriter;
import java.io.BufferedWriter;
public class test {
public static void main(String[] args) {
BookSum books = new BookSum();
AlphaBetaAgent c4 = new AlphaBetaAgent(books);
File lock = new File("/Users/Arpit/DDQN/src/games/lock");
String outputFileName = "/Users/Arpit/DDQN/src/games/out.txt";
Scanner scanner = new Scanner(System.in);
String l;
while(true) {
if (scanner.hasNextLine()) {
try{
lock.createNewFile();
l = scanner.nextLine();
c4.resetBoard();
int player, move;
for(int i = 0; i < l.length(); i++) {
move = l.charAt(i) - '0';
player = (i%2 == 0)?1:2;
c4.putPiece(player, move);
}
player = (l.length()%2 == 0)?1:2;
String output="";
int winningMove;
if (c4.hasWin(player)) { // if can win in single move
winningMove = c4.rootNode(false);
for (int x = 0; x < 7; x++) {
if (x == winningMove) {
output += "1000 ";
}else{
output += "-1000 ";
}
}
}else{
for (int x = 0; x < 7; x++) {
if (c4.getColHeight(x) == 6){
output += "-1000 ";
}else{
c4.putPiece(player, x);
int result0 = c4.rootNode(true);
result0 *= (player == 2)?-1:1;
output += String.valueOf(result0) + " ";
c4.removePiece(player, x);
}
}
}
FileWriter fstream = new FileWriter(outputFileName, false);
BufferedWriter out = new BufferedWriter(fstream);
out.write(output);
out.close();
System.out.println(output);
System.out.println();
lock.delete();
}catch(IOException e){
e.printStackTrace();
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment