an overview of game program Development
Reprint please retain the author information:
Author: 88250
blog:http:/blog.csdn.net/dl88250
MSN & Gmail & qq:dl88250@gmail.com
Game is a very wide range of disciplines, big to everything development, small to the board game, Paul Vientiane. Computer game also has a rapid development, game technology is also the cornerstone of artificial intelligence. Let us first look at the history of computer chess games.
A brief history of computer game
------------------------------------------------- First chess machine in 1769, Hungarian engineer Ballans Wolfgang Fan Cambillin (Baron Wolfgang von Kempelen) made a chess-playing machine for the Austrian Queen to entertain. This is a mechanical device with a stiff appearance, but its excellent chess power comes from having a chess master cleverly hidden in the machine. So this chess-playing machine is an impostor. (as pictured) Turing's "paper Machine"
|
It was a very interesting fact that the first chess program was written before the computer was actually invented. It was written by an imaginative person who knew that a programmable computer was about to appear and that once invented, there was the ability to play chess. This gentleman is Allen Toux (Alan Turing), one of the greatest mathematicians ever. Turing's great achievement was to lead the panel to decipher Nazi Germany's "Enigma" code, thus contributing to the decisive end of the Second World War. He is very interested in chess, but despite his intelligence and great efforts to learn chess, he is a lame chess player. Soon after the war, he wrote down the instructions to make the machine play chess. Since there was not a single machine capable of executing these instructions, so he carried out his own, acting as a "human CPU", each step takes more than half an hour, "the so-called" own implementation, that is, Turing according to his written algorithm to calculate, strictly based on the results of the calculation to moves. Here is a game of chess, Turing's "paper machine" lost to colleagues: |
Turing's "paper Machine"--alick glennie Manchester 1952 1.e4 e5 2.nc3 Nf6 3.d4 Bb4 4.nf3 d6 5.bd2 Nc6 6.d5 Nd4 7.h4 Bg4 8.a4 nxf3+ 9.gxf3 Bh5 10.bb5+ c6 11.dxc6 0-0 12.cxb7 Rb8 13.ba6 Qa5 14.qe2 Nd7 15.rg1 Nc5 16.rg5 Bg6 17.bb5 Nxb7 18.0-0-0 Nc5 19.bc6 Rfc8 20.Bd 5 Bxc3 21.bxc3 Qxa4 22.kd2? [22.h5 could have been like] 22...ne6 23.rg4 Nd4? [23...rxb2! 24.bxb2 rxc2+] 24.qd3 Nb5 25.bb3 Qa6 26.bc4 Bh5 27.rg3 Qa4 28.bxb5 Qxb5 29.qxd6 Rd8 0-1.
Schonlen's StrategyBell Lab's Kraudi Schonlen (Claude Shannon) is another great mathematician of Turing's time, and he has been exploring teaching computers to play chess. He realized that the problem was that the number of moves was so terrible that the "a strategy" of searching all the moves was distinguished from the "B strategy" that removed some of the change routes. Today we also distinguish between "forced search" and "Select Search" programs, although all powerful programs are more or less the former.
chess instead of nuclear bombsDuring the war, the United States established a huge laboratory in the Alamos of New Mexico State, whose main purpose was to develop nuclear weapons. It takes a huge amount of computation to properly execute the internal explosions that trigger the chain reaction.
|
The 1946 Hungarian mathematician John Fan Neumann (John von Neumann) was assigned the task of designing a powerful computer to speed up the progress of the work. By the year 1950, a giant machine called "Maniac" was being delivered (pictured left) with thousands of tubes and switches and 10,000 instructions per second. It can also be programmed. Scientists don't use it immediately to design a bomb, but to test the machine first, and one of the first things to do is to write a chess program. This is a shrinking 6x6 chessboard, no elephant. Although this simplifies, but the program to search the depth of the four layer will take 12 minutes, "four is equivalent to the current situation both sides of the two steps", if you add the image, it will take 3 hours. |
In the middle of the 50, the machine played a three-game game. The first inning is self, Baek Seung. The second inning was for the Queen's strong chess player, the chess game for 10 hours, the result of the human master victory. The opponent of the third inning was a young girl who had just learned chess for one weeks, and the result was a 23-round victory. This is the first time in the game of intelligence that humans are negative for computers.
Chess and MathThe main problem with the program playing chess is that the number of chess steps involved is too much. On average, there are about 40 steps in each situation that conform to the rules. If you think about each step, you will encounter x 40 = 1600 situations. This means that after a two-storey (ply, one-level, half-backgammon), there will be 1600 different situations in a single step, and 2.5 million after two steps, and 4.1 billion after three steps. On average, a game of chess takes about 40 steps, so all the possible scenarios have a 10 of 128, which is far more than the total number of atoms in the world known to the universe (about 10 of 80). It's clear that no computer or other machine can search all the possible way to play chess, but humans can't. The only problem is that the machine needs to search deep depth to reach the human strategy level. Early computers could generate and evaluate about 500 scenarios per second, or 90,000 possible per step in three minutes of the game. It means they can only search the depth of three layers (that is, one step and a half), which is a very low level, the equivalent of a novice. To search more than one layer requires about 15,000 scenarios per second, which is 30 times times faster. But even if you can search four floors is very shallow, so it seems that the computer can not reach the master level.
Alpha-beta AlgorithmThe first breakthrough came in 1958, when three scientists at the University of Pittsburg, Neville, Sean and Simon (Newell, Shaw and Simon), had a major discovery: they could remove rather large portions from the search tree without affecting the final results, which they called the Alpha-beta algorithm. It is important to note that this is a purely mathematical field of skill that is independent of any chess knowledge that comes into force. Alpha-beta algorithm Diagram 1 We have a rough description of the Alpha-beta algorithm: for example, the computer has completed the evaluation of a move, began to calculate the second move. Once a single change shows the value of the returned value below the first step, you can abort the search immediately. We don't need to know exactly how bad the second move is, and the program will definitely choose the first move. Alpha-beta algorithm diagram 2 unless otherwise required, the Alpha-beta algorithm produces the same result as a full search when only the number of square roots is searched for so many scenarios. The early computer suddenly can also look forward five to six layers, to the 70 's fastest computer can search seven layers, chess force is remarkable. But even with the Alpha-beta algorithm, you need to increase the speed 5 times times to search the deep layer. The number of exponential explosive growth again catches up with the programmer.
Hardware CreatureKen Thompson, a computer scientist, Ken Thompson that the $5-25 trillion-dollar supercomputer could not be waiting to be used to improve the ability to play chess. Together with his colleagues at Bell Labs, he decided to build a dedicated machine that used hundreds of chips worth about 20,000 dollars. They call the machine "The Creature" (Belle, right below), and it only does chess. It can search around 180,000 scenarios per second (and then the supercomputer can only search 5,000). "The Creature" in the game can search eight to nine layers so deep, so you can compete with the master. From 1980 to 1983 it won the World Computer Chess and all other computer competition titles until it was replaced by the X-mps giant Machine (Cray x-mps), which was thousands of thousands of thousands.
a chip for playing chessIn the middle of the 80, Hans Bellina, a computer scientist and a professor at the University of Cameron (Hans Berliner, pictured left), took over the job Ken Thompson put down. Bellina, once the world Chess Communications champion, made a hardware-type machine called "High Technology" (HiTech), and he studied with his graduate students on pluggable chips. "High technology" with 64 parallel chips nearly won the World Computer Chess Championship for 1986 years (Champion is clay). Subsequently, several students of Bellina, including Chinese Tony Xu, such as the "core measurement" of the machine, later is "thoughtful" (Deep thought). It only costs 5000 dollars but searches 500,000 scenarios per second. Tony Xu (pictured right) later joined IBM, working with others to create IBM's current "Blue" (Deep Blue).
Deep BlueGary Kasparov's computer in Philadelphia and New York includes a IBMSP/2 server equipped with a large number of high-speed computing chips, each of which can handle 2-3 of millions of scenarios per second. With more than 200 such chips, the speed of the entire program reached 200 million scenarios per second. The chess machine can handle 200 million scenarios per second. Ken Thompson, the father of "The Creature" (also the Father of Unix and C), made a very meaningful experiment in the relationship between the draw of search depth in the 80 's. He let "the creature" himself with himself, but only one side of the search depth is increasing, averaging each additional search depth can be roughly converted into 200 chess grade ELO points. So, "The creature" search four levels of its level is about 1230 points, search to nine levels of its level reached 2328 points. Extend this curve, to the top will be smooth, you can calculate the search depth of 14 levels, reached the world championship level is 2800 points. (as shown below, the horizontal axis is the search layer, and the ordinate is the international grade.) The upper horizontal line is a reference to Kasparov's score, and a lines represents an optimistic estimate of the computer's level, B-line for pessimistic estimates, C-line for realistic estimation) search depth Draw Relationship graph experts concluded that in order to compete with the human world champion, we must do a computer 1 billion times per second (depth of 14 layers). The Navy is close, but it's not up to it. Note: The depth of the search to 14 levels here should be defined as the time allotted for all rounds in the game allocation period. Otherwise, it is not difficult to search for a single step without limiting time, or to search for some simple situations, to reach the 14 level of today's many high-speed computers. "Of course, the quality of the program also plays an important role. Today's top PC programs like Fritz and Junior can reach and handle 500,000 scenarios per second. They are, in fact, more than 2600 points away and can counter anyone but the world's top 100 players. In the fast chess War human only about the top more than 10 can be competent, but in the ultra fast chess probably only 两、三名 human chess player to pass through. It can also be seen that the speed of operation required for each higher level is not merely linear, but exponential. So 500,000 times per second to reach 2600 points of the Grand Master level, but to achieve 2800 points, according to the above estimate will need to calculate 1 billion times per second. 】
Challenge all StartAn important aspect of computer chess is the use of a broad opening library in chess. The knowledge accumulation and experience of many generations of human masters can easily be stored on the hard disk and adopted at the start stage. Even the PC program knows tens of millions of openings, and every one of those situations has a full count (such as the number of things that have been done, the ones that are better than the ones that have been used, and so on). Programs often take 15 to 20 steps before they need to be counted for the first time. If you do not benefit from these human start knowledge, the program will greatly reduce the strength. When computers gain a solid advantage from the vast number of starting knowledge accumulated from chess history, they also benefit from the search on the other end of the game.
Endgame Database This is also the influence of the Ken Thompson to serve as the pioneer of research. In the 80 's, he began to build and store all the rules of the board with four to five children. A typical five-child endgame, such as the King's Wang Chanma, contains a total of 1.21 million scenarios. Plus a moving discontinuous soldier, this number increases to 3.35 million. Thompson writes a program that produces all the rules and calculates the possible mandatory changes to each of the pieces. He also compresses the results in a way that allows a standard CD-ROM to hold about 20 pieces. The original text did not mention another Nalimov to make a significant contribution to the development of the endgame database. "Computers use these endgame databases to make every endgame perfectly perfect, just like God." For any situation in which the sub force and number of the chessboard appear, the computer can immediately know the victory, the sum or the negative, and know how many steps to take. It often announces 15 moves after the victory or will die, and the one color of the game can be optimized to defend "that is inevitable to be dead every step of the defense are trying to optimize." Deep Blue uses Thompson's endgame database, and PC programs like Fritz carry them through the search tree. It remains to be seen what effect these have on the force of chess. Some of the five sons of the mess is extremely difficult even for humans to grasp, but these five-child pieces are a tiny fraction of what Thompson is trying to do with the six-child mess, and in some six, it has to be done in more than 200 steps: Of course, it's in the realm of pure computer chess. , the proportion of experience and knowledge is very large, there are a lot of chess to know how to go without thinking about it. But the computer is "meticulous" all to calculate. So, it's not quite as important as the numbers. The development of natural hardware technology is beneficial to the computer, Thompson's six pieces, each containing 80 to 20 billion situation, just can compress into a DVD. "The high-end application is not known, and commonly used in Personal computer program Nalimov, all four pieces of the mess accounted for 30MB storage, all five pieces of the total need 7GB, as for the six pieces, now visible only some relatively simple situation and a soldier also did not, because the soldiers will rise and change, Complexity, if coupled with a considerable period of time in general computer hard to bear, do not forget that growth is not a straight line but exponential type. "Fortunately, the situation is much greater than the incredible seven pieces, from the generation is still very distant." What's more, the two ends of the game, the start and the endgame, are never going to be together. Yes, it's too hard to accept if you see a computer go 1.e4 and announce that 40 moves are going to die. But the computer in the game to stabilize the victory over the human world Championship is probably just a matter of time, a few years or a few decades later ... "the 1997 Blue in the" comeback "defeated Chess Kasparov, but the outside of the uncertainties too much, the results may not be convincing, whatNote that two of the total score is actually still Kaparov to 6.5-5.5 victory over dark blue. The October 2002 Kramnik to the deep Fritz Man-machine war, uncertainties and a bit of a tendency to the Romney, and the public opinion that the computer opportunity is not big, and to see. Kasparov himself thought that the computer was truly stable against the human world champion by 2010, and Thompson thought it would be 2018 years. Interestingly, including Bellina, Tony Xu and others in the early 90 that the computer in 1994 to achieve this point. "The source of Thompson and Kasparov: Chessbase: Michael Type: slightly abridged-------------------------------------------------
two basic elements of computer game programComputer software that can play chess should include at least the following components: 1. The representation of the chessboard, that is, the storage method of the situation in the memory, the program is based on it to analyze the situation; 2. Grasp the rules, that is, what kind of law is reasonable, if the procedure even unreasonable law can not detect, then the opponent can use this law to deceive the program; 3. Find all the reasonable algorithms, so that the program can find the best from these methods, rather than just find a way; 4. Comparison methods, including methods of comparison and comparison of the situation, so that the procedure can choose the best method; 5. User interface. This serialization will cover all but the user interface in addition to all content, the user interface in all two-dimensional chess game is similar, here is not introduced. The following sections are described in detail, and many important concepts are drawn up.
three programming languages and development environment
The specific program is to be written in a specific language, according to the characteristics of the game program, we should choose a high efficiency, the development of high efficiency of the language. C + + should be the first, in conjunction with the previous low-level assembly instruction library should be able to achieve the highest operational efficiency. But considering the convenience of development and the convenience of example code explanation, I chose Java for development. It turns out that Java does not really fit into a similar "utility" program:
Pure Java code has a good portability, so the development environment can be selected according to their actual situation. My environment is the Linux operating system +netbeans IDE+JDK 1.6.0_06.