Skip to content

Instantly share code, notes, and snippets.

View mdakram28's full-sized avatar
💻
Coding and Hackathons

Akram Ansari mdakram28

💻
Coding and Hackathons
View GitHub Profile
import java.util.logging.Level;
import java.util.logging.Logger;
public class TicTacToe extends javax.swing.JFrame {
static int winComb[][] = {{1,2,3},{4,5,6},{7,8,9},{1,4,7},{2,5,8},{3,6,9},{1,5,9},{3,5,7}};
public static int[][] state = {{0,0,0},{0,0,0},{0,0,0}};
Player pl1 = new Human();
Player pl2 = new Computer("mind\\layer");
public abstract class Player {
void playTurn(int pl,int turn){}
void playerInit(){}
void notifyWin(int pl){}
void notifyLose(int pl){}
}
public class Human extends Player {
@Override
void playTurn(int pl,int turn){
while(TicTacToe.butClicked == 0);
switch(TicTacToe.butClicked)
{
case 1 : TicTacToe.state[0][0]=pl;break;
case 2 : TicTacToe.state[0][1]=pl;break;
case 3 : TicTacToe.state[0][2]=pl;break;
import java.io.*;
import java.util.ArrayList;
public class Computer extends Player {
int t=0;
Node begin = new Node("000000000",0,this);
Node current = begin;
import java.util.ArrayList;
public class Node {
ArrayList<Node> sub_nodes = new ArrayList<Node>();
String subNodes="";
String id="";
int pref = 0;
int n=0;
import java.util.ArrayList;
public class Layer {
ArrayList<Node> nodes = new ArrayList<Node>();
int layerNum = 0;
public Layer(int Num){
layerNum = Num;
}
void playTurn(int pl,int turn){
while(TicTacToe.butClicked == 0);
switch(TicTacToe.butClicked)
{
case 1 : TicTacToe.state[0][0]=pl;break;
case 2 : TicTacToe.state[0][1]=pl;break;
case 3 : TicTacToe.state[0][2]=pl;break;
case 4 : TicTacToe.state[1][0]=pl;break;
case 5 : TicTacToe.state[1][1]=pl;break;
case 6 : TicTacToe.state[1][2]=pl;break;
for(int i=0;i<9;i++)
{
layerFiles[i] = new File(l+(i+1)+".nodes");
if(!layerFiles[i].exists())
{
try{
layerFiles[i].createNewFile();
}
catch(Exception e)
{
public void playNext1(){
ArrayList<Node> temp = new ArrayList<Node>();
//System.out.println(id+" : "+sub_nodes.size());
long max = sub_nodes.get(0).pref;
for(int i=0;i<sub_nodes.size();i++)
{
if(sub_nodes.get(i).pref > max)
{
temp.clear();
temp.add(sub_nodes.get(i));
0x999Ac312D598Ab0Ac4C09463a6faf5C21A4A47Ec