# Simple AI review-optimization

2 replies to this topic

### #1 roa

roa

GMC Member

• New Member
• 96 posts

Posted 18 May 2012 - 02:59 AM

I have been working on a game and slapped some script together. Its a maze game/ pac-man clone but this is the AI for the "ghost". Im trying my best to make it resemble the AI of the original pac-man and I was in thought if anyone here knew a way to clean it up? I been kinda sick and my thought process is stressed, it would be sweet if I could get some tips from the community. It works 100% I know about the self. and using Var instead of variableA=0
//resets veriables
wall_check_right=0
wall_check_left=0
wall_check_up=0
wall_check_down=0
dound_mid=0
right_dist=0
left_dist=0
up_dist=0
down_dist=0
//rules out prior direction
if direction=180 then wall_check_right=1
if direction=0then wall_check_left=1
if direction=270then wall_check_up=1
if direction=90 then wall_check_down=1

//find where walls are

if position_meeting(x+32,y+16,wall) then wall_check_right=1
if position_meeting(x-32,y+16,wall) then wall_check_left=1
if position_meeting(x+16,y-32,wall) then wall_check_up=1
if position_meeting(x+16,y+32,wall) then wall_check_down=1
// now all possable paths are found- take remainder paths and find which is closest to target vector (for now player)

//finds values of directions + if not a valid direction, makes sure not an optional min
if wall_check_right =0 then
{right_dist=point_distance(self.x+32,self.y,player.x,player.y)}else {right_dist=10003}
if wall_check_left =0 then
{left_dist=point_distance(self.x-32,self.y,player.x,player.y)}else {left_dist=10002}
if wall_check_up =0 then
{up_dist=point_distance(self.x,self.y-32,player.x,player.y)}else {up_dist=10001}
if wall_check_down =0then
{down_dist=point_distance(self.x,self.y+32,player.x,player.y)}else {down_dist=10000}
//finds lowest distance
found_min=min(right_dist,left_dist,up_dist,down_dist)
//finds which value was min and returns to variable rather then integer then decides direction
if right_dist=found_min then direction=0
if left_dist=found_min then direction=180
if up_dist=found_min then direction=90
if down_dist=found_min then direction=270
//notes* getting the npc into a cornered position will take on errors or be forced into order of operation conflicts- no longer a conflict

any help would be great
It also takes place in step under a D&D check aligned by 32x32 with all variables in initiated in create event

Edited by roa, 18 May 2012 - 03:02 AM.

• 0

### #2 Nocturne

Nocturne

Nocturne Games

• 16792 posts
• Version:GM:Studio

Posted 18 May 2012 - 09:00 AM

This question does not follow the Advanced Section Rules. Please post in the correct forum in future.
• 0

### #3 roa

roa

GMC Member

• New Member
• 96 posts

Posted 19 May 2012 - 12:47 AM

This question does not follow the Advanced Section Rules. Please post in the correct forum in future.

How may I go about finding this post else where on the site now that its moved? I hadn't noticed the rules of asking for optimization. I figured it would have been kicked from novice on grounds of asking for gml variants being to demanding for such a forum?- I will check the rules out again...
• 0

#### 0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users