AI in Java, Ideas and Help

For AI lovers everywhere, Help each other and post questions

Page 1 of 1

1 Replies - 1168 Views - Last Post: 15 January 2007 - 02:17 PM Rate Topic: -----

#1 MoonFai_ZeroMI  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 15-January 07

AI in Java, Ideas and Help

Posted 15 January 2007 - 11:28 AM

Well, people call me crazy, but trying never hurt anyone. right now im working on the Nural Net (memory saving and keeping) and have completed the basics of the user interface and the "time running" loop (that was the eaisiest part, so i got it out of the way :P ). My idea is to take everypart of the human brain (or at least what i think it does) and turn it into code, and before u say anything, i know that some of the brains functions can't be converted, but the ones that can are the ones that count.


Anyone with ideas on creating an AI or foud an eaiser way to rewite existing code, plz tell.


well, heres what i got so far:
(PS: havnet finished the buttons on the menu yet, having trouble with the ActionListener!)

//A.I. Number 1: Larexene Prototype
//Create file Named "AI Number 1 Data.txt"

import java.io.*;
import javax.swing.*;
import java.io.File;
import javax.swing.JOptionPane;
import java.awt.event.*;
import java.awt.*;

public class AInumb1
{
	static Data AI;
	static File AiData;
	static Thread LifeSpan= new AiLifeSpan();
	static Thread WhatTimeIsIt= new AiTimeReader();
	static Thread Linguistics= new AiLinguistics();
	static Thread UserMenu= new AiMenu();
	static Thread NuralNet= new AiNuralNet();
	static Thread PrgmCall= new AiPrgmCall();
	static Thread MindLoop= new AiMindLoop();
	public static void main(String args[])
	{
		String AIname="AI #1";
		int t=0;
		String UsrName= "Guest";
		
		String Con=JOptionPane.showInputDialog(AIname+": UPLOAD FILE (1)YES OR (2)NO?");
		int Confirm= Integer.parseInt(Con);
		if (Confirm==1) 
		{
			JFileChooser FileChoose= new JFileChooser(); 
			int result= FileChoose.showOpenDialog(null);
			AiData=null;
			if (result==JFileChooser.APPROVE_OPTION)
				AiData= FileChoose.getSelectedFile();
			System.out.println("UPLOADING: "+ AiData.getName());
			BufferedReader Uploading= getReader(AiData);
			AI= readData(Uploading);
			AIname= AI.AIname;
			UsrName= AI.UsrName;
			t= AI.t;	
			MindLoop.start();
		}
		else if(Confirm==2)
		{	
			MindLoop.start();
			JOptionPane.showMessageDialog(null,AIname+": Start up complete\nHello.");
			JOptionPane.showMessageDialog(null, AIname+": My name is "+AIname);
			UsrName= JOptionPane.showInputDialog(AIname+": What is your name user?");
			JOptionPane.showMessageDialog(null, AIname+": O, nice to meet you "+UsrName);
			AI.UsrName= UsrName;
		}
		else if((Confirm!=1)||(Confirm!=2))
		{ System.out.println("ERROR IN LOADING...."); System.exit(0);}
			
		
	}	
	private static BufferedReader getReader(File AiData)
	{
		BufferedReader Uploading= null;
		try {Uploading=new BufferedReader(new FileReader(AiData));}
		catch(FileNotFoundException e) {System.out.println("THE FILE DOES NOT EXIST..."); System.exit(0);}
		catch(IOException e) {System.out.println("I/O ERROR...."); System.exit(0);}
		return Uploading;
	}
	
	private static Data readData(BufferedReader Uploading)
	{
		String line= "";
		String[] FragLine;
		int t;
		String AIname;
		String UsrName;
		
		try {line= Uploading.readLine();}
		catch(IOException e) {System.out.println("I/O ERROR"); System.exit(0);}
		if (line==null) {return null;}
		else {FragLine=line.split("\t"); AIname=FragLine[0]; t=Integer.parseInt(FragLine[1]); UsrName=FragLine[2];}
		return new Data(AIname, t, UsrName);
	}
	
	// Mind-Loop Thread
	public static class AiMindLoop extends Thread
	{
		public void run()
		{
			LifeSpan.start();
			UserMenu.start();

		}
	
	}
	
	
	
	// Lfiespan Thread 
	public static class AiLifeSpan extends Thread
	{
		int t= Data.t;
		public void run()
		{
			for(; t>=0; t++) {System.out.println("Time Running (in sec): "+t); AI.t=t; try {Thread.sleep(1000);} catch(InterruptedException e){}}
		}
	}
	
	
	
	//Linguistics Thread
	public static class AiLinguistics extends Thread
	{
	
	}
	
	

	//Menu Thread
	public static class AiMenu extends Thread
	{
		static JTextField logBox= new JTextField(20);
		static JButton Open,Close,BackUp,StandBy,Talk;
		static JFrame frame = new JFrame();
		public void run()
		{
			frame.getContentPane().add(init());
			//Activate Menu!!
			frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
			frame.setVisible(true);
		}
		
