File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Meaningless Drivel and the fly likes AI - anyone try to program it? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Other » Meaningless Drivel
Bookmark "AI - anyone try to program it?" Watch "AI - anyone try to program it?" New topic
Author

AI - anyone try to program it?

Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Wonder if anyone tried to program some artifical intell. into a program to play a game or something. I am working on it for tic tac toe. I almost got it done. I am not teaching it anything but to learn from its brain. Brain is just a database of games that it plays.
This is an interecsting concept to try to program. I have programmed tictactoe with every combination of moves, telling where the computer to go. I am trying to get the computer to learn where to go without me telling it.
i just have a couple of big bugs to work out.
Just wondering if anyone else jumped into this subject matter?
Plus I am trying to do this all with JavaScript so it makes it even tougher.
Eric
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1815
I've done a small amount of AI programming, (but never used a Neural Network, which seems to be the main structure for producing a 'learning' program). Instead I used Genetic Algortihms, in which you 'evolve' a program rather than 'teach' it.
I managed to get a program to learn how to play a German board game called 'Adel Verpflichtet' This involved producing a 'strategy' that competed against other 'strategies'. Once all strategies had been tested, they would 'mate'. The strategies that performed the best would have a better chance of 'mating' IN the mating process, two strategies would 'cross' at a certain point (the strategies were represented as character strings; a point in the string would be chosen and the two strategies would swap their data from that point on). The resulting new strategies were then placed in the next generation.
This worked well enough that when I sat down to play the computer at the end of evolution (100 generations), the computer not only beat me but completely routed me.
------------
(Side note: I never (well, almost never) play computer/console games. I spend my entire day in front of a computer, so when I get home that's the last place I want to be. Instead, I have a large selection of quality board games [and a much larger selection of not-so-quality board games!], most of which are German games, and get together with groups of friends to play these games. 'Adel Verpflichtet', 'Die Siedler van Catan', and 'Ra' are but a few prime examples.)
(Side Note 2: Since analyzing the computer's strategy, I have only lost the game once in the past five years. And that was to my wife, who also knows the computer's strategy....)


Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Greg Harris
Ranch Hand

Joined: Apr 12, 2001
Posts: 1012
we started on the tic-tac-toe game in a c++ class a few years ago, but never finished it. the idea was to make the computer "learn" by keeping track of losing combinations. obviously, if the computer lost with a certain set of moves in response to the opponent's moves, the computer would not make that move again. simple in theory - just a pain in the neck to keep track of.
i wrote another pseudo-ai game for the same class. it is the game of NIM - you have a jar full of marbles. you and the computer take turns removing marbles from the jar. the one who takes the last marble loses.
the rule is that you can take NO MORE than half of the marbles, but you MUST take AT LEAST one.
there is a way to win the game every time if you go first. so, my computer has stupid mode and smart mode. if you play the computer in smart mode and it goes first (or you go first and make a mistake), the computer wins.
if you play the computer in stupid mode, you will win (unless you are stupid).
of course, that is not AI, but some of my non-programmer friends think it must be.


what?
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1815
Interesting rules for NIM. I always knew it as you could take 1, 2, or 3 marbles. And there were always 21 marbles in the JAR. And you will win every time if you opponent goes first. (When you opponent takes x marbles, you take 4-x marbles)
Greg Harris
Ranch Hand

Joined: Apr 12, 2001
Posts: 1012
hmmm, we must be using a variation of the game. there is not a limit on the number of marbles in the jar for us... and if your opponent goes first and knows how to win, you will lose.
the trick to win our variation is to leave (power-of-two - 1 )in the jar after your turn.
so, if you start with 21 marbles and you go first, you want to take 6 marbles to leave 15... and so on until there are 3 marbles left and it is the opponent's turn. the most the opponent can take is 1, leaving 2 and you take 1 leaving the last marble for the opponent.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15286
    
    6

We have forums that deal with AI at http://forums.embeddedthought.com
My colleague is very much into AI and really knows his stuff.
You all should check it out. We would be willing to add some more Categories that deal with AI if we have some interested parties participating at the site.


GenRocket - A Test Data Generation Platform
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937
Wonder if anyone tried to program some artifical intell. into a program to play a game or something. I am working on it for tic tac toe.
I had this as a project in my senior year CS class. Essentially, you build a tree where each node corresponds to a game state space. That is, for every possible human move you construct all possible computer moves, and for every one of those, you construct all possible human moves again. Since there are only 9 spots in tic-tac-toe, your tree has only 9 levels. Once you build a tree, you evaluate the position at each node at the bottom of the tree. Subsequently, you traverse back from the best node on the bottom up to the current level and make a move. It's just a hundred lines of code or so.
This is just one way to do AI, of course. There are other techniques, such as neural networks, genetic programming, fuzzy logic, or even plain old regression techniques.
Eugene.
Greg Harris
Ranch Hand

Joined: Apr 12, 2001
Posts: 1012
Originally posted by Gregg Bolinger:
We have forums that deal with AI at http://forums.embeddedthought.com

looks like a great site, gregg... i will have to check it out this weekend. i am getting back into c++ this summer for a "Linux Systems Programming" class, so i am sure i can use a refresher.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15286
    
    6

Originally posted by Greg Harris:

looks like a great site, gregg... i will have to check it out this weekend. i am getting back into c++ this summer for a "Linux Systems Programming" class, so i am sure i can use a refresher.

Good deal!
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4339
    
    2

gee...and i thought i was doing good by having my Ship Captain and Crew game not roll for a better score if it had already won (since it rerolled 3's and saved 4's it would have been possible for it to reroll and get a lower score) :roll:


SCJP
Visit my download page
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: AI - anyone try to program it?
 
Similar Threads
Stumbling Block at the beginning
IS JAVA THE RIGHT LANGUAGE?
Careers, Learning, Programming...
Comm Api... ARGH!
jsp, and php learning question