AI Based Tic Tac Toe (Java Code) - CodeProject



Comments



Description

6/3/2016AI based Tic Tac Toe (java code) ­ CodeProject 12,309,265 members ﴾58,870 online﴿ Sign up for our free weekly Web Developer Newsletter. articles Q&A forums lounge Sign in × Search for articles, questions, tips AI based Tic Tac Toe ﴾ java code﴿ Mohd Akram, 27 May 2014 CPOL Rate this:    5.00 ﴾12 votes﴿ Java Tic Tac Toe ﴾ AI based ﴿ Introduction This project was originally developed by Mohd Akram. This project is a simple demonstration of the power of AI. The friendly language will help you easily understand the code. Hope that after reading this post you might be more interested in AI than before and would develop much better applications. Using the code A brief description of the classes and their methods... http://www.codeproject.com/Articles/778260/AI­based­Tic­Tac­Toe 1/25 6/3/2016 AI based Tic Tac Toe (java code) ­ CodeProject file : TicTacToe.java class : TicTacToe global variables : winComb ‐ int[][] : all winning situations state ‐ int[][] : Current state of the Game pl1 ‐ Player : Player 1 object ﴾Computer / Human﴿ pl2 ‐ Player : Player 2 object ﴾Computer / Human﴿ butClicked‐ int : Buttton recently clicked by the user w1 ‐ int : Number of games won by Player1﴾X﴿ w2 ‐ int : Number of games won by Player1﴾O﴿ dr ‐ int : Number of game draws Methods : public TicTacToe﴾﴿ public void start﴾﴿ public void refreshGrid﴾﴿ public static int checkWin﴾int turn,int[][] st﴿ public static int checkWin2﴾String x,String o﴿ public void print﴾String s﴿ public void gameInit﴾﴿ private void initComponents﴾﴿ file : Player.java class : Player ﴾abstract﴿ global variables : none Methods : void playTurn﴾int pl,int turn﴿ void playerInit﴾﴿ void notifyWin﴾int pl﴿ void notifyLose﴾int pl﴿ file : Human.java class : Human ﴾extends Player﴿ global variables : none Mathods : void playTurn﴾int pl,int turn﴿ // overriden file : Computer.java class : Computer ﴾extends Player﴿ global Variables : t ‐ int ‐ Turn number begin ‐ Node ‐ top element of the state tree current ‐ Node ‐ Current Node of state tree layerFiles ‐ File[] ‐ Layer Files from layer1 ...... layer 9 layers ‐ ArrayList<Layer> ‐ layers of memory tree Methods : http://www.codeproject.com/Articles/778260/AI­based­Tic­Tac­Toe 2/25 </script> <script type="text/javascript" src="http://resources. " id ‐ String ‐ id of Current Node pref ‐ int ‐ Preference value of current Node n ‐ int ‐ No..int l.com/Articles/778260/AI­based­Tic­Tac­Toe 3/25 ..java class : Node global variables : sub_nodes ‐ ArrayList<Node> ‐ connections of this node to its subNodes subNodes ‐ String ‐ Temporary storing id's of subNodes separated by " .com/js/infolinks_main..js"></script> The model of the game can be summarized as follows . of times this node is played lNum ‐ int ‐ The layer number in which this node exists in the memory tree comp ‐ Computer ‐ The Computer object this node belongs to nodeType ‐ int ‐ Stores whether this node is end node or not Methods : public Node﴾String i.java class : Layer global Variables : nodes ‐ ArrayList<Node> ‐ Stores reference to the Nodes in that Layer layerNum ‐ int ‐ Stores Layer Number﴾1‐9﴿ Methods : public void refreshLayer﴾﴿ public Node searchByState﴾int[][] state﴿ public Node searchById﴾String id﴿ DESCRIPTION. var infolinks_wsid = 0..Computer c﴿ public void setAsState﴾﴿ public void playNext1﴾﴿ public void playNext2﴾﴿ public void playNextn﴾﴿ public void extractNodes﴾﴿ file : Layer.codeproject. <script type="text/javascript"> var infolinks_pid = 2110076..int turn﴿ // overriden void notifyWin﴾int pl﴿ // overriden void notifyLose﴾int pl﴿ // overriden file : Node.infolinks. http://www..6/3/2016 AI based Tic Tac Toe (java code) ­ CodeProject public Computer﴾String l﴿ public void evaluate﴾﴿ public void loadMind﴾﴿ public void saveMind﴾﴿ public void makeNewMind﴾﴿ public void playTurn﴾int p. 1 stands for 'x' and 2 stands for 'o'.updates the display and breaks the game whenever there is a win situation. The bare at the right side of the jFrame shows three status : Number of games won by either player and Number of Draws.. The game alternately calls the playTurn methods of each player starting from player 1. The Human Class http://www.codeproject. All the internel processing of the next Turn takes place by the Player object.There is also a notification bar at the bottom of the jFrame. the method of finding the favourable state is explained later. The Classes Human and Computer extend the Player class hence an object of either class can be stored in pl1 and pl2 objects.6/3/2016 AI based Tic Tac Toe (java code) ­ CodeProject The Game follows a very easy method of getting the most probable next chance .. notifyLose﴾﴿ etc.. The Main Class﴾Tic Tac Toe﴿ Tic Tac Toe is the main class : The state variable of type int[][] stores the state of the game. The method "checkWin﴾﴿" checks win situation. The Display The display part contains a 9x9 grid of jButtons. The GUI of the game is made with netbeans Form maker. It contains some necessary functions which a player should contain like playTurn﴾﴿ .The text on top of these shows the block status. notifyWin﴾﴿ .com/Articles/778260/AI­based­Tic­Tac­Toe 4/25 . It is a 3x3 array initially filled with 0's. The Player Class This is an abstract class and is extended by a player type. There are two objects of type Player named "pl1" and "pl2". The possible states of the game are stored in objects named Node. The makeNewMind﴾﴿ method creates new Nodes or possible states of the Game without the layer Files and stores them in layer objects. If the layer files do not exist the computer makes new layer Files. If the layer files do not exist the computer makes new layer Files.000100000. The saveMind﴾﴿ method saves the layers date ﴾i.createNewFile().          begin. Each Node containes information about its state. Initializing the Computer Hide   Copy Code for(int i=0.. There are nine layer files. Then Comes the part where the computer memory is created. current states .i++)          {              layerFiles[i] = new File(l+(i+1)+".At each call of the PlayTurn﴾﴿ the computer finds the most preferred state of the game after the current state by looking at the subNodes of the Current Node. The method to fill a block by a Human Player is .          makeNewMind().000000100..   The computer object is provided with a file path to the Layer Files which contain list of all the Nodes.0000 00001.exists())              {                  try{                      layerFiles[i]. Each Character shows a cell. http://www.000010000.println(e).001000000.subNodes="100000000.000000010.. example of an id is : "220211001" which represents the state shown on top of the page. 1 shows 'x' and 2 shows 'o'.evaluate(). it waits until the user presses one of the button from the 9x9 grid. There are nine layer files.There are two methods of finding and updating the preference values.out. the Nodes data﴿ into layer Files. Then Comes the part where the computer memory is created.com/Articles/778260/AI­based­Tic­Tac­Toe 5/25 . These Layer Files can be used to retain the memory of the game after the game exists.e.6/3/2016 AI based Tic Tac Toe (java code) ­ CodeProject This is the interface between the human and the game . Each Node has an id which represent the state of the Node. The COMPUTER Class This is where the main part of artificial intelligence comes.".000001000.nodes"). If it's an even No the object fills 'o' in the required cell otherwise it fills 'a' by setting the state variable of the Main class which updates the display after receiving a new state. 0 shows blank cell.              if(!layerFiles[i]. The Computer classes a tree method to store the possible sates . The Node also contains references to the nodes which can be played after the current node is played.010000000. When the playTurn﴾﴿ method is callled . and there preferences . Then it evalutes the Winning and Losing Situations by and updates their preference values by 100 and ‐100 respectively.                  }                  catch(Exception e)                  {                      System.saveMind(). The static variable butPressed gives the recently pressed button and this inforation is used by the player Human class to fill a cell with 'x' or 'o' depending on the player turn Number.The Most Preffered state is obtained by comparing the preference values of the subNodes and the subNode with largest value is set as the current state and also as the Current Node. The notifyWin﴾﴿ and notifyLose﴾﴿ have nothing to do with the Human class hence are empty.                  }              }          }          //loadMind(). The id is a String of 9 characters.codeproject.extractNodes().           begin.i<9. The existing Mind Files can be loaded by loadMind﴾﴿ method. The computer object is provided with a file path to the Layer Files which contain list of all the Nodes.   http://www. Then it evalutes the Winning and Losing Situations by and updates their preference values by 100 and ‐100 respectively.i<sub_nodes.              for(int i=0.size()). The saveMind﴾﴿ method saves the layers date ﴾i.          //System.clear().                  }              }                    int choice = (int) (Math.                  }                  else if(sub_nodes.get(i).get(choice).get(i)).size()).get(i).codeproject.          temp.get(choice).get(0).get(i).size()).e.add(sub_nodes.get(choice).              for(int i=0.setAsState(). blank node﴿.pref < min)                  {                      temp.get(i)).random()*temp.clear().size().pref.﴿ and the PlayNextn﴾﴿.com/Articles/778260/AI­based­Tic­Tac­Toe 6/25 .pref == min)                  {                      temp.get(i).          temp.          temp.pref.println(id+" : "+sub_nodes.It is then manually connected to its possible subNodes by setting the variable subNodes and then calling extractNodes﴾﴿. These Layer Files can be used to retain the memory of the game after the game exists.get(i)).i++)              {                  if(sub_nodes.get(choice).pref.out. The two methods are PlayeNext1﴾﴿/PlayeNext2﴾﴿﴾depending on the player No.get(i).n++.                      temp. The Node "begin" is the first node of the Game ﴾i.i<sub_nodes.                  }                  else if(sub_nodes.          long min = sub_nodes.pref.                      temp.pref > max)                  {                      temp. The existing Mind Files can be loaded by loadMind﴾﴿ method.      }            public void playNextn(){          ArrayList<Node> temp = new ArrayList<Node>(). Playing the Turn The computer plays the nextTurn by the process written above.add(sub_nodes.                  }              }                    int choice = (int) (Math.setAsState().add(sub_nodes.e.                      min = sub_nodes.get(i)).get(i).                      max = sub_nodes. the Nodes data﴿ into layer Files.          long max = sub_nodes.println(id+" : "+sub_nodes.          temp.size()).random()*temp. Hide   Shrink   Copy Code public void playNext1(){          ArrayList<Node> temp = new ArrayList<Node>().size().      }            public void playNext2(){          ArrayList<Node> temp = new ArrayList<Node>().get(0).n++.i++)              {                  if(sub_nodes.6/3/2016 AI based Tic Tac Toe (java code) ­ CodeProject The makeNewMind﴾﴿ method creates new Nodes or possible states of the Game without the layer Files and stores them in layer objects.out.add(sub_nodes.pref == max)                  {                      temp.          //System. This way the computer will go away from this node and thus will go toward a winning situation.          int w=0.logging.exit(0).{3.com/Articles/778260/AI­based­Tic­Tac­Toe 7/25 .          int current = 1 . This method is useful when doing the evaluation process.0}.0}}.6.n++.{0.{2.5.get(choice). The PlayNextn﴾﴿ method plays the turn which is played least no of times thus not leaving any stone unturned.setAsState().5.      }            public void start(){          if(w1==500)System.{0. dr = 0.0.      Player pl1 = new Human(). the blank node﴿.get(i). This way the node having no chances of winning in the nextTurn hence having no positive value in its subNodes will have very less value of its own . Files : TicTacToe.n.println(id+" : "+sub_nodes.size()).5.swing.JFrame {      static int winComb[][] = {{1. When playing against a human it's better to use the PlayNext1﴾﴿ method to play the turn because it makes best use of what it learned from previous games.0.          long min = sub_nodes.      int w1=0 .codeproject. This way upon playing many times by the playNextn﴾﴿ method we will get a clear map of the preferred and not unfavoured sates and what path to take in order to reach a highly favoured winning state.          while((w=checkWin(turn.get(i).java Hide   Shrink   Copy Code import java.{7.logging.0.{1.Logger.i<sub_nodes.n < min)                  {                      min = sub_nodes.util. turn = 1.get(0).7}.9}.9}.{3.      }  The playnext1﴾﴿ method prepares a list of all the Nodes having maximum preferences and then plays one of them.util.7}}.          sub_nodes.      Player pl2 = new Computer("mind\\layer").4.3}.get(choice).{4.  import java.9}.      public static int[][] state = {{0.                      choice = i.0}. The Computer class does the job of finding the prefernces of all the nodes except the repfernce of the beginning node﴾i.          int choice = 0.      public static int butClicked = 0.{1.8.size().i++)              {                  if(sub_nodes.n.Level.6}.2.out.              for(int i=0.  public class TicTacToe extends javax.                  }              }                    sub_nodes. w2 = 0 .8}.      public TicTacToe() {          initComponents().e.6/3/2016 AI based Tic Tac Toe (java code) ­ CodeProject         //System.state))==0)          {  http://www. On getting a win or lose state the Computer is notified and thus the computer decreases the preference of the current node by 10 if its a losing notification and if its a winning notification the computer increases the value of the currrent node by 10.5. Method of finding preference : The computer finds the preference f a node by adding the preferences of all its subNodes. setText(state[2][2]==1?"X":(state[2][2]==2?"O":"")).          b21.              w2++.getLogger(TicTacToe.          String o ="".          jLabel2.          }          else if(w==2)          {              pl2.          int i=0 .}      }            public void refreshGrid(){          b11. null.codeproject.sleep(0).notifyLose(2).          }          try {Thread.              pl2.          b13.notifyLose(2).setText(state[1][2]==1?"X":(state[1][2]==2?"O":"")).p++)          {              for(q=0.setText(state[1][1]==1?"X":(state[1][1]==2?"O":"")).setText(" X wins : "+w1).              dr++.q<3.          }          else if(w==‐1)          {              print("Game DRAW !").SEVERE. ex).          b22.notifyWin(1).setText(state[0][2]==1?"X":(state[0][2]==2?"O":"")).playTurn(1.setText(state[2][1]==1?"X":(state[2][1]==2?"O":"")).                  refreshGrid().          b32.              w1++.notifyWin(1).sleep(0).          String x ="".turn).                  refreshGrid().getName()).          b12.} catch (InterruptedException ex)  {Logger. p .setText(" O wins : "+w2).playTurn(2. null.setText(state[1][0]==1?"X":(state[1][0]==2?"O":"")).              print("Player 2 Won The Game !").setText(state[0][1]==1?"X":(state[0][1]==2?"O":"")). q.}          }          if(w==1)          {              pl1.log(Level.p<3.          jLabel1.setText(state[2][0]==1?"X":(state[2][0]==2?"O":"")).              print("Player 1 Won The Game !").int[][] st){         int ret = 0.              try {Thread.          b33.getLogger(TicTacToe.          jLabel3. ex).6/3/2016 AI based Tic Tac Toe (java code) ­ CodeProject             if(current == 1)              {                  pl1.          for(p=0. c=0 .com/Articles/778260/AI­based­Tic­Tac­Toe 8/25 .                  current = 1.setText(state[0][0]==1?"X":(state[0][0]==2?"O":"")).          b23.      }            public static int checkWin(int turn.          b31.              }              turn++.} catch (InterruptedException ex)  {Logger.                  current = 2.                  if(st[p][q]==1)  http://www.setText(" Draws  : "+dr).              }              else if(current == 2 )              {                  pl2.              pl1.q++)              {                  c++. j=0 .class.SEVERE.getName()).turn).class.log(Level.           state[2][1] = 0.              }              if(o.          ret = checkWin2(x.codeproject.          for(p=0.          state[1][2] = 0.                    if(turn==10 && ret==0)          {              ret = ‐1.          state[2][0] = 0.                  }                  else if(st[p][q]==2)                  {                      o+=c.          state[1][1] = 0.p++)          {                            if(x.o).indexOf((char)winComb[p][2]+'0')>‐1)              {                  ret = 1.indexOf((char)winComb[p][0]+'0')>‐1 && x.          int p.6/3/2016 AI based Tic Tac Toe (java code) ­ CodeProject                 {                      x+=c.      }      public void print(String s){          Notification.indexOf((char)winComb[p][0]+'0')>‐1 && o.setText("\t"+s).      }      public static int checkWin2(String x.          state[0][1] = 0.              }          }                    return ret.com/Articles/778260/AI­based­Tic­Tac­Toe 9/25 .          state[0][2] = 0.                  break.          }          return ret.          refreshGrid().          state[1][0] = 0.      }            public void gameInit(){          state[0][0] = 0.indexOf((char)winComb[p][1]+'0')>‐1 &&  o.      }                                                @SuppressWarnings("unchecked")      // <editor‐fold defaultstate="collapsed" desc="Generated Code">//GEN‐BEGIN:initComponents  http://www.String o){          int ret = 0.p<8.indexOf((char)winComb[p][2]+'0')>‐1)              {                  ret = 2.          state[2][2] = 0.indexOf((char)winComb[p][1]+'0')>‐1 &&  x.                  }              }          }          //print(x+" : "+o).                  break. awt.awt.swing.ActionListener() {              public void actionPerformed(java.swing.JButton().ActionListener() {              public void actionPerformed(java.          } catch (java.awt.          jLabel6 = new javax.  "TicTacToe_jPanel1").setCursor(new java.JLabel().swing.JButton().          b12 = new javax. // NOI18N          b22.          b13 = new javax.swing.ActionEvent evt) {                  b12ActionPerformed(evt). 400)). 1.          b11.          jLabel2 = new javax.com/Articles/778260/AI­based­Tic­Tac­Toe 10/25 .setBackground(new java.JLabel().swing.              }          }).addActionListener(new java.HAND_CURSOR)).JButton().ActionListener() {              public void actionPerformed(java.awt.          b33 = new javax.swing.setCursor(new java.          jLabel1 = new javax.swing.HAND_CURSOR)).JButton().event.awt.swing.          b11.JLabel().JLabel().          setAlwaysOnTop(true).instantiate(getClass().          } catch (ClassNotFoundException e) {              e. // NOI18N          b21.          b21.awt.Beans.awt.event. 255)).6/3/2016 AI based Tic Tac Toe (java code) ­ CodeProject     private void initComponents() {          try {              jPanel1 =(javax.JPanel().ActionEvent evt) {                  b22ActionPerformed(evt).Color(255.EXIT_ON_CLOSE).addActionListener(new java.swing.         b11.          b22.Font("Arial".JButton().          jPanel2 = new javax.event.swing.swing.          b12.setFont(new java.setFont(new java.printStackTrace(). 48)). 48)).awt.event.setCursor(new java.          }          b21 = new javax.          b12.swing.awt.JButton().          b31 = new javax.awt.          b32 = new javax.Cursor.JLabel().Cursor(java. 255. 1.awt.Cursor.          setPreferredSize(new java.io.Color(255. 255)).          b21.setBackground(new java.awt.          jLabel4 = new javax.awt. // NOI18N          b12.JButton().Cursor.ActionEvent evt) {                  b21ActionPerformed(evt).setCursor(new java. 255.awt.          setDefaultCloseOperation(javax.codeproject.Font("Arial".beans.setFont(new java. 1.event.ActionEvent evt) {                  b11ActionPerformed(evt).HAND_CURSOR)).JPanel)java.addActionListener(new java.setFont(new java.IOException e) {              e.printStackTrace().event.awt.awt.awt.JLabel().awt.          Notification = new javax. 48)). 255)).ActionListener() {              public void actionPerformed(java.          jLabel3 = new javax.swing.swing.Dimension(600.swing.setBackground(new java.swing.awt.awt.awt. 1.  http://www.addActionListener(new java.JLabel(). 255.JButton().swing.swing.event.Color(255.Font("Arial".HAND_CURSOR)).Cursor(java.Color(255.Cursor(java.Cursor.          b11 = new javax.event. 255)).awt.          b22 = new javax.getClassLoader().JButton().         b22.awt.swing.awt.              }          }).awt.Cursor(java.setBackground(new java.          b23 = new javax. 48)). 255.WindowConstants.              }          }). // NOI18N          b11.         b21.          jLabel5 = new javax.Font("Arial".          b22.         b12.         b23.codeproject. 255.ActionEvent evt) {                  b32ActionPerformed(evt). 255)).Font("Arial".Color(0.Cursor.Color(255.awt. 48)).          Notification.awt.setFont(new java.addActionListener(new java.Color(0.setBackground(new java.              }          }).awt. 255.awt.Cursor(java.ActionListener() {              public void actionPerformed(java.Font("Arial".BorderFactory.          b31. 0.event.event.         b31.          Notification. 1.event.createLineBorder(new java.awt.BorderFactory.Color(255.ActionListener() {              public void actionPerformed(java. // NOI18N          jLabel4.setFont(new java.Font("Arial".setBorder(javax.swing.awt. 18)).setFont(new java.setFont(new java. 255.createLineBorder(new java.com/Articles/778260/AI­based­Tic­Tac­Toe 11/25 . 0))). // NOI18N          b32. // NOI18N          jLabel2.awt.          b23.awt.awt. // NOI18N          jLabel1.awt. 255)).BorderFactory.Font("Arial".awt.6/3/2016 AI based Tic Tac Toe (java code) ­ CodeProject             }          }). 0.          jLabel3.Color(0.              }          }).setBackground(new java.              }          }).          jLabel1.swing.ActionListener() {              public void actionPerformed(java. 48)).awt.createLineBorder(new java.ActionListener() {              public void actionPerformed(java.awt.          b13.awt. 18)).addActionListener(new java. 102)).awt.setCursor(new java.ActionEvent evt) {                  b33ActionPerformed(evt).awt.              }          }).setBackground(new java. 255)).swing. 48)). 1.          b13. 255.          b33.border.awt. // NOI18N          b23.awt. 18)).         b33. 255)).MatteBorder(null)).setText("Tic ‐ Tac ‐ Toe"). // NOI18N          jLabel3.setBorder(javax.Cursor.HAND_CURSOR)).event.setFont(new java. // NOI18N          b13.Font("Arial".awt.awt.setBackground(new java.          b33.awt.ActionEvent evt) {                  b13ActionPerformed(evt).addActionListener(new java.awt.awt.Cursor.awt. 0.awt. 255)).          b31. 0.Cursor(java.event.event.setCursor(new java.Font("Arial".awt.ActionEvent evt) {                  b23ActionPerformed(evt). 1.setFont(new java. 18)).awt.Color(255.          b23.Font("Tahoma".setBackground(new java.awt.setFont(new java.HAND_CURSOR)). 1.awt.Cursor(java.BorderFactory. // NOI18N          Notification.setCursor(new java. 48)).Cursor.addActionListener(new java.Cursor(java.setFont(new java. 18)).addActionListener(new java.awt. // NOI18N          b31.Color(255. 0.swing. 255.awt.setCursor(new java.setForeground(new java. 0))).              }          }).setCursor(new java.Cursor(java.ActionEvent evt) {                  b31ActionPerformed(evt).awt. 0. 0.HAND_CURSOR)).  http://www.event.awt.setFont(new java.          b32.awt.awt.Color(0.          b32.HAND_CURSOR)). 0))). 0.setBorder(javax.awt.Cursor.awt.Font("Arial".awt.          Notification. 0.          jLabel4.createLineBorder(new java.event.HAND_CURSOR)).Color(255.event. 255.setBackground(new java.awt. 0))).awt.          Notification.swing.Color(255. 1.Font("Arial".setFont(new java.          jLabel2. 0)).setBorder(new javax.ActionListener() {              public void actionPerformed(java.Font("Arial".         b32.event. 48)).setBorder(javax.awt.         b13. // NOI18N          b33.Color(0. 0. createLineBorder(new java.GroupLayout.swing.addComponent(jLabel5.  javax.          jPanel1.swing.  javax. 0.createParallelGroup(javax.BorderFactory.addGroup(jPanel2Layout.addPreferredGap(javax. 18)).LEADING)              .swing.GroupLayout.swing.awt.          jPanel2Layout.addComponent(Notification.addPreferredGap(javax.PREFERRED_SIZE)                  . javax.addGroup(jPanel1Layout.  javax.LEADING)              .  javax.swing.GroupLayout.DEFAULT_SIZE.addContainerGap()                   .GroupLayout(jPanel1). Short.GroupLayout jPanel2Layout = new javax.setHorizontalGroup(              jPanel1Layout.createParallelGroup(javax. javax.GroupLayout.Alignment.swing.Color(0.  javax.          jPanel2.awt.  http://www.  Short.DEFAULT_SIZE.createSequentialGroup()                  . 0.LayoutStyle.  javax. javax.setBorder(javax.6/3/2016 AI based Tic Tac Toe (java code) ­ CodeProject         jLabel5.addComponent(jLabel3.createParallelGroup(javax. 40.MAX_VALUE))          ).swing.addComponent(jLabel4.addGroup(jPanel1Layout. 203.addPreferredGap(javax. Short. 0))).PREFERRED_SIZE)                  .BorderFactory.GroupLayout.GroupLayout. javax.DEFAULT_SIZE.getAccessibleContext().          javax. javax.MAX_VALUE)                      .ComponentPlacement.swing.LayoutStyle.Color(0.GroupLayout.DEFAULT_SIZE.swing.setLayout(jPanel2Layout).LEADING)                      .addContainerGap(javax.Alignment.addComponent(jLabel2.swing.RELATED)                  .DEFAULT_SIZE.addComponent(jLabel5.addComponent(jLabel1.addComponent(jLabel3.PREFERRED_SIZE.GroupLayout. javax. 40.          jLabel1.setBorder(javax.RELATED)                  .swing.LayoutStyle.addPreferredGap(javax.GroupLayout.ComponentPlacement.GroupLayout.swing.addContainerGap()                   .MAX_VALUE))                  . Short.PREFERRED_SIZE)                  .createLineBorder(new java.swing.swing.GroupLayout.createSequentialGroup()                  .DEFAULT_SIZE. 0.swing.swing.swing.ComponentPlacement. Short.MAX_VALUE)                      . 40.addContainerGap()                  .  javax.Alignment.setVerticalGroup(              jPanel2Layout. // NOI18N          jLabel6.GroupLayout. 40. Short.GroupLayout. javax.LayoutStyle.swing.GroupLayout.RELATED)                  .GroupLayout.addPreferredGap(javax.PREFERRED_SIZE.addGroup(jPanel2Layout.getAccessibleContext().swing.createParallelGroup(javax.          jLabel6. javax.awt.swing.addComponent(jLabel6.addComponent(jLabel2.          jPanel1Layout.DEFAULT_SIZE. javax.createParallelGroup(javax.  javax.PREFERRED_SIZE.addComponent(jLabel1.swing.          javax.RELATED)                  .awt.swing.Alignment. javax.GroupLayout.GroupLayout.LayoutStyle.swing.swing.PREFERRED_SIZE)                  .PREFERRED_SIZE. Short.addContainerGap())          ).GroupLayout(jPanel2).swing.codeproject.Font("Arial".swing.setLayout(jPanel1Layout).DEFAULT_SIZE.swing. 40.  javax.swing.Alignment. javax.          jPanel2Layout.GroupLayout. javax.          jLabel1.swing.swing.setFont(new java.PREFERRED_SIZE.GroupLayout.DEFAULT_SIZE.addComponent(jLabel4.swing.GroupLayout.addComponent(jLabel6.swing.MAX_VALUE)                      .PREFERRED_SIZE)                  .ComponentPlacement. 0))).swing. 0.GroupLayout.swing.GroupLayout.GroupLayout.GroupLayout.GroupLayout. 18)).com/Articles/778260/AI­based­Tic­Tac­Toe 12/25 .MAX_VALUE)                      .swing.PREFERRED_SIZE.DEFAULT_SIZE.GroupLayout.PREFERRED_SIZE)                  .DEFAULT_SIZE.setFont(new java.Font("Arial". // NOI18N          jLabel5.DEFAULT_SIZE.addGroup(jPanel2Layout. javax. 40.RELATED)                  .swing.createSequentialGroup()                  .LEADING)                      .  javax.GroupLayout.  javax.swing.swing.setHorizontalGroup(              jPanel2Layout.GroupLayout.setAccessibleName("l1").swing.swing.GroupLayout jPanel1Layout = new javax.MAX_VALUE)                      .DEFAULT_SIZE.GroupLayout.swing.GroupLayout.LEADING)              .setAccessibleDescription("").ComponentPlacement. DEFAULT_SIZE.  javax.PREFERRED_SIZE))))                              .PREFERRED_SIZE.  javax. javax.swing.swing.swing.GroupLayout.PREFERRED_SIZE)                              .createParallelGroup(javax.PREFERRED_SIZE.ComponentPlacement.GroupLayout.LayoutStyle.swing.  javax.PREFERRED_SIZE)                              .PREFERRED_SIZE)                                           .GroupLayout.GroupLayout. javax.RELATED)                                          .createParallelGroup(javax.createParallelGroup(javax.RELATED)                                  .GroupLayout. 100.swing.Alignment.GroupLayout.  http://www.addComponent(b23.addComponent(b13.swing.GroupLayout. 100.PREFERRED_SIZE)                                           . javax.addGroup(jPanel1Layout.addContainerGap()                   .swing.LEADING)                              .swing.swing.  javax.addComponent(b33.Alignment.LEADING)                                      .GroupLayout.createSequentialGroup()                                          .PREFERRED_SIZE))                                  . javax.PREFERRED_SIZE))                                      .createParallelGroup(javax.GroupLayout.Alignment. 100.GroupLayout.createSequentialGroup()                  .LayoutStyle.ComponentPlacement.swing. javax.PREFERRED_SIZE)                                  .LayoutStyle.MAX_VALUE)                      .GroupLayout.LayoutStyle.swing.addPreferredGap(javax.swing.PREFERRED_SIZE.swing.PREFERRED_SIZE.addGroup(jPanel1Layout.swing.PREFERRED_SIZE.addGroup(jPanel1Layout.addPreferredGap(javax.Alignment.swing.GroupLayout.Alignment.swing.6/3/2016 AI based Tic Tac Toe (java code) ­ CodeProject javax.swing.LayoutStyle.swing.GroupLayout.  100.swing.RELATED)                                          .PREFERRED_SIZE.swing.createSequentialGroup()                           .GroupLayout.RELATED)                                  . 100.addGroup(jPanel1Layout.GroupLayout. javax.swing. false)                      . javax.swing.swing.swing. javax.ComponentPlacement.  100.swing.  javax.addPreferredGap(javax.ComponentPlacement. javax.addGroup(jPanel1Layout.swing.  javax.PREFERRED_SIZE.PREFERRED_SIZE.GroupLayout.swing.swing.LEADING)                              .PREFERRED_SIZE.BASELINE)                              . 100.swing.GroupLayout.PREFERRED_SIZE)                                  .PREFERRED_SIZE.LayoutStyle.createParallelGroup(javax.swing.addComponent(b11.PREFERRED_SIZE.GroupLayout.addComponent(b13.addGroup(jPanel1Layout.swing.GroupLayout.  javax.addGroup(jPanel1Layout. 100. javax.DEFAULT_SIZE.GroupLayout.Alignment.swing.  javax.GroupLayout. Short. 100.addComponent(b22.createSequentialGroup()                                   .swing.GroupLayout.createSequentialGroup()                           . javax.          jPanel1Layout.addPreferredGap(javax.addComponent(jPanel2.Alignment.GroupLayout. 100.PREFERRED_SIZE.PREFERRED_SIZE.GroupLayout.addGroup(jPanel1Layout.swing.ComponentPlacement.addGroup(jPanel1Layout.addComponent(b32.com/Articles/778260/AI­based­Tic­Tac­Toe 13/25 .addPreferredGap(javax. javax.swing. javax.swing.addComponent(b12.RELATED)                                   .GroupLayout. 100. javax.setVerticalGroup(              jPanel1Layout.addContainerGap())          ). javax.PREFERRED_SIZE)                              .LEADING)                                      .swing.PREFERRED_SIZE)                              .GroupLayout.addComponent(b12. javax.addComponent(b21.swing.swing.swing.PREFERRED_SIZE)                                      .GroupLayout.GroupLayout.addGroup(jPanel1Layout.MAX_VALUE)))                  . javax.GroupLayout.GroupLayout.addComponent(b23.PREFERRED_SIZE.swing.addComponent(b21.  javax.GroupLayout.PREFERRED_SIZE.addPreferredGap(javax. 100.swing.  100.addComponent(b31.addPreferredGap(javax.addGroup(jPanel1Layout.LayoutStyle.swing.addGroup(jPanel1Layout.swing.addComponent(b22.addComponent(b11.LEADING)              . 100. javax.ComponentPlacement.GroupLayout.  javax.RELATED)                           .GroupLayout.swing. javax.RELATED)                          .GroupLayout. Short.LEADING.PREFERRED_SIZE)))                          .swing.createParallelGroup(javax.GroupLayout.  javax.GroupLayout.GroupLayout.createSequentialGroup()                                          . javax.  100.DEFAULT_SIZE.GroupLayout.ComponentPlacement.createSequentialGroup()                                  .GroupLayout.createParallelGroup(javax.PREFERRED_SIZE))                          .codeproject.addGroup(jPanel1Layout. BASELINE)                              . 40.swing. 100.awt.6/3/2016 AI based Tic Tac Toe (java code) ­ CodeProject javax.swing.  javax. javax.ActionEvent evt) {//GEN‐ FIRST:event_b32ActionPerformed          if(state[2][1]==0)          butClicked = 8.LayoutStyle.addContainerGap())          ).createParallelGroup(javax.GroupLayout.swing.GroupLayout.createParallelGroup(javax.  javax.      }//GEN‐LAST:event_b33ActionPerformed      private void b32ActionPerformed(java.createSequentialGroup()                  .swing.GroupLayout.swing.GroupLayout.swing.GroupLayout.GroupLayout. 100.  javax.swing.ComponentPlacement.addGroup(layout.addComponent(jPanel1.ActionEvent evt) {//GEN‐ FIRST:event_b13ActionPerformed          if(state[0][2]==0)          butClicked = 3.PREFERRED_SIZE)))                      .awt.  javax.MAX_VALUE))                  .setLayout(layout).DEFAULT_SIZE.MAX_VALUE)                  . Short.GroupLayout.addComponent(jPanel2.PREFERRED_SIZE. javax.addGroup(jPanel1Layout.event.DEFAULT_SIZE.swing. Short.setHorizontalGroup(              layout.          getContentPane().awt.MAX_VALUE))          ).swing.swing.      }//GEN‐LAST:event_b31ActionPerformed      private void b23ActionPerformed(java.addComponent(Notification.PREFERRED_SIZE.GroupLayout.event.ActionEvent evt) {//GEN‐ FIRST:event_b23ActionPerformed          if(state[1][2]==0)          butClicked = 6.GroupLayout.GroupLayout. 100.swing.setVerticalGroup(              layout.addComponent(b31. javax.Alignment.addPreferredGap(javax.GroupLayout.swing.awt.      }// </editor‐fold>//GEN‐END:initComponents      private void b33ActionPerformed(java.GroupLayout.swing. javax.createParallelGroup(javax.addGap(0.          layout.swing.codeproject.PREFERRED_SIZE)                              .GroupLayout.event.ActionEvent evt) {//GEN‐ FIRST:event_b33ActionPerformed          if(state[2][2]==0)          butClicked = 9.awt. 385.PREFERRED_SIZE)                  .          layout.GroupLayout.GroupLayout.PREFERRED_SIZE. javax.swing.com/Articles/778260/AI­based­Tic­Tac­Toe 14/25 .event.  javax.ActionEvent evt) {//GEN‐ FIRST:event_b31ActionPerformed          if(state[2][0]==0)          butClicked = 7.      }//GEN‐LAST:event_b32ActionPerformed      private void b31ActionPerformed(java.addPreferredGap(javax.Alignment.swing.addComponent(b32.GroupLayout(getContentPane()). javax.LEADING)              .GroupLayout layout = new javax.Alignment.DEFAULT_SIZE.addComponent(b33.          javax.PREFERRED_SIZE)                              .swing.RELATED)                           .swing.LEADING)              . 561.swing. javax. 0.PREFERRED_SIZE.      }//GEN‐LAST:event_b13ActionPerformed  http://www.swing. Short.MAX_VALUE)          ).ComponentPlacement.GroupLayout.PREFERRED_SIZE))                          .event.LayoutStyle.DEFAULT_SIZE.addComponent(jPanel1.UNRELATED)                  .      }//GEN‐LAST:event_b23ActionPerformed      private void b13ActionPerformed(java.          pack().  Short. util. ex).log(java.class.logging.log(java.swing.UIManager.Logger.class.          } catch (IllegalAccessException ex) {               java.awt.      }//GEN‐LAST:event_b22ActionPerformed      private void b11ActionPerformed(java.      }//GEN‐LAST:event_b12ActionPerformed      private void b22ActionPerformed(java.SEVERE. ex).6/3/2016 AI based Tic Tac Toe (java code) ­ CodeProject     private void b12ActionPerformed(java.LookAndFeelInfo info :  javax.SEVERE.ActionEvent evt) {//GEN‐ FIRST:event_b21ActionPerformed          if(state[1][0]==0)          butClicked = 4.SEVERE.awt.class.getInstalledLookAndFeels()) {                  if ("Nimbus".  null.util.util.                      break.UIManager.      }//GEN‐LAST:event_b21ActionPerformed      public static void main(String args[]) {          /* Set the Nimbus look and feel */          //<editor‐fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">          /* If Nimbus (introduced in Java SE 6) is not available.Level.codeproject.          } catch (InstantiationException ex) {               java.getName())) {                      javax.logging.class.swing.                      t.ActionEvent evt) {//GEN‐ FIRST:event_b11ActionPerformed          if(state[0][0]==0)          butClicked = 1.util.getLogger(TicTacToe.UnsupportedLookAndFeelException ex) {               java.                      while(true)                      {                          t. ex).event.      }//GEN‐LAST:event_b11ActionPerformed      private void b21ActionPerformed(java.log(java.  null.log(java.          }          //</editor‐fold>                      TicTacToe t = new TicTacToe().util.getName()).Level.Level.           * For details see http://download.com/Articles/778260/AI­based­Tic­Tac­Toe 15/25 .getLogger(TicTacToe.ActionEvent evt) {//GEN‐ FIRST:event_b12ActionPerformed          if(state[0][1]==0)          butClicked = 2.Logger.com/javase/tutorial/uiswing/lookandfeel/plaf.Logger.getName()).getLogger(TicTacToe.logging.event. ex).                          t.util.logging.Level.ActionEvent evt) {//GEN‐ FIRST:event_b22ActionPerformed          if(state[1][1]==0)          butClicked = 5.                  }              }          } catch (ClassNotFoundException ex) {               java.getLogger(TicTacToe.logging.swing.awt.event.swing.setVisible(true).logging.                      }      }  http://www.SEVERE.logging.getName()).util.getClassName()).gameInit().Logger.  null.equals(info.setLookAndFeel(info.start().html            */          try {              for (javax. stay with the default look and  feel.event.awt.  null.UIManager.getName()).logging.util.          } catch (javax.oracle.           }          TicTacToe.break.JButton b32.      // End of variables declaration//GEN‐END:variables        }  Player.swing.              case 7 : TicTacToe.JButton b23.swing.JLabel Notification.JLabel jLabel1.break.      public static javax.swing.      public static javax.6/3/2016 AI based Tic Tac Toe (java code) ­ CodeProject           // Variables declaration ‐ do not modify//GEN‐BEGIN:variables      private javax.break.state[2][2]=pl.  http://www.      private javax.JButton b13.swing.state[0][0]=pl.      }  }  Computer.java Hide   Shrink   Copy Code import java.JLabel jLabel5.int turn){          while(TicTacToe.JButton b33.      public static javax.butClicked = 0.swing.state[0][2]=pl.      public static javax.state[1][0]=pl.break.break.swing.JPanel jPanel1.ArrayList.      private javax.              case 3 : TicTacToe.java Hide   Copy Code public class Human extends Player {      @Override      void playTurn(int pl.state[0][1]=pl.state[1][2]=pl.swing.codeproject.          switch(TicTacToe.swing.JLabel jLabel4.swing.*.swing.swing.JButton b22.      private javax.JLabel jLabel2.  import java.com/Articles/778260/AI­based­Tic­Tac­Toe 16/25 .swing.      public static javax.              case 5 : TicTacToe.int turn){}      void playerInit(){}      void notifyWin(int pl){}      void notifyLose(int pl){}  }  Human.util.              case 2 : TicTacToe.      private javax.butClicked == 0).state[1][1]=pl.JPanel jPanel2.              case 4 : TicTacToe.      private javax.swing.break.break.butClicked)          {              case 1 : TicTacToe.JLabel jLabel3.swing.break.break.state[2][1]=pl.io.      private javax.              case 8 : TicTacToe.swing.state[2][0]=pl.swing.swing.      public static javax.              case 9 : TicTacToe.JLabel jLabel6.      public static javax.      private javax.      public static javax.JButton b11.swing.JButton b12.              case 6 : TicTacToe.JButton b31.JButton b21.      public static javax.java Hide   Copy Code public abstract class Player {      void playTurn(int pl.      private javax. pref=‐50.saveMind().out.nodes.                      if(ch=='1')                      {                          x+=(k+1).                      }                      else if(ch=='2')                      {                          o+=(k+1).com/Articles/778260/AI­based­Tic­Tac­Toe 17/25 .i++)          {              Layer l = layers.k<9.get(j).createNewFile().0000 00001.                  switch(r)                  {                      case 1 : l.get(j).                          break.010000000.      Node begin = new Node("000000000".                  for(int k=0.j<l.nodes.nodes.i++)          {              layerFiles[i] = new File(l+(i+1)+".              if(!layerFiles[i].println(e).this).                      case ‐1 :                           l. s = l.0.nodes").      ArrayList<Layer> layers = new ArrayList<Layer>().extractNodes().k++)                  {                      char ch = s.                  }              }          }          //loadMind().                          l.i<9.                  }              }  http://www.000100000.000010000. o="" .i<9.                double lr = 0.nodes.                          break.nodeType=1.                      }                  }                  int r = TicTacToe.get(j).nodes.                          break.j++)              {                  String x="" .          makeNewMind().      public Computer(String l){          for(int i=0.      }      public void evaluate(){          for(int i=0.000000100.get(j).                  }                  catch(Exception e)                  {                      System.      Node current = begin.size().checkWin2(x.".charAt(k).001000000.codeproject.evaluate().      File[] layerFiles = new File[9].pref=50.000000010.get(j).                          l.exists())              {                  try{                      layerFiles[i].nodeType=1.                      case 2 : l.o).get(i).subNodes="100000000.nodeType=1.          begin.              for(int j=0.6/3/2016 AI based Tic Tac Toe (java code) ­ CodeProject public class Computer extends Player {      int t=0.000001000.           begin.nodes.nodes.id.get(j). get(l).out.                      layers.                      temp.get(j).j++)                  {                      layers.                      p.out).                      }                      p.pref = Integer.println(temp.l++)              {                  layers.println(no).                  PrintWriter p = new PrintWriter(new BufferedWriter(new FileWriter(layerFiles[i]))).                      temp.                  for(int j=0.readLine().                      String no = r.readLine()).nodes.l<9.sub_nodes.                  f = new FileReader(layerFiles[l]).                      temp.                  while((line=r.i‐‐)          {              layers.j<layers.                      p.get(i).l++)              {                  for(int j=0.readLine().l<9.          }      }      public void saveMind(){          for(int i=7.i<9.get(i).parseInt(no).nodeType = Integer.n = Integer.                      p.size().          BufferedReader r.nodes.subNodes = r.k++)                      {                          s+=temp.get(k).codeproject.add(new Layer(l+1)).readLine())!=null)                  {                      Node temp = new Node(r.println(temp.i++)              {                  Layer l = layers.                  String line.                      p.parseInt(r.j<l.".nodes.extractNodes().          }          try{              for(int i=0.get(j).get(l).refreshLayer().id).get(l).pref).                  }              }                        }          catch(Exception e){              e.println(temp.out.nodes.                       for(int k=0.nodeType).nodes.println(s).k<temp.size().printStackTrace(System.println(temp.size().          int i=0.j++)                  {                      Node temp = l.parseInt(r.add(temp).println("***********************************************").id+".                      String s="".                  }              }                            for(int l=0.                      p.                      //System.sub_nodes.l+1.n).6/3/2016 AI based Tic Tac Toe (java code) ­ CodeProject         }      }      public void loadMind(){          FileReader f.this).com/Articles/778260/AI­based­Tic­Tac­Toe 18/25 .                  }  http://www.i>=0.id).readLine().                      temp.          try{              for(int l=0.println(temp.readLine()).                      //System.                  r = new BufferedReader(f). this)).layers.i5<=2.close().j++)              {                  Node node = layers.              if(i6==0)l‐‐.get(l).get(j).i3<=2.out.get(l‐1).i7++){          for(int i8=0.add(new Node(id.i6++){          for(int i7=0.              if(i9==1)x++.l++)          {              for(int j=0.add(new Layer(2)).                  layers.                  for(int i=0.i9++){              int l=9.l.out).              }          }}}}}}}}}           for(int l=1.              if(i7==0)l‐‐.layers.i++)                  {                      String newId="".                            int x=0.i3++){          for(int i4=0.              if(i4==0)l‐‐.codeproject.charAt(k).              if(i6==1)x++.              if(i2==1)x++.k<9.i2<=2.add(new Layer(3)).                            int o = l‐x.                            if((x‐o==0 || x‐o==1) && l!=0 )              {                  String id = ""+i1+i2+i3+i4+i5+i6+i7+i8+i9.              if(i3==1)x++.add(new Layer(7)).              if(i3==0)l‐‐.layers.printStackTrace(System.layers.i7<=2.              if(i5==0)l‐‐.k++)                      {                          char ch = node.i<9.              if(i4==1)x++.                  //System.              if(i9==0)l‐‐.i5++){          for(int i6=0.layers.              }          }          catch(Exception e)          {              e.j<layers.              if(i8==0)l‐‐.                    for(int i1=0.i8<=2.com/Articles/778260/AI­based­Tic­Tac­Toe 19/25 .size()).                      for(int k=0.nodes.get(l).layers.              if(i7==1)x++.i2++){          for(int i3=0.add(new  Layer(8)).nodes.id.i4<=2.size().layers.              if(i8==1)x++.add(new Layer(1)).i4++){          for(int i5=0.              if(i5==1)x++.              if(i2==0)l‐‐.i1<=2.add(new  Layer(4)).  http://www.i1++){          for(int i2=0.nodes.add(new Layer(6)).println("layer "+i+" : "+l.i9<=2.                          if(k==i)ch='0'.i6<=2.nodes.              if(i1==1)x++.add(new Layer(9)).layers.l<9.          }      }      public void makeNewMind(){          layers.i8++){          for(int i9=0.              if(i1==0)l‐‐.add(new Layer(5)).6/3/2016 AI based Tic Tac Toe (java code) ­ CodeProject                 p.       int n=0.pref‐=10.nodeType=1.out.out.pref).pref‐=10.  public class Node {      ArrayList<Node> sub_nodes = new ArrayList<Node>().extractNodes().lNum‐ 1).                             //System.java Hide   Shrink   Copy Code import java.equals(node.      }            @Override      public void playTurn(int p.add(node).get(l‐1).  http://www.sub_nodes.com/Articles/778260/AI­based­Tic­Tac­Toe 20/25 .searchByState(TicTacToe.      }  } Node.searchById(current.codeproject.util.id).          if(p==2)current.ArrayList.6/3/2016 AI based Tic Tac Toe (java code) ­ CodeProject                         newId+=ch.          if(turn != 1)          {              current = layers.pref).id))                      {                          try{                                                            layers.pref+=10.nodeType=1.          saveMind().                          }                          catch(NullPointerException e){}                      }                  }                                }          }          begin.get(turn‐2).out.      int pref = 0.pref+" : "+layers.id+" : "+newId+" : "+l).pref+=10.pref+" : "+layers.          if(pl==2)current.id+":"+current.          //System.          }          if(turn == 1)          {              current = begin.      String subNodes="".          }          if(p==1)current.println(node.                      }                      if(!newId.          if(pl==2)current.state).searchById(current.      }      @Override      void notifyLose(int pl){          if(pl==1)current.playNext2().get(current.      }            @Override      void notifyWin(int pl){          if(pl==1)current.get(current.int turn){          t = turn.      String id="".          current.          //System.playNextn().id+":"+current.          current.          saveMind().lNum‐ 1).id).println("*******"+current.println("*******"+current.searchById(newId). clear().                      temp.          temp.add(sub_nodes.clear().              for(int i=0.pref == max)                  {                      temp.int l.add(sub_nodes.          temp.add(sub_nodes.get(choice).                      max = sub_nodes.get(i).size().pref.add(sub_nodes.get(i)).get(i).get(choice).      int nodeType=0.length().          lNum = l.get(choice).get(0).state[t][i‐(t*3)] = val.pref.          long max = sub_nodes.get(i).                  }                  else if(sub_nodes.      public Node(String i.          //System.      }            public void setAsState(){          for(int i=0.pref > max)                  {                      temp.get(i)).size()).i<id.          temp.              for(int i=0.i<sub_nodes.get(i).random()*temp.com/Articles/778260/AI­based­Tic­Tac­Toe 21/25 .                  }              }                    int choice = (int) (Math.out.          temp.                        }      }            public void playNext1(){          ArrayList<Node> temp = new ArrayList<Node>().      }            public void playNext2(){          ArrayList<Node> temp = new ArrayList<Node>().Computer c){          id=i.i++)          {              int val = (int)(id.println(id+" : "+sub_nodes.                  }              }                    int choice = (int) (Math.i<sub_nodes.                      temp.setAsState().          comp = c.                      min = sub_nodes.get(0).              TicTacToe.n++.charAt(i)‐'0').out.get(i).6/3/2016 AI based Tic Tac Toe (java code) ­ CodeProject     int lNum.random()*temp.size()).setAsState().              int t = i/3.      Computer comp.      }        http://www.get(i).get(choice).size()).codeproject.size().n++.          //System.          long min = sub_nodes.                  }                  else if(sub_nodes.pref.i++)              {                  if(sub_nodes.get(i)).pref.pref == min)                  {                      temp.println(id+" : "+sub_nodes.size()).pref < min)                  {                      temp.get(i)).i++)              {                  if(sub_nodes. get(i).com/Articles/778260/AI­based­Tic­Tac­Toe 22/25 .              temp.i++)              {                  if(sub_nodes.println(id+" : "+sub_nodes.get(choice).      }            public void extractNodes(){          if(lNum!=9)          {              int l = subNodes.6/3/2016 AI based Tic Tac Toe (java code) ­ CodeProject     public void playNextn(){          ArrayList<Node> temp = new ArrayList<Node>().                                        }                  else                  {                      sub_nodes.layers.n.pref)/2.add(comp.              for(int j=0.                      w="".      public Layer(int Num){          layerNum = Num.ArrayList.i<sub_nodes.get(lNum).sub_nodes.i++)              {                  char ch = subNodes.pref=0.              if(temp.get(i).              }  http://www.size().j<temp.get(0).n++.out.sub_nodes.i<nodes.          //System.              String w="".nodeType!=0)continue.n.searchById(w)).          int choice = 0.              for(int i=0.get(choice).              for(int i=0.size()).pref += (int)(temp.size().      }            public void refreshLayer(){          for(int i=0.get(i).  public class Layer {      ArrayList<Node> nodes = new ArrayList<Node>().setAsState().util.i<l.n < min)                  {                      min = sub_nodes.          sub_nodes.                      choice = i.j++)              {                  temp.          long min = sub_nodes.codeproject.                  }              }                    sub_nodes.      int layerNum = 0.')                  {                      w+=ch.charAt(i).get(j).length().                  }              }          }                }  }  Layer.java Hide   Shrink   Copy Code import java.i++)          {              Node temp = nodes.size().                  if(ch!='. codeproject.              }          }                        return ret.out. I am 16 years old indian with many ideas in my mind and hope that you will help me make them come real.!=0?temp:"").      }  } Conclusion I hope you enjoyed reading my post and would be further interested in this topic.get(i). along with any associated source code and files.print(temp.out.pref!=0?temp.          //System.id.out.                  break.an Intermediate student from India .println("*********"+nodes.com/Articles/778260/AI­based­Tic­Tac­Toe 23/25 .i++)          {              //System.          return ret.6/3/2016 AI based Tic Tac Toe (java code) ­ CodeProject             //System.i<nodes.equals(id))              {                  ret = nodes. I would be really happy to see this in other programs .                    for(int i=0.get(i). Thank You very much for reading my work.pref+"\n":"").print(temp.size().get(i).          Node ret = searchById(temp). is licensed under The Code Project Open License ﴾CPOL﴿ Share EMAIL TWITTER About the Author http://www. This Method can be used to develop other machine learning programs.          }      }            public Node searchByState(int[][] state){                    String temp = ""+state[0][0]+state[0][1]+state[0][2]+state[1][0]+state[1][1]+state[1] [2]+state[2][0]+state[2][1]+state[2][2]. Credits This project was developed by Mohd Akram .id).      }            public Node searchById(String id){          Node ret = null.              if(nodes. License This article. .6/3/2016 AI based Tic Tac Toe (java code) ­ CodeProject Mohd AkramNo Biography provided United States You may also be interested in. mainadmn 20‐Dec‐15 14:32 Quetion http://www..com/Articles/778260/AI­based­Tic­Tac­Toe mehul110 9‐Sep‐15 23:20 24/25 . Yet Another Tic Tac Toe Static Code Analysis in an Agile World Laser Guided Tic Tac Toe Game using Webcam For Vision Getting Started with React Tic Tac Toe in C# Looking Back: One Year of Microsoft Edge Comments and Discussions   You must Sign In to use this message board. Search Comments   Go First Prev Next Computer vs.codeproject... Computer Atalay Asa 28‐Dec‐15 2:24 Inspiring. 160531.codeproject. Ctrl+Shift+Left/Right to switch pages.6/3/2016 AI based Tic Tac Toe (java code) ­ CodeProject mehul110 9‐Sep‐15 23:20 Error gjumboman 22‐May‐15 13:09 Run time error Member 11274100 29‐Nov‐14 17:38 Re: Run time error Member 8323880 7‐Dec‐14 13:59 Solution: Run time error Mohd Akram 21‐Mar‐15 5:40 Vote of 5 Vijay G.1 | Last Updated 27 May 2014 http://www. Permalink | Advertise | Privacy | Terms of Use | Mobile Web01 | 2. 1999‐2016 25/25 . Ctrl+Up/Down to switch threads.8. Yadav Re: Vote of 5 Mohd Akram 10‐Jun‐14 0:15 21‐Mar‐15 5:41 Good for newbie TrumDongNat 30‐May‐14 17:23 Refresh General    News    1 Suggestion    Question    Bug    Answer    Joke    Praise    Rant    Admin    Use Ctrl+Left/Right to switch messages.com/Articles/778260/AI­based­Tic­Tac­Toe Select Language ▼ Layout: fixed | fluid Article Copyright 2014 by Mohd Akram Everything else Copyright © CodeProject.
Copyright © 2024 DOKUMEN.SITE Inc.