Thread: My next 'dos console' game...

  1. #1
    Unregistered Leeman_s's Avatar
    Join Date
    Oct 2001
    Posts
    753

    My next 'dos console' game...

    I was thinking of battleship, would that be cool or what? That shouldn't be TOO hard, right?

  2. #2
    Flash Animator, OF DOOOOM bluehead's Avatar
    Join Date
    Nov 2001
    Posts
    269
    Battle ship being not TOO hard???are you on something?
    Code:
    #if _emo
      #define stereo_type_i_dislike
    #endif

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    412
    Battleship's reasonably easy.

    Connect-4 would be easy. Go is easy enough to program, rules-wise, but the AI would be trickier.

  4. #4
    Unregistered Leeman_s's Avatar
    Join Date
    Oct 2001
    Posts
    753

    Ok

    Battleship wouldnt be that hard. The only hard part is the AI. It would just take a long time to write out all the code for it. Thinking of how to do it is an easy task so far. Just to prove it, now I'm definitely going to do it. Muahahahaha!

  5. #5
    Registered User
    Join Date
    Sep 2001
    Posts
    412
    Well, you have some options for AI:

    * If no hits on unsunk ships are present, you can try a few things:

    1) Randomly fire
    2) Fire only on areas that could conceivably have a ship -- you need to figure out the size(s) of the remaining ship(s), figure which elements could contain one or more of these ships, and fire on any random one of them.
    3) Fire in an area that is "most likely" to contain a ship -- i.e. given the size of the remaining ship(s), figure how many ways each grid point could contain a ship, and of all of those with the highest probability, one is randomly chosen.

    The AI will improve as you move from 1-3, but so will complexity. 2) is probably a good choice, 3) would take a little more effort, but there would be ways to get around having to recalculate the probability of each square on the board -- you only need to recalculate the squares whose probablility changes after each move.

    In fact, 3 could be implemented with a little careful thought. If you set up classes and methods intelligently, it wouldn't be THAT tricky.

    * If you have previously hit an unsunk ship, the algorithm is simpler -- try to figure out which direction the ship lies on, and continue to fire on that line until sunk.

  6. #6
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    If you want to do battleships then try to take an oop approach and use virtual functions and inheritance properly.

    make a class like BoardItem that contains a pure virtual function called Shot(). Then derive some classes from BoardItem like AirCarrier,Cruiser,OpenSea. Each of these can override the virtual function shot. A possible implementation of OpenSea version could be :-

    cout<<"Splosh"<<flush;

    implementation in aircraft carrier would be ...

    cout<<"Bang !! You hit my aircraft carrier"<<flush;

    the beauty of all this is when you make the board this is really an array of pointers to objects of these classes.You then call shot on whatever object in the array because all array items are derived from BoardItem and the correct thing happens. Read about polymorphism. You can tie all the ai into this sort of structure too.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 2D Game project requires extra C++ programmers, new or experienced
    By drallstars in forum Projects and Job Recruitment
    Replies: 2
    Last Post: 05-16-2007, 10:46 AM
  2. 2D RPG Online Game Project. 30% Complete. To be released and marketed.
    By drallstars in forum Projects and Job Recruitment
    Replies: 2
    Last Post: 10-28-2006, 12:48 AM
  3. Game console programming
    By swgh in forum Game Programming
    Replies: 10
    Last Post: 05-07-2006, 12:24 PM
  4. C Programming 2d Array Question
    By jeev2005 in forum C Programming
    Replies: 3
    Last Post: 04-26-2006, 03:18 PM
  5. DOS program versus DOS console program
    By scromer in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 01-10-2002, 01:42 PM