Our Feeds

Saturday 16 August 2014

Ajith KP

Fist GUI Program - FASM

          I hope you have read the previous posts about FASM. Else please read it here: http://terminalcoders.blogspot.in/search/label/FASM.

          I hope most of you are familiar with Visual C++. Otherwise it will be hard to study FASM/MASM. Because you should know the syntax of Visual C++ and how you can convert it to FASM.

          I hope the first GUI program you studied is how to show the MessageBox. Isn't? Now I will explain the important parts of code.



The syntax of MessageBox() in Visual C++ is,

MessageBox(WindowHandle, YourMessage, CaptionOfMessageBox, IconsAndButtons);

           Now we can convert it to FASM,
           The function MessageBox() is declared in user32.dll in Windows OS. When the API function MessageBox() calls, the OS will pass its control to kernel modules where the function is actually declared. So we need to import user32.dll. The last import is ExitProcess() function. This function is declared in kernel32.dll. So kernel32.dll is must be included. The syntax of import part is,

data import
     library kernel32, 'kernel32.dll', user32, 'user32.dll'
     import kernel32, ExitProcess, 'ExitProcess'
     import user32, MessageBox, 'MessageBoxA'
end data

           In line ` library import kernel, 'kernel.dll', user32, 'user32.dll' ` the `kernel32` and `user32` are aliasing of long `kernel32.dll` and `user32.dll`. Like wise we have aliased ExitProcess and MessageBoxA.

           The function `invoke` is used to invoke the system calls.

invoke MessageBox, 0, msg, cap, MB_ICONINFORMATION+MB_YESNO

           The full source code is,

format PE GUI 4.0
;
;
; AJITH KP > HTTP://WWW.TERMINALCODERS.BLOGSPOT.DE
;
;
; IMPORTED FROM MY ANOTHER BLOG DSPROGRAMMING.CO.VU
;
include 'win32a.inc'
invoke MessageBox, 0, msg, cap, MB_ICONINFORMATION+MB_YESNO
msg db 'Do you like this blog http://www.dsprogramming.co.vu ???', 0
cap db 'D S', 0
exit:
        invoke ExitProcess
data import
     library kernel32, 'kernel32.dll', user32, 'user32.dll'
     import kernel32, ExitProcess, 'ExitProcess'
     import user32, MessageBox, 'MessageBoxA'
end data

           Now check the size of programs in both FASM and Visual C++ of same program.
In FASM
In Visual C++

           The size of program in FASM is only 1 KB, but the program in Visual C++ is about 27 KB. So the program in ASM will execute more rapidly than programs in C++ or any other programming languages. So that ASM is used to create device drivers, game modules, even computer viruses!!!.
           Hope you like this post. Please share with you friends who is interested in it.

Thursday 14 August 2014

Ajith KP

Reverse IP Look up Tool in PHP

          Reverse IP look up tool is very important for the hackers who need to hack servers and he can find vulnerable website from a list of websites using this tool. The important website which provides reverse IP look is http://www.yougetsignal.com. Here I have developed a tool in PHP to find reverse IPs using the service of YouGetSignal.



The source code is,


Ajith KP

Free Domain For Your Blogs

          If you are seeking a free domain service for your blogs here is an absolute free and easy solution. Just register your account and use domains for free. Also you can sign up using Facebook account also.

          Register Domain Here: http://codotvu.com/i/fawd


          After register domain, the website will load another page to sign up. Sign up there or if you have already registered an account you can sign in.

          After sign in, select Blogger or Tumblr or Weebly and follow the steps showed there.

       
          You can register 3 domains for free. Hope you will share this with your friends.
         
          I have registered a domain for my another blog: http://www.dsprogramming.co.vu. Please visit it.
Ajith KP

Hello World in FASM

          `Hello World` is the first program to implement in every programming languages. Here it is going to implement first application in FASM.


format PE console
include 'win32a.inc'
;
;
; AJITH KP > HTTP://WWW.TERMINALCODERS.BLOGSPOT.DE
;
;
invoke printf, hello
invoke getch
invoke ExitProcess, 0
hello db 'Hello World!!!', 0
data import
     library kernel32, 'kernel32.dll', msvcrt, 'msvcrt.dll'
     import kernel32, ExitProcess, 'ExitProcess'
     import msvcrt, printf, 'printf', getch, '_getch'
