Code:
/////////////segment of start up script //////////////

tile[0] = "noone"
tile[1] = "noone"
tile[2] = "noone"
tile[3] = "noone"
tile[4] = "noone"
tile[5] = "noone"
tile[6] = "noone"
tile[7] = "noone"
tile[8] = "noone"
tile[9] = "noone"
Code:
//////////////// scr_expert //////////////////

//Create an array to store how many dangerous squares can be created for the player
num_dan[1] = 0;
num_dan[2] = 0;
num_dan[3] = 0;
num_dan[4] = 0;
num_dan[5] = 0;
num_dan[6] = 0;
num_dan[7] = 0;
num_dan[8] = 0;
num_dan[9] = 0;

cwt = 0;
block = 0;

for(i = 1; i < 10; i += 1;) // check every square
{
    if tile[i] != "noone"  //if occupied then ignore it
    {   
        num_dan[i] = -1; 
        continue;
    }
    tile[i] = "computer"; 
        
    if script_execute(scr_win_check_com) == true // check computer winning here
    { 
        tile[i] = "noone";
        com_win_tile[cwt] = i;
        cwt += 1;
        num_dan[i] = -1;
        continue;
    }
    tile[i] = "noone";
        
    if script_execute(scr_block_check,i) == true //check computer having to block here
    {
        block = 1;
        num_dan[i] = -1;
        continue;
    }
        
    script_execute(scr_most_dan,i); // check all other moves
}

if (cwt) // Select random winning move if there is one
{
    rand = floor(random(cwt));
    script_execute(scr_com_take,com_win_tile[rand]);
    exit;
}

if (block) // Select blocking move if there is one
{
    script_execute(scr_com_take,block);
    exit;
}

most_dangerous = 0;
ttt = 0;

// Check the num_dan array to see which square choice leads to most dangerous squares for the player

for(i = 1; i < 10; i += 1;)
{
    if (num_dan[i] > most_dangerous)
    {
        most_dangerous = num_dan[i];
    }
}

// Check if there is more than one square creating the same number of dangerous squares
 
for(i = 1; i < 10; i += 1;)
{
    if (num_dan[i] == most_dangerous)
    {
        tile_choice[ttt] = i;
        ttt += 1;
    }
}

// randomly select the square leading to the most dangerous outcome.
 
rand = floor(random(ttt));
script_execute(scr_com_take,tile_choice[rand]);
Code:
///////////////// scr_win_check_com ////////////////


if tile[1] == "computer" && tile[2] == "computer" && tile[3] == "computer"
{
    return true;
    exit;
}

if tile[4] == "computer" && tile[5] == "computer" && tile[6] == "computer"
{
    return true;
    exit;
}
if tile[7] == "computer" && tile[8] == "computer" && tile[9] == "computer"
{
    return true;
    exit;
}
if tile[1] == "computer" && tile[4] == "computer" && tile[7] == "computer"
{
    return true;
    exit;
}
if tile[2] == "computer" && tile[5] == "computer" && tile[8] == "computer"
{
    return true;
    exit;
}
if tile[3] == "computer" && tile[6] == "computer" && tile[9] == "computer"
{
    return true;
    exit;
}
if tile[1] == "computer" && tile[5] == "computer" && tile[9] == "computer"
{
    return true;
    exit;
}
if tile[3] == "computer" && tile[5] == "computer" && tile[7] == "computer"
{
    return true;
    exit;
}
return false;
Code:
//////////////// scr_block_check /////////////////////
// check winning combinations that may involve the square in question...
// corners (1,3,7,9) have 3 combinations, sides(2,4,6,8) have 2, and centre(5) has 4.

tile_to_check = argument0;

if tile_to_check == 1
{
    if (tile[2] == "player" && tile[3] == "player")
    {
        return true;
        exit;
    }
    if (tile[4] == "player" && tile[7] == "player")
    {
        return true;
        exit;
    }
    if (tile[5] == "player" && tile[9] == "player")
    {
        return true;
        exit;
    }
}

// .... other square checks here... \\

return false;

Code:
//////////////// scr_most_dan ////////////////////

script_execute(scr_tt1_upd);
next_tile = argument0
test_tile_1[next_tile] = "computer"; 
script_execute(scr_com_wc_1,next_tile);

