|
Beat my noughts and crosses bot? |
James Stanley
Member #7,275
May 2006
|
I'm not sure exactly where to post this, but I've written a noughts and crosses bot (Charlie), and I'd like some of you to see if it is beatable (I'd rather it wasn't). The code is attached, compile with... gcc -o noughts noughts.c charlie.c
Then run noughts. Type 0 if you want to start, or X if you want Charlie to start. If you manage to beat Charlie, can you please post the game? |
Vanneto
Member #8,643
May 2007
|
There is nothing attached. In capitalist America bank robs you. |
James Stanley
Member #7,275
May 2006
|
Hmm... EDIT: |
Slartibartfast
Member #8,789
June 2007
|
I'm sorry for being rude, but what's the point? *-well, that's an exaggeration, but pretty much everyone I know that is familiar with the rules of the game is smart enough never to lose. (and so, never to win.) ---- |
James Stanley
Member #7,275
May 2006
|
Quote: I'm sorry for being rude, but what's the point?
I thought I'd got it to that state before, but then somebody at my school beat it. |
Slartibartfast
Member #8,789
June 2007
|
I meant the question more along the lines of why program a tic tac toe bot, considering that it is such a simple game, but I'm guessing you did it for fun and personal enlightenment (rather than to boast the unbeatable tic tac toe player). Hmmm, this post reminds me of a game I programmed in allegro a long while ago. (I didn't feel it was finished, and then abandoned it, so I didn't feel like adding it to the depot, or sharing it. [Plus its not that cool of a game, and I'm not really sure how to add games to the depot]) ---- |
James Stanley
Member #7,275
May 2006
|
I did it because I plan to learn about programming bots. I thought 'what better place to start than the simplest game I can think of?' I'm going to play your game now. EDIT: |
Slartibartfast
Member #8,789
June 2007
|
Hmm, that's true. ---- |
Matthew Leverton
Supreme Loser
January 1999
|
Charlie beat me because the coordinates are messed up. 0,1 should be row 0, column 1. But I digress. I played the three different variations of the game and it was a draw every time. |
James Stanley
Member #7,275
May 2006
|
Well my compiler didn't enjoy it, but it compiled. EDIT: Quote: Charlie beat me because the coordinates are messed up. 0,1 should be row 0, column 1. But I digress.
What? Quote: I played the three different variations of the game and it was a draw every time. Good. Thanks for testing! EDIT2: |
Slartibartfast
Member #8,789
June 2007
|
Quote: Well my compiler didn't enjoy it, but it compiled. Like I said, its quite ugly. Quote: Your AI's pretty good, too. I'm going to have to read that.
Its a really simple algorithm, first it builds a list of where it can place its mark, then it checks the neighbours of each place in the list and gives it a "grade" on how important it is (which depends on the number of identical marks in a row, and upon the grade of the squares that the next player will now be able to put on top of this square), and picks the highest scored one. BTW, the code I posted in the previous post is not the latest code, turns out its an older version of the game (also with a weaker AI). I attached the newest code to this post. IIRC there's still one tiny little kink in the AI I didn't fix even in the newest version. (where it doesn't properly recognize a few very certain cases) ---- |
kazzmir
Member #1,786
December 2001
|
Hey thats a neat game. And you're( Slartibartfast ) AI is pretty good. Initially I didn't understand the game mechanics, but I looked at the source and figured it out. I only won 2/14 games. |
Slartibartfast
Member #8,789
June 2007
|
Quote: Hey thats a neat game. And you're( Slartibartfast ) AI is pretty good. Initially I didn't understand the game mechanics, but I looked at the source and figured it out. I only won 2/14 games.
(Thanks.) ---- |
Kibiz0r
Member #6,203
September 2005
|
"Beat my noughts" sounds... naughty. --- |
bamccaig
Member #7,536
July 2006
|
Slartibartfast said: ...if you (the player) make the same moves, then the AI will make the same moves, so you can just win once and then repeat that game over and over again. ...I beat it ~75% of the time.
-- acc.js | al4anim - Allegro 4 Animation library | Allegro 5 VS/NuGet Guide | Allegro.cc Mockup | Allegro.cc <code> Tag | Allegro 4 Timer Example (w/ Semaphores) | Allegro 5 "Winpkg" (MSVC readme) | Bambot | Blog | C++ STL Container Flowchart | Castopulence Software | Check Return Values | Derail? | Is This A Discussion? Flow Chart | Filesystem Hierarchy Standard | Clean Code Talks - Global State and Singletons | How To Use Header Files | GNU/Linux (Debian, Fedora, Gentoo) | rot (rot13, rot47, rotN) | Streaming |
Slartibartfast
Member #8,789
June 2007
|
bamccaig said:
Obviously when I intentionally don't repeat winning sequences. ---- |
Evert
Member #794
November 2000
|
Damnit, now look what you've made me do? The rules for the 20-liners were originally that the code had to be no more than 20 lines long. This was later clarified to mean it should not have more than 20 statement ending semicolons. This bit of code only has 16, so it can be written in about 16 lines of sourcecode - it's quite a bit more than that presently because I've tried to make the code a bit readable.
Untested for N>3. PS. Oh, in case you were wondering, it's quite unbeatable. |
|