Tic Tac Toe
A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Tic Tac Toe

  1. #1
    Registered User
    Join Date
    Dec 2016
    Posts
    1

    Tic Tac Toe

    I want to know about the algorithm use in tic tac toe.
    I am not talking about minimax algorithm but i want to know about winner decision logic.
    When we compare a specific sign of "X" or "O" by row wise, column wise or diagonal wise is it breadth first search or depth first search or any other algorithm that we used or its just a simple logic.
    i have tried but not get answer every one talking about minimax.

    Thanks in advance.

  2. #2
    Tim (Super Moderator) Northcode's Avatar
    Join Date
    Dec 2000
    Location
    Whitehorse YT
    Posts
    3,746
    There are only 8 ways to win a game, by getting 3 of the same markers in any of 3 vertical, 3 horizontal or 2 diagonal rows. That means you just need 8 if statements to check to see if the game has been won, you don't need any more complicated algorithm than that. If you're talking about a strategic algorithm for playing the game, there are plenty of resources out there and none of them are very complicated.
    When your swf2exe tool just HAS to work
    there's only one choice... SWF Studio

  3. #3
    Senior Member
    Join Date
    Apr 2011
    Posts
    742
    along with what northcode said in terms of the 8 ways to win you should also store 1 variable, one that will store your next winning move, and than when its the ai's turn you give it a 50/50 chance to block your winning move or move somewhere random,

    id store all the moves in an array like this

    var game_slots={
    slot1:[0,0,0],
    slot2:[0,0,0],
    slot3:[0,0,0]
    };

    and when you make you make a move on 3,3, slot 3 would look like

    var game_slots={
    slot1:[0,0,0],
    slot2:[0,0,0],
    slot3:[0,0,1]
    };

    and when the ai makes a move you can store its flag as a 2 since yours is a 1 lets say it made a move on 1,1 it would look like this

    var game_slots={
    slot1:[2,0,0],
    slot2:[0,0,0],
    slot3:[0,0,1]
    };
    Last edited by Alloy Bacon; 01-04-2017 at 04:16 PM.
    remote controlled cpu

  4. #4
    Member
    Join Date
    Oct 2016
    Posts
    42
    mornings alloy, you seem to no what you say about, can you please make the game so i can learn from you coding, thank in advance.
    before you maske i think you make confused with things,

    var game_slots = {slot1:[1, 2, 3], slot2:[4, 5, 6], slot3:[7, 8, 9]};
    trace(game_slots.slot1[0]);

    i not know how do but you gonna be mixed with yours

  5. #5
    Member
    Join Date
    Oct 2016
    Posts
    42
    it can get confusing after a while for me, how you do alloy

    PHP Code:
    var game_slots = [["0"" ""0"], ["X""0""0"], ["X""X""X"]];
    // " " = unused
    // "X" = x piece
    // "0" = 0 piece
    /*
    trace(game_slots[0]);
    trace(game_slots[1]);
    trace(game_slots[2]);

    trace(game_slots[0][0]);
    trace(game_slots[1][0]);
    trace(game_slots[2][0]);
    */


    for (var i:Number 0game_slots.lengthi++)
    {
        
    trace("Game slot " " : " game_slots[i]);
        for (var 
    j:Number 0game_slots[i].lengthj++)
        {
            if (
    game_slots[i][j] == "X")
            {
                
    //trace(game_slots[i][i]);
            
    }
        }

    then you have inouts to deal along too

  6. #6
    Senior Member realMakc's Avatar
    Join Date
    Oct 2002
    Posts
    877
    here is ready tic tac toe game to "learn" from. if ya ain't afraid of moonspeak.
    who is this? a word of friendly advice: FFS stop using AS2

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center

Poll by Flashkit.com