		public static JPanel init()
		{
			String UsrName=Data.UsrName;
			if (UsrName==null) UsrName="Guest"; else UsrName=Data.UsrName;
			String AIname=Data.AIname;
			if (AIname==null) AIname="AI #1"; else AIname= Data.AIname;
			
			frame.setSize(500,500);
			ClickListener cl= new ClickListener();
			JPanel panel= new JPanel();
			panel.setLayout(new GridBagLayout());
			JTextField logBox= new JTextField(20);
			JButton Open,Close,BackUp,StandBy,Talk;
			Box MenuAiName= Box.createVerticalBox(); MenuAiName.add(new JLabel("A.I.: "+AIname));
			MenuAiName.add(Box.createVerticalStrut(20)); MenuAiName.add(new JLabel("User: "+UsrName));
			addItem(panel, MenuAiName, 4,6,1,1, GridBagConstraints.WEST);
			Box DialogBox= Box.createVerticalBox(); DialogBox.add(logBox); DialogBox.add(Box.createVerticalStrut(10));
			DialogBox.add(new JLabel("RESPONCE BOX HERE"));
			addItem(panel, DialogBox, 1,6,2,1,GridBagConstraints.WEST);
			addItem(panel, new JLabel("PICTUER BOX HERE"), 2,2,3,3, GridBagConstraints.CENTER);
			addItem(panel, new JLabel("Time Running: "+Data.t), 4,6,1,1, GridBagConstraints.WEST);
			Box buttonBox= Box.createHorizontalBox();
			Open= new JButton("Open PRGM");
			Close= new JButton("Close AI");
			BackUp= new JButton("Back-Up AI");
			StandBy= new JButton("Stand By");
			Talk= new JButton("Talk To");
			BackUp.addActionListener(cl);
		/*	
			Close.addActionListener(cl);
			Open.addActionListener(cl);
			StandBy.addActionListener(cl);
			Talk.addActionListener(cl);
		*/
			buttonBox.add(Open); buttonBox.add(Box.createHorizontalStrut(30)); buttonBox.add(Close);
			buttonBox.add(Box.createHorizontalStrut(30)); buttonBox.add(BackUp); buttonBox.add(Box.createHorizontalStrut(30));
			buttonBox.add(StandBy); addItem(panel, buttonBox, 1,0,4,1, GridBagConstraints.CENTER);
			Box butBox= Box.createHorizontalBox();butBox.add(Talk); 
			addItem(panel, butBox, 3,6,1,1, GridBagConstraints.CENTER);
			
			return panel;
		}
		
		
		
		private static void addItem(JPanel p, JComponent c, int x, int y, int width, int height, int align)
		{
			GridBagConstraints GX= new GridBagConstraints();
			GX.gridx= x; GX.gridy= y; GX.gridwidth= width; GX.gridheight= height;
			GX.weightx=50.0; GX.weighty=50.0; GX.insets= new Insets(5,5,5,5);
			GX.anchor= align; GX.fill= GridBagConstraints.NONE;
			p.add(c,GX);
		}

		private static class ClickListener implements ActionListener
		{
			public void actionPerformed(ActionEvent e)
			{
				if (e.getSource()== BackUp)
				{
					NuralNet.start();
					UserMenu.start();
				}
			/*
				else if(e.getSource()==Talk)
				etc, finish when other buttons are ready.
			*/
			}	
		}
	
	}
	
	
	
	//Nural Net Thread
	public static class AiNuralNet extends Thread
	{	
		public void run()
		{

				PrintWriter out= openWriter();
				writeFile(out);
				out.close();	
			
		}
		
		private static PrintWriter openWriter()
		{
			try
			{ 
				File AiDataSaveFile;
				JFileChooser FileChoose= new JFileChooser(); 
				int result= FileChoose.showSaveDialog(null);
				AiDataSaveFile=null;
				if (result==JFileChooser.APPROVE_OPTION)
					AiDataSaveFile= FileChoose.getSelectedFile();
				System.out.println("Saving To: "+ AiDataSaveFile.getName());
				PrintWriter out= new PrintWriter(new BufferedWriter(new FileWriter(AiDataSaveFile)), true);
				return out;
			}
			catch (IOException e)
			{
				System.out.println("I/O Error");
			}
			return null;
		}
		
		private static void writeFile(PrintWriter out)
		{
			String lineOfData= AI.AIname;
			lineOfData+= "\t"+AI.t;
			lineOfData+= "\t"+AI.UsrName;
			out.println(lineOfData);
		}
	}
	
	
	
	//Time Thread
	public static class AiTimeReader extends Thread
	{
		//JOptionPane.showMessageDialog(null,"Time: "+Time);
		
	}
	
	
	
	//Acsess Thread
	public static class AiPrgmCall extends Thread
	{
	
	}
	
	
	//AI Data Saver
	private static class Data
	{
		static String AIname;
		static int t;
		static String UsrName;
		
		public Data(String AIname, int t, String UsrName) 
		{
			this.AIname= AIname; 
			this.t= t; 
			this.UsrName= UsrName;
		}
	}
}


there, u have it cool huh?. prbly not, but still all help or comments will be taken, and seriously at that, o and overshow the changed code if u do reply with an alteration.

thanks, MoonFai

Is This A Good Question/Topic? 0
  • +

Replies To: AI in Java, Ideas and Help

#2 GWatt  Icon User is offline

  • member icon

Reputation: 264
  • View blog
  • Posts: 3,059
  • Joined: 01-December 05

Re: AI in Java, Ideas and Help

Posted 15 January 2007 - 02:17 PM

Can it analyze Paradise Lost for me? That'd be pretty cool.

I think for AI programming, a compiled language might not be the best. I know that the language LISP (completely interpreted) can edit its own source code at runtime, which could lead to some pretty interesting programs.

This post has been edited by GWatt: 15 January 2007 - 02:19 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1