if wincha > 1
{
    //return true;
    num_dan[next_tile] = 10;
    exit;
}
else
if wincha == 1
{
    test_tile_1[win_chances[0]] = "player";
    script_execute(scr_pl_wc_1,win_chances[0]);
    if wincha > 1
    {
        num_dan[argument0] = -1;
        exit;
    }
    else
    if wincha == 1
    {
        test_tile_1[win_chances[0]] = "computer"
        script_execute(scr_com_wc_1,win_chances[0]);
        if wincha > 1
        {
            num_dan[argument0] = 10;
            exit;
        }
        else
        if wincha == 1
        {
            test_tile_1[win_chances[0]] = "player"
            script_execute(scr_pl_wc_1,win_chances[0]);
            if wincha > 1
            {
                num_dan[argument0] = -1;
                exit;
            }
            else
            if wincha == 1
            {
                test_tile_1[win_chances[0]] = "computer"
                script_execute(scr_com_wc_1,win_chances[0]);
                if wincha > 1
                {
                    num_dan[argument0] = 10;
                    exit;
                }
            }
            else
            if wincha == 0
            {
                script_execute(scr_com_mo_2,next_tile)
            }
        }
    }
    else
    if wincha == 0
    {
        script_execute(scr_com_mo_2,next_tile)
    }
}
else
if wincha == 0
{
    script_execute(scr_pl_mo_2,next_tile)
}

Code:
//////// scr_com_wc_1 ///////////////

tile_to_check = argument0;
wincha = 0;
if tile_to_check == 1
{
    if (test_tile_1[2] == "computer" && test_tile_1[3] == "noone") || (test_tile_1[3] == "computer" && test_tile_1[2] == "noone")
    {
        if test_tile_1[3] == "noone" then win_chances[wincha] = 3;
        if test_tile_1[2] == "noone" then win_chances[wincha] = 2;
        wincha += 1;
    }
    if (test_tile_1[4] == "computer" && test_tile_1[7] == "noone") || (test_tile_1[7] == "computer" && test_tile_1[4] == "noone")
    {
        if test_tile_1[4] == "noone" then win_chances[wincha] = 4;
        if test_tile_1[7] == "noone" then win_chances[wincha] = 7;
        wincha += 1;
    }
    if (test_tile_1[5] == "computer" && test_tile_1[9] == "noone") || (test_tile_1[9] == "computer" && test_tile_1[5] == "noone")
    {
        if test_tile_1[5] == "noone" then win_chances[wincha] = 5;
        if test_tile_1[9] == "noone" then win_chances[wincha] = 9;
        wincha += 1;
    }
}

//.... other squares to check here.....//

if wincha > 0
{
    return true;
    exit;
}
else
{
    return false;
    exit;
}
Code:
//////// scr_com_wc_2 ///////////////

tile_to_check = argument0;
wincha = 0;
if tile_to_check == 1
{
    if (test_tile_2[2] == "computer" && test_tile_2[3] == "noone") || (test_tile_2[3] == "computer" && test_tile_2[2] == "noone")
    {
        if test_tile_2[3] == "noone" then win_chances[wincha] = 3;
        if test_tile_2[2] == "noone" then win_chances[wincha] = 2;
        wincha += 1;
    }
    if (test_tile_2[4] == "computer" && test_tile_2[7] == "noone") || (test_tile_2[7] == "computer" && test_tile_2[4] == "noone")
    {
        if test_tile_2[4] == "noone" then win_chances[wincha] = 4;
        if test_tile_2[7] == "noone" then win_chances[wincha] = 7;
        wincha += 1;
    }
    if (test_tile_2[5] == "computer" && test_tile_2[9] == "noone") || (test_tile_2[9] == "computer" && test_tile_2[5] == "noone")
    {
        if test_tile_2[5] == "noone" then win_chances[wincha] = 5;
        if test_tile_2[9] == "noone" then win_chances[wincha] = 9;
        wincha += 1;
    }
}


//.... other squares to check here.....//

if wincha > 0
{
    return true;
    exit;
}
else
{
    return false;
    exit;
}

Code:
//////// scr_com_wc_3 ///////////////

