Presentation is loading. Please wait.

Presentation is loading. Please wait.

Design of a real time strategy game with a genetic AI By Bharat Ponnaluri.

Similar presentations


Presentation on theme: "Design of a real time strategy game with a genetic AI By Bharat Ponnaluri."— Presentation transcript:

1 Design of a real time strategy game with a genetic AI By Bharat Ponnaluri

2 Abstract Current strategy game AI Involved combinations of heuristics and constants. The combinations need to be optimized for the AI to be effective Too many possible constants&combinations-->difficult optimization Chess heuristic evaluations Moves available Is the king safe Pawn structure Material balance Genetic AI Can produce constants and combinations of heuristic algorithms quickly by eliminating suboptimal combinations.

3 Introduction Design of a simple real time strategy game –Build troops and try to take over cities –Like Risk in real time –Goal is to have an intelligent AI optimized with a Genetic Algorithm(GA). AI design –Coding of simple building block heuristic evaluation functions –Addition of constants(Agressiveness,stinginess) that determine behaviour –Chromosomes will be random combinations of Heuristic evalution functions –Used to evaluate the quality of a possible course of action based on game data

4 Personality Traits Goal: To make the AI more interesting and humanlike Traits –Agressiveness –Paranoia –Stinginess –Vengence –Trustworthiness

5 Observation AI will take advantage of other players' behavior Examples –Assertivness The AI will keep track of when a player retreats The AI will attack a player which retreats a lot –Attacking game leader One player is threatening to win AI will track who tries to stop that player Then the AI will let that player do the work

6 Game Theory Advantages –Not very complicated –Easily understandable by AI –Good model of human behavior

7 Game Theory: War of attrition Two players fighting over city Backing down=loss in percieved assertiveness Fighting=massive loss in strength t=time that conflict lasts Don't FightFight Don't Fight(0,0,0)(-t+1,-t,0) Fight(t,-t+1,0)(-t,-t,2*t)

8 Sample chromosome Chromosome enemyStrength()/2*myStrength()-3*fooA()/43.........+power() Possible genes public int fooA().... public int enemyStrength().... public int myStrength()

9 Heuristic evaluation functions –Used to evaluate the quality of a possible course of action based on game data Example: –Public int getTrafficJamFactor() Return ( 1.001^(number of cars))/roadSize

10 How do GAs work Replicate evolution Steps 1.Determine random combinations of heuristics and constants(chromosomes) 2.Test chromosomes 3.Remove suboptimal chromosomes 4.Mutate surviving chromosomes 5.Swap data between surviving chromosomes 6.If chromosomes are optimal,end algorithm 7.Otherwise, repeat steps 1-7

11 Advantages and Disadvantages Advantages o Can function without user input o Can optimize a large number of constants o Usually is very good at optimizing stuff o Can determine unknown solutions Possible disadvantages o GAs are complicated o Take a significant amount of computing power o Networking will increase complexity

12 Evolutionary Stable Strategies(ESS) Gene pool of defectors means cooperating players will lose Advantages –Diverse AI personalities Disadvantages –May lead to suboptimal/boring AI's CooperateDefect Cooperate1,1-10,3 Defect3,-10-5,-5

13 ESS: Example Population of turtling AI's AI's only counterattack or attack weak players A more balanced AI will lose Playing against a group of turtling AI's is boring

14 New Heurstics Find Targets() –Average proximity –Income power factor –Troop power factor –Potential borders

15

16 Testing results Numbers greater than 1 are not good From last working version(before new heurstics) Number of Troops On Map Rendering Time Update Time AI 101.10 0.060.55 15002.50 0.070.63 2500 2.85 0.080.56

17 Generating a target number using a mathematical expression –Combination of numbers(1-9) and mathematical operators(-,+,*,/) adding up to a target number –Each number=4 bits –Chromosome 6.7657+5.7845*4.8568/2.8969 +1.756857 –Fitness value is the absolute value of (targetNumber)/(expressionValue-targetNumber) –Can be scaled for large numbers &decimals –No attempting to use brute force to test out random combinations.

18 Important Classes Classes –FormualaGenerator: Driver Program –GraphPanel: Draws the graph of the average fitness and maximum fitness. Makes the GA run periodically in synchornization with the graph. –Chromosome: Represents the chromosomes/expressions.

19 Static Mutation

20 Dynamic Mutation

21 Sample Expressions for 150 Static Mutation –1.0292804250299605 + ((2.7400839829565777 / 1.0605221382369576) * 7.741718241469524 * 7.316070011134583) - ((-0.9821438516501173) / 4.043144676725913) + (0.9986661909539591 * 6.634650893629718 * 0.3645726822807098) = 150.026535 Dynamic Mutation –1.0292804250299605 + ((2.7400839829565777 / 1.0605221382369576) * 7.741718241469524 * 7.316070011134583) - ((-0.9821438516501173) / 4.043144676725913) + (0.9986661909539591 * 6.634650893629718 * 0.3645726822807098) = 150.026535

22 Analysis of results The dynamic mutation did not help because the standard deviations were 0 The GA generally works but occasionally crashes due to a bug which deletes all the chromosomes The graphs show rapid spikes in fitness followed by a rapid decline –Shows that the GA does not get stuck on local exterma. There are long period of nearly static fitness levels.

23 Important Methods RemoveFailures: –Finds all the chromosomes in the population with a fitness that is below average and removes them Crossover: –Picks random chromosomes to mate and produce children. –Once enough children are produced, the children are saved and the parents are deleted Mutations –Generates a mutation rate based on the standard deviation of the fitness values and average change of them –Calls the mutate method and gives it the mutation rate DrawGraph: Takes the saved data for the highest fitness rate, average fitness rate, standard deviation, and change of population and outputs the data visually.

24 Future Plan Debug implementation of dynamic mutation Make genetic algoritm generate formuals for input-output pairs based on common functions Create scenarios for my game with obvious good/bad choices for each player Run GA for game –Fitness rates will be based on how well the AI's evaluates the scenarios. –Running a full version of my game will take too much time.


Download ppt "Design of a real time strategy game with a genetic AI By Bharat Ponnaluri."

Similar presentations


Ads by Google