I’m trying to make an AI, but its not working well.
its supposed to have a turn where it attempts to play the game.
heres the code for the frame:
//Function Block
wait = function (displayTime) {
timer = setInterval(wait, 1000);
displayTime--;
if (displayTime == 0) {
clearInterval(timer);
return 1;
}
};
contains = function (input, arrayData) {
for (i=0; i<arrayData.length; i++) {
if (arrayData* == input) {
return 1;
}
}
return -1;
};
index = function (input, arrayData) {
for (n=0; n<arrayData.length; n++) {
if (arrayData[n] == input) {
return n;
}
}
};
//Setup Block
score;
compscore;
_root.Match = "none";
_root.LastMatch = "none";
turn = "player";
Stage.showMenu = false;
CardBlue1.useHandCursor = false;
CardBlue2.useHandCursor = false;
CardRed1.useHandCursor = false;
CardRed2.useHandCursor = false;
CardGreen1.useHandCursor = false;
CardGreen2.useHandCursor = false;
CardYellow1.useHandCursor = false;
CardYellow2.useHandCursor = false;
//Shuffle Block
Card = new Array(_root.CardBlue1, _root.CardBlue2, _root.CardRed1, _root.CardRed2, _root.CardGreen1, _root.CardGreen2, _root.CardYellow1, _root.CardYellow2);
shuffle = random(7);
Card[shuffle]._x = 120;
Card[shuffle]._y = 130;
Card.push(Card[shuffle]);
Card.splice(shuffle, 1);
shuffle = random(6);
Card[shuffle]._x = 320;
Card[shuffle]._y = 130;
Card.push(Card[shuffle]);
Card.splice(shuffle, 1);
shuffle = random(5);
Card[shuffle]._x = 520;
Card[shuffle]._y = 130;
Card.push(Card[shuffle]);
Card.splice(shuffle, 1);
shuffle = random(4);
Card[shuffle]._x = 720;
Card[shuffle]._y = 130;
Card.push(Card[shuffle]);
Card.splice(shuffle, 1);
shuffle = random(3);
Card[shuffle]._x = 120;
Card[shuffle]._y = 340;
Card.push(Card[shuffle]);
Card.splice(shuffle, 1);
shuffle = random(2);
Card[shuffle]._x = 320;
Card[shuffle]._y = 340;
Card.push(Card[shuffle]);
Card.splice(shuffle, 1);
shuffle = random(1);
Card[shuffle]._x = 520;
Card[shuffle]._y = 340;
Card.push(Card[shuffle]);
Card.splice(shuffle, 1);
shuffle = random(0);
Card[shuffle]._x = 720;
Card[shuffle]._y = 340;
Card.push(Card[shuffle]);
Card.splice(shuffle, 1);
//AI Block
Memory = ["none"];
if (turn == "computer") {
pick = random(7);
if (Card[pick].matched != true) {
Card[pick].gotoAndStop(2);
_root.Match = Card[pick].colour;
_root.LastMatch = Card[pick];
if (wait(1) == 1)
if (contains(Card[pick].matchy, Memory) == 1) {
chance = random(100);
if (chance<((100-10)-index(Card[pick].matchy, Memory))) {
Card[pick].matched = true;
Card[pick].matchy.matched = true;
Card[pick].gotoAndPlay(3);
Card[pick].matchy.gotoAndPlay(3);
compscore += 1;
} else {
picky = Card[random(7)];
if (picky.matched != true) {
if (Card[pick].matchy == picky) {
Card[pick].matched = true;
Card[pick].matchy.matched = true;
Card[pick].gotoAndPlay(3);
Card[pick].matchy.gotoAndPlay(3);
compscore += 1;
} else {
Card[pick].gotoAndPlay(8);
picky.gotoAndPlay(8);
turn = "player";
}
}
}
}
}
}
//Player Turn Block
Playercardnumber = 7;
if (turn == "player") {
while (Playercardnumber>=0) {
if (Card[Playercardnumber].matched == false) {
Card[Playercardnumber] = enabled;
Playercardnumber -= 1;
} else {
Playercardnumber -= 1;
}
}
}
and for the cards:
onClipEvent (load) {
stop();
var colour = "green";
var matchy = _root.CardGreen2;
var matched = false;
}
on (release) {
Memory.splice(index(this, Memory), 1);
Memory.unshift(_root.CardGreen1);
if (_root.Match == "Green") {
this.gotoAndPlay(3);
_root.CardGreen2.gotoAndPlay(3);
_root.Match = "none";
_root.Score += 1;
this.enabled = false;
this.matched = true;
_root.CardGreen2.enabled = false;
_root.CardGreen2.matched = true;
} else {
if (_root.Match != "none") {
gotoAndPlay(8);
_root.LastMatch.gotoAndPlay(8);
_root.Match = "none";
this.enabled = true;
_root.LastMatch.enabled = true;
_root.LastMatch = "none";
turn = "computer";
} else {
gotoAndStop(2);
_root.Match = "Green";
_root.LastMatch = this;
this.enabled = false;
}
}
}
I think this is in AS 2, but it could be 1