TicTacToe

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • 1051109210
    New Member
    • Mar 2007
    • 29

    TicTacToe

    Im tryin to create a tic tac toe ( more then 3x3 but startin with 3x3) with ai. the prob is gettin the ai to work. many eg of 3x3 are out there but they seem to be done based on if this then do this. i kinda want a recursive function cause if else hard to be implemented on a bigger tic tac toe board.
    i think i figured out part of the ai.
    human is X comp is O
    first if O can place a winnin spot it will else
    O to see if X is winnin and block else *
    place randomly

    * this is my prob in finding out how to know if the human has already two in a row and is goin to win unless there is a block
  • RamananKalirajan
    Contributor
    • Mar 2008
    • 608

    #2
    Hi how are you going to start the application, either in table or in div ? If u are starting in table with images means it will be some what easier to calculate what you have asked...

    Regards
    Ramanan Kalirajan

    Comment

    • Dormilich
      Recognized Expert Expert
      • Aug 2008
      • 8694

      #3
      what puzzles me more is, how do you want to implement the AI? using such programmes I'd rather used Java or Flash for implementation. ....

      and of the two-in-a-row problem, you could use ID comparison (given you have named the IDs sensibly*)

      regards

      * like "f11" for first row, first field (so you can use the numbers to address a specific field) - I once did that for a Javascript Check Board to validate the moves

      Comment

      • 1051109210
        New Member
        • Mar 2007
        • 29

        #4
        im using...uh div i guess...actuall y this is done in google gadgets so its sumthin like div....



        yea my board is labeled sumthin like b00 b01 b02 b10 b11 b12 so forth...so how do i continue on from here...with uh that id comparison?

        Comment

        • Dormilich
          Recognized Expert Expert
          • Aug 2008
          • 8694

          #5
          get the numbers out of the ID and you can do any math you like with it (e.g. using it as array index so you can loop through rows, columns and diagonals)

          Comment

          • 1051109210
            New Member
            • Mar 2007
            • 29

            #6
            ooo huh? got lost there? possible to elaborate? tq

            Comment

            • acoder
              Recognized Expert MVP
              • Nov 2006
              • 16032

              #7
              If the IDs are "b00", "b01", etc. you can take the numbers out of the string (which is basically what an ID is) and then use it to index a multi-dimensional array, e.g.
              Code:
              var index1 = id.charAt(1);
              var index2 = id.charAt(2);
              anArray[index1][index2]

              Comment

              Working...