tile_to_check = argument0;
wincha = 0;
if tile_to_check == 1
{
    if (test_tile_3[2] == "computer" && test_tile_3[3] == "noone") || (test_tile_3[3] == "computer" && test_tile_3[2] == "noone")
    {
        if test_tile_3[3] == "noone" then win_chances[wincha] = 3;
        if test_tile_3[2] == "noone" then win_chances[wincha] = 2;
        wincha += 1;
    }
    if (test_tile_3[4] == "computer" && test_tile_3[7] == "noone") || (test_tile_3[7] == "computer" && test_tile_3[4] == "noone")
    {
        if test_tile_3[4] == "noone" then win_chances[wincha] = 4;
        if test_tile_3[7] == "noone" then win_chances[wincha] = 7;
        wincha += 1;
    }
    if (test_tile_3[5] == "computer" && test_tile_3[9] == "noone") || (test_tile_3[9] == "computer" && test_tile_3[5] == "noone")
    {
        if test_tile_3[5] == "noone" then win_chances[wincha] = 5;
        if test_tile_3[9] == "noone" then win_chances[wincha] = 9;
        wincha += 1;
    }
}

//.... other squares to check here.....//

if wincha > 0
{
    return true;
    exit;
}
else
{
    return false;
    exit;
}
Code:
//////// scr_com_wc_4 ///////////////

tile_to_check = argument0;
wincha = 0;
if tile_to_check == 1
{
    if (test_tile_4[2] == "computer" && test_tile_4[3] == "noone") || (test_tile_4[3] == "computer" && test_tile_4[2] == "noone")
    {
        if test_tile_4[3] == "noone" then win_chances[wincha] = 3;
        if test_tile_4[2] == "noone" then win_chances[wincha] = 2;
        wincha += 1;
    }
    if (test_tile_4[4] == "computer" && test_tile_4[7] == "noone") || (test_tile_4[7] == "computer" && test_tile_4[4] == "noone")
    {
        if test_tile_4[4] == "noone" then win_chances[wincha] = 4;
        if test_tile_4[7] == "noone" then win_chances[wincha] = 7;
        wincha += 1;
    }
    if (test_tile_4[5] == "computer" && test_tile_4[9] == "noone") || (test_tile_4[9] == "computer" && test_tile_4[5] == "noone")
    {
        if test_tile_4[5] == "noone" then win_chances[wincha] = 5;
        if test_tile_4[9] == "noone" then win_chances[wincha] = 9;
        wincha += 1;
    }
}

//.... other squares to check here.....//

if wincha > 0
{
    return true;
    exit;
}
else
{
    return false;
    exit;
}
Code:
//////////////// scr_pl_wc_1 ////////////////////

tile_to_check = argument0;
wincha = 0;
if tile_to_check == 1
{
    if (test_tile_1[2] == "player" && test_tile_1[3] == "noone") || (test_tile_1[3] == "player" && test_tile_1[2] == "noone")
    {
        if test_tile_1[3] == "noone" then win_chances[wincha] = 3;
        if test_tile_1[2] == "noone" then win_chances[wincha] = 2;
        wincha += 1;
    }
    if (test_tile_1[4] == "player" && test_tile_1[7] == "noone") || (test_tile_1[7] == "player" && test_tile_1[4] == "noone")
    {
        if test_tile_1[4] == "noone" then win_chances[wincha] = 4;
        if test_tile_1[7] == "noone" then win_chances[wincha] = 7;
        wincha += 1;
    }
    if (test_tile_1[5] == "player" && test_tile_1[9] == "noone") || (test_tile_1[9] == "player" && test_tile_1[5] == "noone")
    {
        if test_tile_1[5] == "noone" then win_chances[wincha] = 5;
        if test_tile_1[9] == "noone" then win_chances[wincha] = 9;
        wincha += 1;
    }
}

//.... other squares to check here.....//

if wincha > 0
{
    return true;
    exit;
}
else
{
    return false;
    exit;
}
Code:
///////////// scr_pl_wc_2 ////////////////

tile_to_check = argument0;
wincha = 0;
if tile_to_check == 1
{
    if (test_tile_2[2] == "player" && test_tile_2[3] == "noone") || (test_tile_2[3] == "player" && test_tile_2[2] == "noone")
    {
        if test_tile_2[3] == "noone" then win_chances[wincha] = 3;
        if test_tile_2[2] == "noone" then win_chances[wincha] = 2;
        wincha += 1;
    }
    if (test_tile_2[4] == "player" && test_tile_2[7] == "noone") || (test_tile_2[7] == "player" && test_tile_2[4] == "noone")
    {
        if test_tile_2[4] == "noone" then win_chances[wincha] = 4;
        if test_tile_2[7] == "noone" then win_chances[wincha] = 7;
        wincha += 1;
    }
    if (test_tile_2[5] == "player" && test_tile_2[9] == "noone") || (test_tile_2[9] == "player" && test_tile_2[5] == "noone")
    {
        if test_tile_2[5] == "noone" then win_chances[wincha] = 5;
        if test_tile_2[9] == "noone" then win_chances[wincha] = 9;
        wincha += 1;
    }
}
//.... other squares to check here.....//

