artificial intelligence - AI in javascript -
i'm developping simple game , i'm trying program ai using javascript.
function ai() { ammotrue = 0; ammofalse = 0; if (round == 1) { aiammunition(); } if (aiammo == "true" && round > 1) { //or gun or shield ammotrue = math.floor((math.random() * 2) + 1); if (ammotrue == 1) { aishoot(); } if (ammotrue == 2) { aiprotect(); } } if (aiammo == "false" && round > 1) { //or ammo or shield ammofalse = math.floor((math.random() * 2) + 1); if (ammofalse == 1) { aiammunition(); } if (ammofalse == 2) { aiprotect(); } } }
explanation :
in first round, want function aiammunition()
executed. works.
after rounds after first one, want test if aiammo
true or false.
if aiammo
true, want randomly execute aishoot
or aiprotect
.
if aiammo
false, want randomly execute aiammunition
or aiprotect
.
i later have reset function resetting aishoot
, aiprotect
after each round, there can 1 of being true.
in first rounds (like 1 3), code seems work, after that, aishoot
, aiprotect
seem both true, can read in console (i made clear debug).
here link codepen, can check out : http://codepen.io/ninivert/pen/vlmjql
thanks.
Comments
Post a Comment