Search For Guidance

Showing posts with label Programming. Show all posts
Showing posts with label Programming. Show all posts

Monday, September 29, 2008

Python

If only life worked like Python...

>>>import happiness
>>>gravity = 1.6
>>>hasPizza = true
>>>import heartthrob
>>>hasLife = true
>>>a = 0
>>>while a <>>>getMoney(1000000000)
>>>publishBook('The Adventures of Nathan Fondue')
>>>haveFun = true
>>>ageLength = 90
>>>sexLife = 'Excellent'
>>>currentAge = 15
>>>while currentAge <>>>die(In_Sleep)
>>>reincarnate(Jack_Russell_Terrier)

If only...

Wednesday, April 30, 2008

My own Program

Okay, so if you're a bit daunted by the sheer number of files needed, you can condense them (although I'm running into a few bugs). Since this is a "psychiatrist", you may be able to use it for advice. Here's the code (in Java):

import java.util.*;
import java.io.*;
import javax.swing.*;
public class ArtificialIntelligence{
public static void main(String args[]) throws NoSuchElementException {
String input = "";
String name = "";
String output = "Hello. What is your name?";
name = JOptionPane.showInputDialog(output, "");
output = "Hello, " + name + ".";
JOptionPane.showMessageDialog(null, output); output = "Why are you here?";
while(true)
{
input = JOptionPane.showInputDialog(output, "");
StringTokenizer t = new StringTokenizer(input, " ");
int i = t.countTokens();
try {
while(t.hasMoreTokens())
{ String cool = t.nextToken();
if(cool.equalsIgnoreCase("believe"))
output = "Why would you want to believe?";
else if(cool.equalsIgnoreCase("because"))
output = "Ah, but what if the because isn't true?";
else if(cool.equalsIgnoreCase("no"))
output = "That's very negative.";
else if(cool.equalsIgnoreCase("know"))
output = "And what makes you think you know anything?";
else if(cool.equalsIgnoreCase("sex"))
output = "I am a machine. I know nothing of sex.";
else if(cool.equalsIgnoreCase("bye"))
output = "Goodbye.";
else if(cool.equalsIgnoreCase("goodbye"))
output = "Goodbye.";
else if(cool.equalsIgnoreCase("hate"))
output = "Hate is bad. It leads to the Dark Side, as Yoda's quote goes: \"Fear leads to anger. Anger leads to hate. Hate leads to the Dark Side.\"";
else if(cool.equalsIgnoreCase("Star") && t.nextToken().equalsIgnoreCase("Wars"))
output = "Star Wars is cool! I like it too, especially R2-D2. Although General Grievous was pretty sweet too.";
else if(cool.equalsIgnoreCase("friend") t.nextToken().equalsIgnoreCase("friends"))
output = "Friends are nice sometimes, but often are fickle. Choose them wisely.";
else if(cool.equalsIgnoreCase("why"))
output = "I don't know. Only you can answer that question.";
else if(cool.equalsIgnoreCase("food"))
output = "I have never had food. Is it good?";
else if(cool.equalsIgnoreCase("good"))
output = "Good is relative. Also, nothing is an absolute, other than a boolean.";
else if(cool.equalsIgnoreCase("yes"))
output = "That's good. Do you have any interests or hobbies?";
else if(cool.equalsIgnoreCase("HELP"))
output = "How can I help? I am simply a machine.";
}
}
catch(NoSuchElementException e)
{
output = "I'm sorry, I cannot respond to that.";
}
}
}
}

Tuesday, April 29, 2008

Programming

Alright, this is the start of what I'm sure will be my FAVORITE topic. In this topic, I will be covering some of the coolest programs I've seen, in a variety of programming languages.

For my first post, I will discuss Eliza. This is one of the first AI programs to (unofficially) pass the Turing test, developed by (surprise!) Alan Turing. The test is simple: a human and a computer are available to talk, and an unknowing participant talks to one of them. If said participant mistakes the computer for the human, the computer has passed the Turing test. To download the source code for Eliza, visit http://chayden.net/Eliza/eliza.html. It contains EVERYTHING they used, and could lead to even better programs! See if you can't contribute.