if wincha > 0
{
    return true;
    exit;
}
else
{
    return false;
    exit;
}
Code:
//////////// scr_pl_wc_3 ///////////////////

tile_to_check = argument0;
wincha = 0;
if tile_to_check == 1
{
    if (test_tile_3[2] == "player" && test_tile_3[3] == "noone") || (test_tile_3[3] == "player" && test_tile_3[2] == "noone")
    {
        if test_tile_3[3] == "noone" then win_chances[wincha] = 3;
        if test_tile_3[2] == "noone" then win_chances[wincha] = 2;
        wincha += 1;
    }
    if (test_tile_3[4] == "player" && test_tile_3[7] == "noone") || (test_tile_3[7] == "player" && test_tile_3[4] == "noone")
    {
        if test_tile_3[4] == "noone" then win_chances[wincha] = 4;
        if test_tile_3[7] == "noone" then win_chances[wincha] = 7;
        wincha += 1;
    }
    if (test_tile_3[5] == "player" && test_tile_3[9] == "noone") || (test_tile_3[9] == "player" && test_tile_3[5] == "noone")
    {
        if test_tile_3[5] == "noone" then win_chances[wincha] = 5;
        if test_tile_3[9] == "noone" then win_chances[wincha] = 9;
        wincha += 1;
    }
}

//.... other squares to check here.....//

if wincha > 0
{
    return true;
    exit;
}
else
{
    return false;
    exit;
}
Code:
////////////// scr_pl_mo_2 ////////////////
 
   for(ii = 1; ii < 10; ii += 1;)
{
    script_execute(scr_tt2_upd); 
    if test_tile_2[ii] == "noone"
    {
        test_tile_2[ii] = "player";
        script_execute(scr_pl_wc_2,ii);
        if wincha > 1
        {
            num_dan[argument0] = -1;
            exit;
        }
        else
        if wincha == 1
        {
            test_tile_2[win_chances[0]] = "computer"
            script_execute(scr_com_wc_2,win_chances[0]);  
            if wincha > 1
            {
                num_dan[argument0] += 1;
                continue;
            }
            else
            if wincha == 1
            {
                test_tile_2[win_chances[0]] = "player"
                script_execute(scr_pl_wc_2,win_chances[0]);
                if wincha > 1
                {
                    num_dan[argument0] = -1;
                    exit;
                }
                else
                if wincha == 1
                {
                    test_tile_2[win_chances[0]] = "computer"
                    script_execute(scr_com_wc_2,win_chances[0]);
                    if wincha == 1
                    {
                        test_tile_2[win_chances[0]] = "player"
                        script_execute(scr_pl_wc_2,win_chances[0]);
                        if wincha > 1
                        {
                            num_dan[argument0] = -1;
                            exit;
                        }
                    }
                }
            }
            else
            if wincha == 0
            {
                if script_execute(scr_pl_mo_3) == false
                {
                    num_dan[argument0] = -1;
                    exit;
                }
            }
        }
        else
        if wincha == 0
        {
            if script_execute(scr_com_mo_3) == true
            {
                num_dan[argument0] += 1;
                continue;
            }
        }
    }
}
Code:
///////////// scr_pl_mo_3 //////////////

