PlaceholderGames / AI4Games-2020-Code-the-Classics

Private fork of Wireframe Magazine's Code the Classics repo for CS3S667 Assignment 1
0 stars 0 forks source link

Caverns Enemy Ai Example #9

Closed ghost closed 3 years ago

ghost commented 3 years ago

Im having trouble finding the position of the enemy ai us when i retrieve it i get just there spawn position. If i can get an example for this it will be good might clear up some things :D

DoctorMikeReddy commented 3 years ago

Here is a video of your current AI

Anthimos Cavern AI prototype.zip

The AI performs well, if accidentally, due to the use of bubbles, but I suspect it is not intended to be used as cleverly as it might appear. The bot stalls at left or right edges, or stands still at times. The route is not optimal, and it is still prone to random shots from the robot antagonists. A good start

DoctorMikeReddy commented 3 years ago

I will annotate mike-cavern-demo with code that can detect the location of Enemy AI.

ghost commented 3 years ago

Thank you mike for the help it mostly does preforms well by shear luck ill have to rethink my if statements

DoctorMikeReddy commented 3 years ago

Ok, I would suggest that you look at the Robot AI movement, to make it change direction when it collides with a wall, as this code already exists. I won't implement that again, as it is already done. However, in the Player update, we can detect the location of all the enemies and check to see if they are in the same row as us - potentially able to shoot us, but I won't include code to determine if they are aggressive, or pointing the right way, as that is up for you to do - so I will upload that code in a few minutes. On line 253 (in the original code) we have an else section for when we are not immune, although the AI code could go anywhere in Player.update(). Here is an example of code to print off the location of all the enemies on screen: 253 ` else:

We're not hurt

            # *** Here is probably where I would do the AI code, replacing the keyboard stuff

            for robot in game.enemies:      # *** We are going to print off the location of baddies
                print('Robot location: (' + str(robot.x) + ',' + str(robot.y) + ')')`

which gives us output like so: Robot location: (686.0,324.0) Robot location: (301.0,224.0) Robot location: (157.0,124.0) Robot location: (684.0,324.0) Robot location: (300.0,224.0) Robot location: (156.0,124.0) Robot location: (682.0,324.0) Robot location: (299.0,224.0) NOTE, the .0 bit is because we are converting the number to a string. So, now we need to show OUR location too, by adding: print('Player location: (' + str(self.x) + ',' + str(self.y) + ')') which gives us debug output: Robot location: (276.0,224.0) Robot location: (685.0,324.0) Robot location: (228.0,6.0) Player location: (308.0,224.0) All we need to do now is do a check on the Y axis to see if an enemy is in the same row: if robot.y == self.y: print('Oh no! Danger, Will Robinson!!!') else: print('Super SAFE, Yeah!!!') substituted instead of the previous print code. See attached video to show correct detection. 2020-11-04 15-07-44.zip NOTE: This is the sort of dialogue that shows testing, for your final reports. See how I broke the problem down and showed evidence of progress at each stage.

DoctorMikeReddy commented 3 years ago

This code in mike-cavern-demo in cavern.py