Skip to main content
GameDev.net gamedev.net
🔒 Locked

Good commercial quality code

Started by Russell May 14, 2003 at 5:09 PM 9 replies 750+ views
Original Post
Russell
Russell
Recently I read some archives of another message board in which there was a discussion about the difference between commercial chess programs and amateur/hobby chess programs. The general consensus was that the difference was not that commercial programs were using some secret methods, but that the authors of the commercial engines had created a good system that allowed them to test out new ideas quickly, and use an automated testing system to determine if the change was positive or negative. I think this probably applies to good code vs. bad code in general, so how do you create a system where you can rapidly try out new ideas and make changes to a program? Automated testing probably isn''t too hard. The closest thing that I can think of is a kind of "firewall" method, or modular approach, where you section off different parts of the program, so if you need to make a change to one part, you minimize the code you change which should result in a rapid changing process, and shouldn''t break the program. Is that what I''m looking for, or is there something better?
GaulerTheGoat
GaulerTheGoat
I always figured they used a scripting language that they probably came up with just for chess. That seems like the best way to do it to me, especially if you will have many different "personalities." If you write a good program, post it! I have beaten Chessmaster 6000, 7000 and 2 (this last one is on Playstation, but for some inexplicable reason they failed to put the sicilian opening into the book. What the hell is up with that?!) on the harder levels like: Karpov; Lasker; Keres; Morphy; Nimzovitch (Ooo, I probably didn''t spell that right ) and others (this is playing by the rules.) I''m just braggin''. I wanted to write a chess program that let the user create his/ her own personality through an intricate scripting system, but since I''ll probably never get around to it, maybe someone else can (or already has) steal the idea.

no wise fish would go anywhere without a porpoise - The Mock Turtle
Russell
Russell
A "personality" is just a group of numbers that specify what the engine''s evaluation function thinks is "better". If you select a "Karpov personality", it probably is nothing more than an opening book that contains a lot of moves that he has made over his career, and it probably has values set to make the engine prefer positional advantages instead of tactical ones, since that is the kind of player he was. There''s no need for a scripting language for this kind of thing, especially not a complex one. Just open a text file and type stuff like this:

// ***Start karpov personality file***

opening_book=karpov.bok

// 1 means more tactical, 10 means more positional
tactical_vs_positional=10

// other variables, 1 is not important and 10 is very important
king_safety="7"
pawn_structure="9"
piece_mobility="4"
// etc.
// ***end karpov file***

Then you just read in a file with all of these
settings. Good chess programs are fast, and a scripting language is just too slow (unless you use a "to C" compiler, such as a "lisp-to-c" compiler).

BTW, congratulations on beating that program. You must be an international grandmaster, since that is about the level that chessmaster is. Or, maybe you''re stretching the truth a bit...
GaulerTheGoat
GaulerTheGoat
So what you're saying is that Chessmaster has only one evaluation procedure and it takes parameters like king_safety etc? Altough it would be very slow, wouldn't it be more fun to write an evaluation function from the ground up, using a scripting language? Then you could, say, write an opponent who looked to get mated instead of avoiding it. A great idea would be to write two opponents, one who only moves his kingside pieces (plus queen,) and one who only moves his queenside pieces. Pit them against each other and watch the weirdest game ever played! I mean, THAT would be cool, and you just can't do it with one algorithm.
BTW, thank you. I assure you I am not stretching the truth, and I am not an international master. I also didn't say I beat them every time I play them . I played about 20 hard-core games against my computer last summer and I won 4. I forget how many I drew, but I believe I lost more than half. This does not give me international master status (or all the real masters would be quite pissed! )

no wise fish would go anywhere without a porpoise - The Mock Turtle

[edited by - GaulerTheGoat on May 14, 2003 8:48:42 PM]
Russell
Russell
If you wanted to write your own evaluation function, there are plenty of open source chess programs that are freely available. You could take your pick and write your own evaluation function for it.

As for making a program that tried to get mated, they exist. There are many chess variants. Losers chess (or maybe it''s suicide chess, can''t remember) is what you''re talking about. There are dozens more variants, and there are chess playing programs that can play losers chess and other variants. You can also play chess variants online at www.chessclub.com (it costs to join though, but it''s the best online chess going).

As for writing a program to only move certain pieces, that would require you to modify more than the evaluation function. Actually it really has nothing to do with the evaluation function, but the move generation function.
Extrarius
Extrarius
Just using simple weights it seems like it would be easy to make an opponent that tries to lose using the same algorithm as the one that tries to win. You would just give everything a negative weight, for ex king_safety=-10 so any move that reduces king safety would increase the score for that move.
"Walk not the trodden path, for it has borne it's burden." -John, Flying Monk
malpass
malpass
to get the NPC to move only certain pieces is simple (I did it with a 6-long tic-tac-toe game to start with to get used to using weight algorithms).

What you''d do is for each piece you want to be moved is give it an extra, say 50 wiegth points, or depending of the max points possible, so that all the others couldn''t move, then the rest would evaluate normal just starting at a higher number.
GaulerTheGoat
GaulerTheGoat
Oh, well I see, the evaluation function doesn''t actually know what he last piece moved was. I should correct myself then, I mean you could completely modify all aspects of the game including the move generating functions. BTW, I always thought it was really pathetic that the computer could not learn from its mistakes. I mean, I once played the exact same game with the computer 4 or 5 times almost in a row. I had to change my opening (reluctantly.) My point is, why don''t they write a chess program as follows: At the start of the game, the program finds the best move as usual (forget about opening book for now.) When it finds its favorite move it records the score, records the move, makes the move and then records your move. Next move it repeats the process, except that it now compares the score with the last moves score. If its score is less than last moves score, it knows its last move was not as gret as it thought it was, so it overwrites the last score with the current score. If the score went up, it does nothing ''cuz you just may be a bonehead who is playing badly. Anyway, it continues this until the game is over and it saves its record to disk. Next game, it would presumably make the same first move as last time, but it first loads its record and checks it out. Now it has some foresight! It can see that maybe that first move didn''t turn out too great so it can pick the next best move and try again. Food for thought.

no wise fish would go anywhere without a porpoise - The Mock Turtle
Russell
Russell
Regarding the problem of being able to play the same opening against a program and win over and over, this is not a big problem for any decent program. If it is a problem, it''s a simple fix. There is no need for "human level understanding" or anything. It''s a pretty simple book learning algorithm.

Basically if the computer loses, it will cut out the last book move, or flag it, or reduce it''s score, or however you''d like to handle it. So if the computer played 1. e4 e5 2. h3, and went on to lose, it would mark 2. h3 as a bad or questionable move, and next time it might still play 1. e4 e5, but it would avoid 2. h3. If 1. e4 turned out to be bad (which isn''t the case, this is just an example), it would catch it eventually. I know that Crafty does it like this, and all top commercial programs that I know of (which doesn''t include Chessmaster) use opening books that have been decades in the making. There are people whose job is to create opening books, to find good lines, to remove bad ones, and they''ve been doing this for 10-20 years. In addition, a lot of engines have a feature that will let you choose to make the opening play more random (random within it''s opening book anyway).
Russell
Russell
BTW AP, there was also a chess program that used temporal difference learning with success. It was called KnightCap. It played on an online chess server, and over a period of a few months it gained several hundred rating points. It was no silver bullet though. It only achieved a rating of (I think) around 2100 or so (top programs are around 2500-2600+). Temporal difference learning can be very powerful, and it may improve the playing strength of a program, but it won''t turn your poorly written program into a world beater.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.