Artificial intelligence in Lua

Discuss using and improving Lua and the Lua Player specific to the PSP.

Moderators: Shine, Insert_witty_name

Post Reply
cools
Posts: 46
Joined: Sat Mar 04, 2006 12:57 pm

Artificial intelligence in Lua

Post by cools »

I need some help with artificial intelligence in lua. I just need a simple script that will add a certain amount of money for the computer. The code for the player is done, i just need some AI for the computer. Now I'm not 100% sure if Lua has AI abilities, or if it'll end up being a whole bunch of math.random()'s...

Heres the code so far:

Code: Select all

black = Color.new(255,255,255)

playerMoney = 0

while true do

pad = Controls.read()

if pad:left() then
playerMoney = playerMoney+1
delay(1000)
end

if pad:right() then
playerMoney = playerMoney+5
delay(1000)
end

if pad:l() then
playerMoney = playerMoney+10
delay(1000)
end

if pad:r() then
playerMoney = playerMoney+50
delay(1000)
end

screen:clear(Color.new(0,0,0))

screen:print(200, 130, playerMoney, black)

screen.flip()
screen.waitVblankStart()

function delay( milli )
vs=math.floor(milli/60)
screen.waitVblankStart( vs )
end
end
JorDy
Posts: 121
Joined: Sun Dec 11, 2005 8:45 am

Post by JorDy »

what is the game/program for? what do you want the AI to do? i can probablly help
cools
Posts: 46
Joined: Sat Mar 04, 2006 12:57 pm

Post by cools »

Its for my monopoly clone. I just need the AI to compete with how much money the player has offered. It has to go up by 1,5,10, or 50. If you need any more info just ask
OCteam
Posts: 7
Joined: Sun Mar 05, 2006 11:12 pm
Location: UK
Contact:

Post by OCteam »

cools wrote:Its for my monopoly clone. I just need the AI to compete with how much money the player has offered. It has to go up by 1,5,10, or 50. If you need any more info just ask
AI is just a series of if statements that will intelligently process a given function. Just do it like you would anything else and ignore the term AI. Figure out the logic and then make it happen.
Last edited by OCteam on Mon Mar 06, 2006 11:38 am, edited 1 time in total.
PP121494863-PSP1001
www.illfoundedmind.com
cools
Posts: 46
Joined: Sat Mar 04, 2006 12:57 pm

Post by cools »

Thanks OCteam, it helps alot! ( otherwise I would've been doing a whole bunch of math.random()'s! )
OCteam
Posts: 7
Joined: Sun Mar 05, 2006 11:12 pm
Location: UK
Contact:

Post by OCteam »

cools wrote:Thanks OCteam, it helps alot! ( otherwise I would've been doing a whole bunch of math.random()'s! )
No problem -- you do want some random variables in there (just so the cpu's movements are not the same always) but worry about that after you get the basic functions down (it is easily to throw in a random statement). Good luck
PP121494863-PSP1001
www.illfoundedmind.com
Post Reply