end data
Ajith KP

FASM Begins

          FASM is an extend of MASM. Like MASM you can use FASM. I like FASM more than MASM because it provides an environment for developing which is easier than MASM. The FASM stands for Flat Assembler.
          Download Linkhttp://flatassembler.net/download.php
     

          You can use FASM for developing applications which will execute faster than that of created by other languages like C++, C#, etc. Because assembly languages is very small in size and uses bare system calls.
So that the game developers still using assembly codes to develop the modules which should load more fast.

          I hope you understand the importance of assembly language and why it is still alive. :)

Sunday 10 August 2014

Ajith KP

How to Auto-Mount Drives in Fedora

          Fedora needs `super user` password to mount the other drives in system. It is not good to ask password to mount drives after every boot for normal users. The following commands are used to auto-mount the drives.



          First of all you need to become `super user`.
$ su

          After become `super user` execute the following commands.
# gpasswd -a loginname wheel
# usermod -a -G wheel loginname

          Login name indicates the `user name` used to login. My user name is `terminal`.

      
       Okey, now you can use your own user password. :)

Saturday 9 August 2014

Ajith KP

Linked Lists

          Linked Lists are implemented to overcome drawbacks of sequential data structures. Sequential data structures uses storage memory in an inefficient way. Also have inefficient implementation of insertion and deletion operations.


          Linked lists have a chained structure and each component in linked list is called nodes. Each nodes of linked list connected like a train bogies. Each node have 2 sections. The first section is data section and other section is link section. The data section contains the data stored in node and link section contains address of next node. According to the number of nodes the linked lists have divided into 3. The first one is singly linked list which contains one link which has address of next node. The second is doubly linked list which contains two links which has address of previous and next nodes. The third is multiply linked list which have more than two links which points to nodes in linked lists. The another type of linked list is circularly linked list which have a circular structure. In this type of linked list the last node's link points to the first node.

          Linked lists have many applications. The most important application is representation of sparse matrix in memory and polynomial addition.
          Addition of Polynomial: http://terminalcoders.blogspot.com/2014/08/addition-of-polynomial-linked-list.html
Ajith KP