for(iii = 1; iii < 10; iii += 1;)
{
    script_execute(scr_tt3_upd);
    if test_tile_3[iii] == "noone"
    {
        test_tile_3[iii] = "player";
        script_execute(scr_pl_wc_3,iii);
        if wincha > 1
        {
            return false;
            exit;
        }
        else
        if wincha == 1
        {
            test_tile_3[win_chances[0]] = "computer"
            script_execute(scr_com_wc_3,win_chances[0]);  
            if wincha == 1
            {
                test_tile_3[win_chances[0]] = "player"
                script_execute(scr_pl_wc_3,win_chances[0]);
                if wincha > 1
                {
                    return false;
                    exit;
                }
                else
                if wincha == 1
                {
                    test_tile_3[win_chances[0]] = "computer"
                    script_execute(scr_com_wc_3,win_chances[0]);
                    if wincha == 1
                    {
                        test_tile_3[win_chances[0]] = "player"
                        script_execute(scr_pl_wc_3,win_chances[0]);
                        if wincha > 1
                        {
                            return false;
                            exit;
                        }
                    }
                }
            }
            else
            if wincha == 0
            {
                if script_execute(scr_mo_4) == true
                {
                    return true;
                    exit;
                }
            }
        }
    }
}
return true;
Code:
//////////////// scr_com_mo_2 //////////////////

for(ii = 1; ii < 10; ii += 1;)
{
    script_execute(scr_tt2_upd);
    if test_tile_2[ii] == "noone"
    {
        test_tile_2[ii] = "computer";
        script_execute(scr_com_wc_2,ii);
        if wincha > 1
        {
            num_dan[argument0] = 10;
            exit;
        }
        else
        if wincha == 1
        {
            test_tile_2[win_chances[0]] = "player"
            script_execute(scr_pl_wc_2,win_chances[0]);  
            if wincha == 1
            {
                test_tile_2[win_chances[0]] = "computer"
                script_execute(scr_com_wc_2,win_chances[0]);
                if wincha > 1
                {
                    num_dan[argument0] = 10;
                    exit;
                }
            }
            else
            if wincha == 0
            {
                if script_execute(scr_com_mo_3) == true
                {
                    num_dan[argument0] = 10;
                    exit;
                }
            }
        }
    }
}
//nd = 0;
//return false;
Code:
//////////////// scr_pl_mo_3 ///////////////////

for(iii = 1; iii < 10; iii += 1;)
{
    script_execute(scr_tt3_upd);
    if test_tile_3[iii] == "noone"
    {
        test_tile_3[iii] = "computer";
        script_execute(scr_com_wc_3,iii);
        if wincha > 1
        {
            return true;
            exit;
        }
        else
        if wincha == 1
        {
            test_tile_3[win_chances[0]] = "player"
            script_execute(scr_pl_wc_3,win_chances[0]);  
            if wincha == 1
            {
                test_tile_3[win_chances[0]] = "computer"
                script_execute(scr_com_wc_3,win_chances[0]);
                if wincha > 1
                {
                    return true;
                    exit;
                }
                else
                if wincha == 1
                {
                    test_tile_3[win_chances[0]] = "player"
                    script_execute(scr_pl_wc_3,win_chances[0]);
                    //if wincha > 1
                   // {
                    //    return false;
                   //     exit;
                   // }
                    //else
                    if wincha == 1
                    {
                        test_tile_3[win_chances[0]] = "computer"
                        script_execute(scr_com_wc_3,win_chances[0]);
                        if wincha > 1
                        {
                            return true;
                            exit;
                        }
                    }
                }
            }
            else
            if wincha == 0
            {
                if script_execute(scr_mo_4) == true
                {
                    return true;
                    exit;
                }
            }
        }
    }
}
nd = 0;
return false;
Code:
//////////// scr_mo_4 ////////////////

for(iiii = 1; iiii < 10; iiii += 1;)
{
    script_execute(scr_tt4_upd);
    if test_tile_4[iiii] == "noone"
    {
        test_tile_4[iiii] = "computer";
        script_execute(scr_com_wc_4,iiii);
        if wincha > 1
        {
            return true;
            exit;
        }
    }
}
return false;
Code:
///////// scr_tt1upd /////////////

for(tt_1 = 1; tt_1 < 10; tt_1 += 1;)
{
    test_tile_1[tt_1] = tile[tt_1]
}

////////// scr_tt2upd /////////////
for(tt_2 = 1; tt_2 < 10; tt_2 += 1;)
{
    test_tile_2[tt_2] = test_tile_1[tt_2]
}

////////// scr_tt3upd ////////////////

for(tt_3 = 1; tt_3 < 10; tt_3 += 1;)
{
    test_tile_3[tt_3] = test_tile_2[tt_3]
}

/////////// scr_tt4upd //////////////

for(tt_4 = 1; tt_4 < 10; tt_4 += 1;)
{
    test_tile_4[tt_4] = test_tile_3[tt_4]
}