![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
The Oblivious One
Join Date: May 2005
Location: Ontario, Canada
Posts: 648
Rep Power: 4
![]() |
is making an AI always this repetetive?
I always hate posting what looks like repetetive code, becuase I am worried I will get flamed...
Anyway... In regard's to DaWei's programming "contest" where we are to make an AI for a tic-tac-toe game, I am finding the coding to be very frusterating and repetetive, example: --first look for offensive moves, --if there are 2 of "you" on any row, column, or diagonal line, then add yourself to the whitespot --make sure you are not already on that spot --then look if there are any of "the other player" on either a row, column, or diagonal. --if there are 2, then go in the empty space, if you are not already there --if there are neither an offensive or defencive moves, make a a randome move --place "you" on the random spot, if it is free. Otherwise, get another spot This pseudo-code has resulted in about 200 lines of repetetive for loops and function calls as well as if statements. I would post it, but it is un-commented ![]() Anyway, the point of the thread: Is this all normal? :p
__________________
Dr. Zoidberg: [ecstatic] I'm going to a movie... with FRIENDS! |
|
|
|
|
|
#2 |
|
Professional Programmer
|
It sounds like you can do better.... 200 is quite a large number.
__________________
% rc4 hexkey < input > output
#define S ,t=s[i],s[i]=s[j],s[j]=t /* rc4 hexkey <file */
unsigned char k[256],s[256],i,j,t;main(c,v,e)char**v;{++v;while(++i)s[
i]=i;for(c=0;*(*v)++;k[c++]=e)sscanf((*v)++-1,"%2x",&e);while(j+=s[i]
+k[i%c]S,++i);for(j=0;c=~getchar();putchar(~c^s[t+=s[i]]))j+=s[++i]S;} |
|
|
|
|
|
#3 |
|
Professional Programmer
Join Date: Sep 2005
Location: serbia & montenegro
Posts: 484
Rep Power: 4
![]() |
Can you provide a link to your source somewhere in the net?
|
|
|
|
|
|
#4 |
|
Hobbyist Programmer
|
What language are you writing it in? One of the main reasons i prefer Python over Java now... Java's just to freakin' verbose.
You probably are repeating things you don't need to though. I'd use a minimax method for tic-tac-toe. http://ai-depot.com/LogicGames/MiniMax.html http://www.fierz.ch/strategy1.htm (both look decent, didnt take the time to read 'em too carefully. google turns up tons of stuff.) With tic-tac-toe i doubt you'd need to do any of that Alpha Beta tree pruning, although it might speed things up. Seeing your code would be nifty, too. Good luck! |
|
|
|
|
|
#5 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Obviously, it's by nature a repetetive task. The human brain has an innate pattern-recognition and evaluation ability the the microprocessor lacks entirely. This is what makes it a challenge to take something in the problem space of the human mind and work with it in the solution space of the microprocessor. Either you get down on the microprocessor's level, or you invest a lot in a layers of abstraction of various utility.
At the processor's level, the task will be highly repetetive. You must analyze the potential value of each square in terms of the conditions of all the other squares. This is where you attempt modularity of one degree or another, or just bite the bullet and crank it through. In a commercial environment, real-life constraints would affect the choices made. If your code is too messy to show, then shame on you. You lack the discipline necessary to be a successful professional programmer. A huge number of programs pass into the hands of others for correction, validation, and maintenance. If, on the other hand, you just feel your program is too "amateurish", you shouldn't let that worry you if your goal is to learn from the members of the forum. They can't read your mind very well, they need to see the code. Since it's a contest, however, I'd defer submitting the code for review until you are prepared to put a "DONE" label on it. Not that it will be DONE in the final sense, but it should be DONE in the contest sense, unless you wish to flag it a team entry.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#6 |
|
The Oblivious One
Join Date: May 2005
Location: Ontario, Canada
Posts: 648
Rep Power: 4
![]() |
I will fix the last bug I am encountering, comment the whole thing tediously, and the post it ( or atleast the header file, where all the work is done ).
For me, it is a learning expirience, not a "who is the best" type thing. ![]() I don't care if people see my effort (or my progress )
__________________
Dr. Zoidberg: [ecstatic] I'm going to a movie... with FRIENDS! |
|
|
|
|
|
#7 |
|
Expert Programmer
|
__________________
Join us at #programmingforums @ irc.freenode.net! My software never has bugs. It just develops random features.
|
|
|
|
|
|
#8 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
I hope you aren't using C/C++. If you are, and the work is "done" in the header file, I would suspect you are misusing the header-file concept. That's not a certainty, but it's a high probability. On the other hand, "include" files in scripting languages like PHP are often code, but not really "headers."
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#9 | |
|
The Oblivious One
Join Date: May 2005
Location: Ontario, Canada
Posts: 648
Rep Power: 4
![]() |
Quote:
![]()
__________________
Dr. Zoidberg: [ecstatic] I'm going to a movie... with FRIENDS! |
|
|
|
|
|
|
#10 |
|
Programming Guru
![]() Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5
![]() |
My AI logic looks something like:
def ai(self):
for index in board.free_spaces:
b = board.copy()
b[index] = self.opponent.symbol
if b.is_won:
board[index] = self.symbol
return
random.choice(list(board.free_spaces))![]() |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|