saveing moves

This is a discussion on saveing moves within the C++ Programming forums, part of the General Programming Boards category; I was wondering how to save a move (from the tic tac toe game) to a specific area in an ...

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    73

    saveing moves

    I was wondering how to save a move (from the tic tac toe game) to a specific area in an array. For example when the player makes his first move i want to store the number of the square that he chose in the array moves[0] (while moves[9] has goes from 0-9) and so on like that? Any suggestions? Understand the question?

  2. #2
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    enum tictac { player1, player2, empty };

    tictac board[9] = { empty };


    //...

    if (it_is_player_1s_ turn())
    {
    board[move] = player1;
    } else if (it_is_player_2s_turn()) {
    board[move] = player2;
    }


    Understand?

  3. #3
    Registered User
    Join Date
    Oct 2002
    Posts
    73
    I think I do. R u saying make two arrays. One for the players and one for the board, and then say that if it is player1s turn then use the board array (for the first move it would be board[0]) to equal player1. Witch mean it would be player1's turn. If not then do the same for player two. Right? But do i actually write "empty" in the board array when i delcare it?

  4. #4
    Registered User
    Join Date
    Oct 2002
    Posts
    73
    O and what exactly is enum? We never talked about it in class and theres not much about it in my book. All it says is its a way to declare simple data types. But what exactly is it used for?

  5. #5
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    enum is an enumerative type, it's just a new data type. The one we declare tictac is basically an int, which can hold the values 0, 1 or 2.

    Kinda like a bool, but with 3 different values.
    If I have a bool variable, I can go

    bool myBool = false;
    or
    bool myBool = 0;
    The two expressions are exactly the same!

    Likewise, for our enum tictac, I can go

    tictac myTicTac = player1;
    or
    tictac myTicTac = 0;

    If I wanted to declare my own boolean data type, I could go
    enum boolean { TRUE, FALSE };

    Get it? So basically we have a tictac array, which is empty. Each time a player moves, we find the correct position in our tictac array and set it equal to the moving player.
    Last edited by Eibro; 10-13-2002 at 10:15 PM.

  6. #6
    Registered User
    Join Date
    Oct 2002
    Posts
    73
    Ok I get that. I know how to set the moves to the two differant players. But what I dont get is how I can save the moves so that I can recall them later on to check to see who won. Unless what your telling me will do that and Im juz not getting it, any suggestions?

  7. #7
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    Just set up an algorithm which will loop through your tictac array and check for wins. Three in a row is all you need. So if board[0] && board[1] && board[2] are all equal to the same player, they have won.

  8. #8
    Registered User
    Join Date
    Oct 2002
    Posts
    73
    I tried that exact method, but it only detects a win if squre 1,2,3 are taken in that order. Any suggesitons?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Forced moves trouble!!
    By Zishaan in forum Game Programming
    Replies: 0
    Last Post: 03-27-2007, 07:57 PM
  2. Jump moves in Checkers Game
    By Reb0270 in forum C++ Programming
    Replies: 2
    Last Post: 04-08-2004, 02:06 PM
  3. Save files move when folder moves
    By mill1k in forum C++ Programming
    Replies: 5
    Last Post: 04-03-2004, 04:35 PM
  4. How do I pop off only the unwanted moves?
    By doampofo in forum C++ Programming
    Replies: 1
    Last Post: 04-25-2003, 10:55 PM
  5. Total moves
    By awkeller in forum C Programming
    Replies: 3
    Last Post: 11-26-2001, 11:24 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21