Thread: Can't think of a way to do it!

  1. #16
    The larch
    Join Date
    May 2006
    Posts
    3,573
    This needs serious rethinking.

    What possible good can you get from a Player being able to return the n-th piece they have?

    And you still have malloc in there...

    You probably shouldn't be writing any code for graphics at this point. Develop the logic part, so it works in a console window, and then replace user input and rendering. (That is, if the graphical aspect is not more important to you. In which case a sufficient AI could be one that can make a random but legal move.)

  2. #17
    Registered User
    Join Date
    Mar 2007
    Posts
    37
    well i have most of my logic workin, it makes legal moves, tells you if there is forced moves or not, but im afraid to show it to you now....

    i originally thought of putting it in a move class but didnt, but if i did i think it would have been so much less coding.

    my graphics are done, in basic terms.

    I totally get what you mean where there is no point to using index for a draught. Is there anyway i could make a constructer where its uses the index of the square and identifies that draught that is on it. earlier u mention creating a bool sayign wheter a draught is on the square or or not, that makes snese, and when it is taken, the bool vlaue is set to false?? see, i can pseudocode this stuff, but when it comes to doing it, i get lost :-(

    I took malloc out in board, but i got a few errors, wanted to ask you bout them.. and if u don't mind, if u could explain how new and delete work for the draught bit ?

    For the A.I if i was able to make a computer to make alegal move, i would jump to the moon, i can even think of how to approach that. All i can think of is creating a vector of possible moves and then using the random algorith to filter through moves, and picking one, thats sound difficult to me...

  3. #18
    The larch
    Join Date
    May 2006
    Posts
    3,573
    As far as memory management goes, malloc-s and free's should be replaced so:
    Code:
    void Player::init(int n)
    {
    	draughts = new Draught[n]; //n new Draughts
    
    	n_draughts = n;
    }
    
    Player::~Player()
    {
    
    	delete [] draughts; //free dynamic array of draughts
    
    }
    As to your design, I'm in no place to help you there, particularly without seeing the code. If your pieces are indexed, then probably each of them contains fields with their coordinates? (But this is duplicate data, because the position of the piece in the grid would already tell you that. I've found that whenever I have redundant data like that to take care of, programming quickly becomes very hard.) So, if a user picks a square, loop through their pieces to see, if some matches this square.

    What I was thinking was something like that:
    Code:
    class Square
    {
        bool has_piece_;
        Piece piece_;
        //interface
    };
    
    class Piece
    {
        player_type owner_; //black or white
        piece_type type_; //if this is the game I think it is, there's two types of pieces
        //interface
    };
    Of course, this wouldn't probably all be very good, if you wanted an advanced AI, in which case you would store the board state in a couple of unsigned ints as a bitset.

    As to the computer making a legal move:
    if it's computer's turn, loop through its pieces and generate all possible moves (forced moves separately). If there are any forced moves, pick one from this list, otherwise pick from non-forced moves.
    Last edited by anon; 04-06-2007 at 03:56 AM.

Popular pages Recent additions subscribe to a feed