Tic Tac Toe - AI fully functional

          Read Basic Version: http://terminalcoders.blogspot.in/2014/08/tic-tac-toe-find-empty-cell-to-play.html

          I hope you have read the basic version. Now I would like to share the code of little bit advanced version of Tic Tac Toe with more characterized CPU player. In this code the CPU player can find the step to win and CPU player can predict the movement of opponent.



          Characteristics of CPU player

  1. Play at center if center cell is empty.
  2. If center cell is empty play at corners because corners are suitable place to play rationally.
  3. If the CPU player can find out is it can win in next step.
  4. If the CPU player can't win in next step and the opponent can win in next step, the CPU player will play there to close the opportunity to win.
  5. If all conditions fail play at first empty cell.
              It is possible to reduce the code by using mathematical functions. But the steps of code will be tough to grab from source code.

    /*
     * 
     * 
     * Coded By AJITH KP
     * Artificial Intelligent Tic Tac Toe CPU Player
     * 
     * 
     */
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Font;
    import java.awt.GridLayout;
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    import java.util.Random;
    import javax.swing.BorderFactory;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    
    
    public class TicTacToe extends JFrame {
        JPanel l = new JPanel(new GridLayout(1, 1, 0, 0));
        JPanel b = new JPanel(new GridLayout(3, 3, 5, 5));
        JLabel lbl = new JLabel("Coded By Ajith Kp");
        JTextField flds[] = new JTextField[9];
        boolean pl = false;
        TextHandle hld = new TextHandle();
        TicTacToe()
        {
            super("TicTacToe --- AJITH KP");
            setLayout(new BorderLayout());
            Random r = new Random();
            int n = r.nextInt(10);
            if(n%2==0)
            {
                pl = true;
            }
            else
            {
                pl = false;
            }
            for(int i=0;i<9;i++)
            {
                flds[i] = new JTextField();
                flds[i].addMouseListener(hld);
                flds[i].setForeground(Color.BLACK);
                flds[i].setHorizontalAlignment(JLabel.CENTER);
                flds[i].setBorder(BorderFactory.createMatteBorder(0, 0, 0, 0, Color.red));
                flds[i].setBackground(Color.CYAN);
                flds[i].setFont(new Font("Times New Roma", Font.BOLD, 25));
                flds[i].setEditable(false);
                b.add(flds[i]);
            }
            lbl.setForeground(Color.BLUE);
            lbl.setFont(new Font("Times New Roman", Font.BOLD, 25));
            lbl.setBorder(BorderFactory.createMatteBorder(3, 3, 3, 3, Color.green));
            lbl.setHorizontalAlignment(JLabel.CENTER);
            l.add(lbl);
            add(l, BorderLayout.NORTH);
            add(b, BorderLayout.CENTER);
            if(pl==true)
            {
                comp();
            }
        }
        public class TextHandle extends MouseAdapter 
        {
            @Override
            public void mouseClicked(MouseEvent e) {    
                if(pl==false)
                {
                    JTextField fld = (JTextField) e.getSource();
                    if(fld.getText().equals(""))
                    {
                        fld.setForeground(Color.red);
                        fld.setBorder(BorderFactory.createMatteBorder(3, 3, 3, 3, Color.red));
                        fld.setText("X");
                        char c = finish();
                        if(c=='U')
                        {
                            lbl.setText("You have won");
                            disable();
                            return;
                        }
                        else if(c=='O')
                        {
                            lbl.setText("Game Over. No one won");
                            disable();
                            return;
                        }
                        pl = true;
                        comp();
                    }
                }
                return;
            }
        }
        public void disable()
        {
            for(int i=0;i<9;i++)flds[i].addMouseListener(null);
        }
        public void comp()
        {
            if(pl==true)
            {
                int n = bestClic();
                flds[n].setForeground(Color.blue);
                flds[n].setBorder(BorderFactory.createMatteBorder(3, 3, 3, 3, Color.BLUE));
                flds[n].setText("O");
                char c = finish();
                if(c=='C')
                {
                    lbl.setText("Computer has won");
                    disable();
                    return;
                }
                else if(c=='O')
                {
                    lbl.setText("Game Over. No one won");
                    disable();
                    return;
                }
                pl = false;
            }
            return;
        }
        public int bestClic()
        {
            int num = 0;
            if(flds[4].getText().equals(""))
            {
                num = 4;
            }
            else
            {
                num = free();
            }
            return num;
        }
        public int free()
        {
            int n = 0;
            int c1, c2, c3, r1, r2, r3, x1, x2;
            c1 = c2 = c3 = r1 = r2 = r3 = x1 = x2 = 0;
            for(int i=0;i<9;i++)
            {
                if(i%3==0)
                {
                    if(flds[i].getText().equals("O"))
                    {
                        c1++;
                    }
                }
                if(i%3==1)
                {
                    if(flds[i].getText().equals("O"))
                    {
                        c2++;
                    }
                }
                if(i%3==2)
                {
                    if(flds[i].getText().equals("O"))
                    {
                        c3++;
                    }
                }
                if(i<3)
                {
                    if(flds[i].getText().equals("O"))
                    {
                        r1++;
                    }
                }
                else if(i<6)
                {
                    if(flds[i].getText().equals("O"))
                    {
                        r2++;
                    }
                }
                else if(i<9)
                {
                    if(flds[i].getText().equals("O"))
                    {
                        r3++;
                    }
                }
                if(i==0||i==4||i==8)
                {
                    if(flds[i].getText().equals("O"))
                    {
                        x1++;
                    }
                }
                if(i==2||i==4||i==6)
                {
                    if(flds[i].getText().equals("O"))
                    {
                        x2++;
                    }
                }
            }
            if(c1==2 && freeCell("c1")>0)
            {
                return freeCell("c1");
            }
            else if(c2==2 && freeCell("c2")>0)
            {
                return freeCell("c2");
            }
            else if(c3==2 && freeCell("c3")>0)
            {
                return freeCell("c3");
            }
            else if(r1==2 && freeCell("r1")>0)
            {
                return freeCell("r1");
            }
            else if(r2==2 && freeCell("r2")>0)
            {
                return freeCell("r2");
            }
            else if(r3==2 && freeCell("r3")>0)
            {
                return freeCell("r3");
            }
            else if(x1==2 && freeCell("x1")>0)
            {
                return freeCell("x1");
            }
            else if(x2==2 && freeCell("x2")>0)
            {
                return freeCell("x2");
            }
            else
            {              
                c1 = c2 = c3 = r1 = r2 = r3 = x1 = x2 = 0;
                for(int i=0;i<9;i++)
                {
                    if(i%3==0)
                    {
                        if(flds[i].getText().equals("X"))
                        {
                            c1++;
                        }
                    }
                    if(i%3==1)
                    {
                        if(flds[i].getText().equals("X"))
                        {
                            c2++;
                        }
                    }
                    if(i%3==2)
                    {
                        if(flds[i].getText().equals("X"))
                        {
                            c3++;
                        }
                    }
                    if(i<3)
                    {
                        if(flds[i].getText().equals("X"))
                        {
                            r1++;
                        }
                    }
                    else if(i<6)
                    {
                        if(flds[i].getText().equals("X"))
                        {
                            r2++;
                        }
                    }
                    else if(i<9)
                    {
                        if(flds[i].getText().equals("X"))
                        {
                            r3++;
                        }
                    }
                    if(i==0||i==4||i==8)
                    {
                        if(flds[i].getText().equals("X"))
                        {
                            x1++;
                        }
                    }
                    if(i==2||i==4||i==6)
                    {
                        if(flds[i].getText().equals("X"))
                        {
                            x2++;
                        }
                    }
                }
                if(c1==2  && freeCell("c1")>0)
                {
                    return freeCell("c1");
                }
                else if(c2==2 && freeCell("c2")>0)
                {
                    return freeCell("c2");
                }
                else if(c3==2 && freeCell("c3")>0)
                {
                    return freeCell("c3");
                }
                else if(r1==2 && freeCell("r1")>0)
                {
                    return freeCell("r1");
                }
                else if(r2==2 && freeCell("r2")>0)
                {
                    return freeCell("r2");
                }
                else if(r3==2 && freeCell("r3")>0)
                {
                    return freeCell("r3");
                }
                else if(x1==2 && freeCell("x1")>0)
                {
                    return freeCell("x1");
                }
                else if(x2==2 && freeCell("x2")>0)
                {
                    return freeCell("x2");
                }
                else
                {
                    return findBest();
                }
            }        
            //return n;
        }
        public int findBest()
        {
            int num = 0;
            if(flds[0].getText().equals(""))
            {
                return 0;
            }
            if(flds[2].getText().equals(""))
            {
                return 2;
            }
            if(flds[6].getText().equals(""))
            {
                return 6;
            }
            if((flds[8]).getText().equals(""))
            {
                return 8;
            }
            for(int i=0;i<9;i++)
            {
                if(flds[i].getText().equals(""))
                {
                    return i;
                }
            }
            return num;
        }
        public int freeCell(String s)
        {
            int num = 0;
            if(s.equals("c1"))
            {
                for(int i=0;i<9;i++)
                {
                    if(i%3==0)
                    {
                        if(flds[i].getText().equals(""))
                        {
                            return i;
                        }
                    }
                }
            }
            else if(s.equals("c2"))
            {
                for(int i=0;i<9;i++)
                {
                    if(i%3==1)
                    {
                        if(flds[i].getText().equals(""))
                        {
                            return i;
                        }
                    }
                }
            }
            else if(s.equals("c3"))
            {
                for(int i=0;i<9;i++)
                {
                    if(i%3==2)
                    {
                        if(flds[i].getText().equals(""))
                        {
                            return i;
                        }
                    }
                }
            }
            else if(s.equals("r1"))
            {
                for(int i=0;i<9;i++)
                {
                    if(i<3)
                    {
                        if(flds[i].getText().equals(""))
                        {
                            return i;
                        }
                    }
                }
            }
            else if(s.equals("r2"))
            {
                for(int i=0;i<9;i++)
                {
                    if(i<6 && i>2)
                    {
                        if(flds[i].getText().equals(""))
                        {
                            return i;
                        }
                    }
                }
            }
            else if(s.equals("r3"))
            {
                for(int i=0;i<9;i++)
                {
                    if(i<9 && i>5)
                    {
                        if(flds[i].getText().equals(""))
                        {
                            return i;
                        }
                    }
                }
            }
            else if(s.equals("x1"))
            {
                for(int i=0;i<9;i++)
                {
                    if(i==0||i==4||i==8)
                    {
                        if(flds[i].getText().equals(""))
                        {
                            return i;
                        }
                    }
                }
            }
            else if(s.equals("x2"))
            {
                for(int i=0;i<9;i++)
                {
                    if(i==2||i==4||i==6)
                    {
                        if(flds[i].getText().equals(""))
                        {
                            return i;
                        }
                    }
                }
            }
            return num;
        }
        public char finish()
        {
            //int num = 0;
            char win = 'N';
            int c1, c2, c3, r1, r2, r3, x1, x2;
            c1 = c2 = c3 = r1 = r2 = r3 = x1 = x2 = 0;
            for(int i=0;i<9;i++)
            {
                if(i%3==0)
                {
                    if(flds[i].getText().equals("X"))
                    {
                        c1++;
                    }
                }
                if(i%3==1)
                {
                    if(flds[i].getText().equals("X"))
                    {
                        c2++;
                    }
                }
                if(i%3==2)
                {
                    if(flds[i].getText().equals("X"))
                    {
                        c3++;
                    }
                }
                if(i<3)
                {
                    if(flds[i].getText().equals("X"))
                    {
                        r1++;
                    }
                }
                else if(i<6)
                {
                    if(flds[i].getText().equals("X"))
                    {
                        r2++;
                    }
                }
                else if(i<9)
                {
                    if(flds[i].getText().equals("X"))
                    {
                        r3++;
                    }
                }
                if(i==0 || i==4 || i==8)
                {
                    if(flds[i].getText().equals("X"))
                    {
                        x1++;
                    }
                }
                if(i==2 || i==4 || i==6)
                {
                    if(flds[i].getText().equals("X"))
                    {
                        x2++;
                    }
                }
            }
            if(c1 == 3|| c2 == 3|| c3 == 3 || r1 == 3 || r2 == 3 || r3 == 3 || x1 == 3 || x2 == 3)
            {
                return 'U';
            }
            c1 = c2 = c3 = r1 = r2 = r3 = x1 = x2 = 0;
            for(int i=0;i<9;i++)
            {
                if(i%3==0)
                {
                    if(flds[i].getText().equals("O"))
                    {
                        c1++;
                    }
                }
                if(i%3==1)
                {
                    if(flds[i].getText().equals("O"))
                    {
                        c2++;
                    }
                }
                if(i%3==2)
                {
                    if(flds[i].getText().equals("O"))
                    {
                        c3++;
                    }
                }
                if(i<3)
                {
                    if(flds[i].getText().equals("O"))
                    {
                        r1++;
                    }
                }
                else if(i<6)
                {
                    if(flds[i].getText().equals("O"))
                    {
                        r2++;
                    }
                }
                else if(i<9)
                {
                    if(flds[i].getText().equals("O"))
                    {
                        r3++;
                    }
                }
                if(i==0 || i==4 || i==8)
                {
                    if(flds[i].getText().equals("O"))
                    {
                        x1++;
                    }
                }
                if(i==2 || i==4 || i==6)
                {
                    if(flds[i].getText().equals("O"))
                    {
                        x2++;
                    }
                }
            }
            if(c1 == 3|| c2 == 3|| c3 == 3 || r1 == 3 || r2 == 3 || r3 == 3 || x1 == 3 || x2 == 3)
            {
                return 'C';
            }
            int cnt = 0;
            for(int i=0;i<9;i++)
            {
                if(flds[i].getText().equals(""))
                {
                    cnt++;
                }
            }
            if(cnt==0)
            {
                win = 'O';
            }
            return win;
        }
        public static void main(String[] args) {
            TicTacToe t = new TicTacToe();
            t.setVisible(true);
            t.setSize(350, 370);
            t.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        }
    }
    Ajith KP

    Tic Tac Toe - Find Empty Cell to Play

              Tic Tac Toe is very simple game. It need only very simple AI to develop. So I'm giving you very simple Java code which the CPU player can find the empty cell and play there. There is no other skills on CPU player.

              The only characteristics of CPU player is to find the empty cells and select a cell in random to play there.
              Read Advanced CPU Player: http://terminalcoders.blogspot.com/2014/08/tic-tac-toe-ai-fully-functional.html




    /*
     * 
     * 
     * ARTIFICIAL INTELLIGENT --- X --- CODED BY AJITH KP BASICS
     * 
     * 
     */
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Font;
    import java.awt.GridLayout;
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    import java.util.Random;
    import javax.swing.BorderFactory;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    
    
    public class TicTacToe extends JFrame {
        JPanel l = new JPanel(new GridLayout(1, 1, 0, 0));
        JPanel b = new JPanel(new GridLayout(3, 3, 5, 5));
        JLabel lbl = new JLabel("Coded By Ajith Kp");
        JTextField flds[] = new JTextField[9];
        boolean pl = false;
        TextHandle hld = new TextHandle();
        TicTacToe()
        {
            super("TicTacToe --- AJITH KP");
            setLayout(new BorderLayout());
            for(int i=0;i<9;i++)
            {
                flds[i] = new JTextField();
                flds[i].addMouseListener(hld);
                flds[i].setForeground(Color.BLACK);
                flds[i].setHorizontalAlignment(JLabel.CENTER);
                flds[i].setBorder(BorderFactory.createMatteBorder(0, 0, 0, 0, Color.red));
                flds[i].setBackground(Color.CYAN);
                flds[i].setFont(new Font("Times New Roma", Font.BOLD, 25));
                flds[i].setEditable(false);
                b.add(flds[i]);
            }
            lbl.setForeground(Color.BLUE);
            lbl.setFont(new Font("Times New Roman", Font.BOLD, 25));
            lbl.setBorder(BorderFactory.createMatteBorder(3, 3, 3, 3, Color.green));
            lbl.setHorizontalAlignment(JLabel.CENTER);
            l.add(lbl);
            add(l, BorderLayout.NORTH);
            add(b, BorderLayout.CENTER);
        }
        public class TextHandle extends MouseAdapter 
        {
            @Override
            public void mouseClicked(MouseEvent e) {    
                if(pl==false)
                {
                    JTextField fld = (JTextField) e.getSource();
                    if(fld.getText().equals(""))
                    {
                        fld.setForeground(Color.red);
                        fld.setBorder(BorderFactory.createMatteBorder(3, 3, 3, 3, Color.red));
                        fld.setText("X");
                        char c = finish();
                        if(c=='U')
                        {
                            lbl.setText("You have won");
                            over();
                            return;
                        }
                        else if(c=='O')
                        {
                            lbl.setText("Game Over. No one won");
                            over();
                            return;
                        }
                        pl = true;
                        comp();
                    }
                }
            }
        }
        public void comp()
        {
            if(pl==true)
            {
                int n = bestClic();
                flds[n].setForeground(Color.BLUE);
                flds[n].setBorder(BorderFactory.createMatteBorder(3, 3, 3, 3, Color.BLUE));
                flds[n].setText("O");
                char c = finish();
                if(c=='C')
                {
                    lbl.setText("Computer has won");
                    over();
                    return;
                }
                else if(c=='O')
                {
                    lbl.setText("Game Over. No one won.");
                    over();
                    return;
                }
                pl = false;
            }
        }
        public int bestClic()
        {
            int num = 0;
            int free[] = free();
            Random ra = new Random();
            int r = ra.nextInt(free.length);
            if(flds[4].getText().equals(""))
            {
                num = 4;
            }
            else
            {
                num = free[r];
            }
            return num;
        }
        public int[] free()
        {
            int cnt = 0;
            for(int i=0;i<9;i++)
            {
                if(flds[i].getText().equals(""))
                {
                    cnt++;
                }
            }
            int num[] = new int[cnt];
            cnt = 0;
            for(int i=0;i<9;i++)
            {
                if(flds[i].getText().equals(""))
                {
                    num[cnt] = i;
                    cnt++;
                }
            }
            return num;
        }
        public char finish()
        {
            char win = 'N';
            int c1, c2, c3, r1, r2, r3, x1, x2;
            c1 = c2 = c3 = r1 = r2 = r3 = x1 = x2 = 0;
            for(int i=0;i<9;i++)
            {
                if(i%3==0)
                {
                    if(flds[i].getText().equals("X"))
                    {
                        c1++;
                    }
                }
                if(i%3==1)
                {
                    if(flds[i].getText().equals("X"))
                    {
                        c2++;
                    }
                }
                if(i%3==2)
                {
                    if(flds[i].getText().equals("X"))
                    {
                        c3++;
                    }
                }
                if(i<3)
                {
                    if(flds[i].getText().equals("X"))
                    {
                        r1++;
                    }
                }
                else if(i<6)
                {
                    if(flds[i].getText().equals("X"))
                    {
                        r2++;
                    }
                }
                else if(i<9)
                {
                    if(flds[i].getText().equals("X"))
                    {
                        r3++;
                    }
                }
                if(i==0||i==4||i==8)
                {
                    if(flds[i].getText().equals("X"))
                    {
                        x1++;
                    }
                }
                if(i==2||i==4||i==6)
                {
                    if(flds[i].getText().equals("X"))
                    {
                        x2++;
                    }
                }
            }
            if(c1 == 3|| c2 == 3|| c3 == 3 || r1 == 3 || r2 == 3 || r3 == 3 || x1 == 3 || x2 == 3)
            {
                return 'U';
            }
            c1 = c2 = c3 = r1 = r2 = r3 = x1 = x2 = 0;
            for(int i=0;i<9;i++)
            {
                if(i%3==0)
                {
                    if(flds[i].getText().equals("O"))
                    {
                        c1++;
                    }
                }
                if(i%3==1)
                {
                    if(flds[i].getText().equals("O"))
                    {
                        c2++;
                    }
                }
                if(i%3==2)
                {
                    if(flds[i].getText().equals("O"))
                    {
                        c3++;
                    }
                }
                if(i<3)
                {
                    if(flds[i].getText().equals("O"))
                    {
                        r1++;
                    }
                }
                else if(i<6)
                {
                    if(flds[i].getText().equals("O"))
                    {
                        r2++;
                    }
                }
                else if(i<9)
                {
                    if(flds[i].getText().equals("O"))
                    {
                        r3++;
                    }
                }
                if(i==0||i==4||i==8)
                {
                    if(flds[i].getText().equals("O"))
                    {
                        x1++;
                    }
                }
                if(i==2||i==4||i==6)
                {
                    if(flds[i].getText().equals("O"))
                    {
                        x2++;
                    }
                }
            }
            if(c1 == 3|| c2 == 3|| c3 == 3 || r1 == 3 || r2 == 3 || r3 == 3 || x1 == 3 || x2 == 3)
            {
                return 'C';
            }
            int c = 0;
            for(int i=0;i<9;i++)
            {
                if(flds[i].getText().equals(""))
                {
                    c++;
                }
            }
            if(c==0)
            {
                return 'O';
            }
            return win;
        }
        public void over()
        {
            for(int i=0;i<9;i++)
            {
                flds[i].removeMouseListener(hld);
            }
        }
        public static void main(String[] args) {
            TicTacToe t = new TicTacToe();
            t.setVisible(true);
            t.setSize(350, 370);
            t.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        }
    }
    
    Ajith KP

    Artificial Intelligence - Beginner

              The question of whether a computer can think is no more interesting than the question of whether a submarine can swim.” 
    ― Edsger W. Dijkstra

    http://www.zeitnews.org/applied-sciences/computer-science/artificial-intelligence-research-revives-its-old-ambitions
              Artificial Intelligence (AI) is the study of implementation of behaviors or actions in computers which the human can do better. AI is very important in game development which the game characters/CPU player player needs to respond every actions.

              Read more details about Artificial Intelligence here: http://en.wikipedia.org/wiki/Artificial_intelligence
           
              We ca discuss more about AI implementations in games in next posts.