Updating Strings

I need help in updating a string variable:

the code is for a tictactoe game. The variable player_0/1 tracks a nine bit pattern (as a string) for each player. The variable pattern returns the current move pattern for the move.

for eg:
| |
X | |
------------ | ------------ | ------------
| |
------------| ------------ | ------------
| |

an x in the position above would generate a pattern of 100000000.

now the problem what should be the code to update the respective patterns of players to get the pattern for each player to reflect the position of moves made by each player so far.

all data is stored as a string.

the code below in stored in a movie clip called piece.
piece forms buttons on the screen that allow a move to be made
on clicking the button transfers control to position on the mc timeline to show a x or O as per the variable chance. and then calls the code below.

chance =0 -------> o
chance =1 ---------> 1

got really frustrated on this one line of code, so please help me.

The code for flash 5 is below:

tellTarget ("/flash"+/:chance) {
gotoAndPlay (1);
}
this_pos = substring(name, 5, 1);
trace (this_pos);
pattern = eval("/:player
"+/:chance);
pattern = substring(pattern,1,this_pos-1) +“1” + substring(pattern,this_pos+1,5-this_pos);
if (/:chance == 0) {
/:player_0 = ???;
} else {
/:player_1 = ???;
}
trace (“pattern:”);
trace (pattern);
trace (“players:”);
trace (/:player_0);
trace (/:player_1);
haswon = 0;
i = 1;
while (i<=8 and haswon == 0) {
j = 1;
hasmatch = 1;
thewin = eval("/:win"+i);
// trace(“thewin :”)
// trace (thewin);
// trace ("--------------");
while (j<=9 and hasmatch == 1) {
// trace (j);
if (substring(thewin,j,i)==“1” and substring (pattern,j,1)==“0”) {
hasmatch = 0;
}
j++;
}
if (hasmatch == 1) {
haswon = 1;
}
i++;
}
/:no_moves = /:no_moves+1;
if (haswon == 1) {
trace (“move fail”);
call (“win”);
} else if (/:no_moves == 9) {
call (“draw”);
} else {
/:chance = ((/:chance-1)*(-1));
tellTarget ("/") {
trace (“move success”);
gotoAndPlay (“go”);
}
}
:sigh:

That’s alot of unnecesary code man… I dunno… I feel the need to help you out by giving you an easier alternative to making a tic-tac-toe game…

2d Arrays :beam:

–|--|–

–|--|–

–|--|–

Where the doube dashes are the actual playing field… You can say that to get a certain location on the field…

tile[x][y] = position.
tile.state = whether it has an o or x on it… or is empty

You can then use these simple status checks to determine where a computer ai will place it’s next move and it will also make a rela life game alot easier to code for you :slight_smile:

2-d arrays is the most obvious solution ro designing a tic-tac-toe game.
i tried using strings just for the heck of it coz 2-d arrays was a bit to easy.

thanx anyway