Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Work in Progress / learning AI [open source]

Author
Message
El Goorf
17
Years of Service
User Offline
Joined: 17th Sep 2006
Location: Uni: Manchester, Home: Dunstable
Posted: 17th Feb 2007 02:13 Edited at: 17th Feb 2007 02:18
about two years ago I tried naughts and crosses, but with a different approach to AI. Instead of programming it to make lines, or block off th eplayers lines, i wanted it to randomly pick which square to play in, and learn over time which moves are good or bad by storing the results of different combinations of moves.

that project went uncompleted but this morning I went back and revisitted the project and have just completed it.

It works by going through a list of all the previous games it's had where the same combinations of moves have been played. for each reamining available square, the ai +'s or -'s the value of the square by counting how many games have been won or lost as a result of making that move, and then going for the one with the greatest value since it has the most chance of winning, judging from history.

and now, the code:



however, at the moment it only judges what to do next by its own history of winning or losing. what i need to do now is also judge which square to go in by observing the player's winnings and losings. for example, if a player has one most by playing in a particular square, then the ai needs to go for that square to stop the player getting it.

Tell me what you think so far

edit: oops forgot to state controls.
click on square to play it, once a game is played, press the any key to start a new game.
HyperByte
17
Years of Service
User Offline
Joined: 3rd Jan 2007
Location: in a small kola bear costume
Posted: 17th Feb 2007 05:17 Edited at: 17th Feb 2007 05:17
Wow it works pretty good but there are a few problems with the AI but Im sure you'll be able to fix it. But good job so far.


(since I tested yours you should test mine "secret knock")

On a scale from one to ten one being very smart and ten being an absolute genius your none of the above
El Goorf
17
Years of Service
User Offline
Joined: 17th Sep 2006
Location: Uni: Manchester, Home: Dunstable
Posted: 17th Feb 2007 11:34 Edited at: 18th Feb 2007 17:33


the AI now has the ability to predict the human's next move by looking at past games.

I've also stopped it from storing repeats of games, to both save memory and stop biasing its desisions unnessecerily (sp?).

Given the number of possible combinations for th egame to take place, the AI will be extremely dumb to begin with. I find it best to always go for the same win every time, for example I always aim for a diagonal down-left. after a just a few games, the AI will manage to make the game a draw 80% of the time, win about 5%, whenever I go for the said diagonal.

edit: just spotted a glitch when detecting wins. im on it now and then i think i'll declare this finished.

edit2: the win condition glitch seems to have been a one off. I noticed that the AI was no repeating moves that caused it to lose, i found that re-enabling the logging of repeated games helped solve this.

at line 83 change the block of text to this:


hence, final code:



edit: i've had a brainwave thats caused me remove the "completed" status from this project.

by the way, link to project's page on my site:
http://notmybase.com/main/node/3
El Goorf
17
Years of Service
User Offline
Joined: 17th Sep 2006
Location: Uni: Manchester, Home: Dunstable
Posted: 19th Feb 2007 16:43
bugfix:

I found what was causing the checkwin() function to not detect when a game had been won.

updated function:


updated code:


http://notmybase.com/main
All my base are not belong to anyone.
Advancement Games
19
Years of Service
User Offline
Joined: 6th Jan 2005
Location:
Posted: 21st Feb 2007 17:24
After it learns my moves, it seems to be picking in a sequence what moves it will try. Good work though, it does become smarter as the game progresses.
Silvester
18
Years of Service
User Offline
Joined: 7th Dec 2005
Location: Netherlands
Posted: 21st Feb 2007 17:30
After 1 turn it just stays the same and doesnt respond anymore...

-Prince Of Darkness
El Goorf
17
Years of Service
User Offline
Joined: 17th Sep 2006
Location: Uni: Manchester, Home: Dunstable
Posted: 21st Feb 2007 21:19 Edited at: 21st Feb 2007 21:41
prince how do you mean? i just came here to declare this project finished, and here you are saying how it "doesnt respond" >.<

http://notmybase.com/main/learningai

finalised code:

the AI now has the first turn since it opens up more possibilities for it to learn from.



edit:
actually im starting to think it was better when the human play went first. the AI's learning curve was a lot more obvious then.

near the top of the code, change the start variable
1= AI goes fuirst
0 = human goes first

tell me what you think.

http://notmybase.com/main
All my base are not belong to anyone.
Turoid
20
Years of Service
User Offline
Joined: 1st Nov 2003
Location: The Netherlands
Posted: 13th Mar 2007 23:44
hey that's cool, I played a few games and I saw the AI kinda learning my moves indeed well done. It's more learning and placing itself on places I did the round before than actually thinking of how it could win... <myenglish>SMACK</myenglish>

danielp
User Banned
Posted: 19th Mar 2007 09:48 Edited at: 19th Mar 2007 09:48
Still kicking it's ass after about 30 rounds - all you have to do is try to predict what it will do next, and then just trick it.

I guess it would eventually have enough data to beat me or at least draw continuously.

The problem with "1's and 0's" is whoever starts gets a huge advantage, if they place there markers right - then the second player only has 2 options - draw or loose. Unless the first player stuffs up.

I agree with Turoid, I wouldn't call it learning - just copying.

You might want to have a look at some of the chatterbots that are available on the internet, they work in a similar way. They'll answer questions based on what they have already been told.

Still, nice working programming it - hope you can extend (the program) beyond just naughts and crosses.

danielp

danielp
Email - thegamecreators@danielp.e4ward.com
My Specs - 2047MB RAM | P4 3.4GHz | XP 5.1.2600 SP2 | GeForce 6800 256MB | Dell 230310 1600x1200 34x27cm

Login to post a reply

Server time is: 2024-05-04 07:15:58
Your offset time is: 2024-05-04 07:15:58