5 Replies - 1048 Views - Last Post: 11 March 2013 - 06:25 PM Rate Topic: -----

#1 kelagar  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 10-March 13

Connect four game progam

Posted 10 March 2013 - 07:43 PM

Hi,

hi,

I need help making a c++ program for school.

The program deals with the game connect 4(http://en.wikipedia.org/wiki/Connect_Four). The game consists of a grid : 3 rows x 3 columns (or 9 cells) :
To identify each cell, we index them : Cell 1 is at the bottom-left
while cell 9 is at the top-right of the grid. Use only arrays of one
dimension.
There are two players (indexed by 1 and 2) who take turn to
drop one token (identified by the user index) in either column 1,
2 or 3, with the objective to align 3 of his/her tokens in a row,
in a column or in a diagonal. Both players are humans and the program will request the players to input the column where they wish to drop the token.

Implement your program with one input to get the column index where the player will drop the token. Your program must check that the selected column is not full; as long as the player keeps selecting a column that is full, the program must ask the same player for another input. After getting a valid column index, have your program update the state of the grid, display its content and determine if the game is over or not. If the game is not over, then it is the turn of the other player. And so on.
Here are (some of ) the tasks your flowchart needs to implement (you may add others) :
a) how does the program determine that the game is over (either all the 9 cells are filled and
there is no winner or one of the player aligns 3 tokens in a row, a column or a diagonal) ?
B)/> The players take turn to drop their tokens. How does your program determine who is the
next player to play and how does it identify the tokens (from player 1 or from player 2) in the grid ?
c) If a column is full (ie. 3 tokens are already in the that column), no player can drop another
token in that column. How does your program identify the column(s) where the next player can still
drop his/her token ?

I do know how to generate a random number between 1,2, and 3:
#include <cstdlib>
#include <iostream>
#include <time.h>
using namespace std;
int main(int argc, char *argv[])
{ 
srand ( time(NULL) );
int code = rand()%3 +1; // code will be 1, 2 or 3
cout << code<<endl; 
system("PAUSE");
return EXIT_SUCCESS;
}


Thank you very much :)/>

This post has been edited by Skydiver: 10 March 2013 - 07:59 PM
Reason for edit:: Put code in code tags. Next time, do this yourself.


Is This A Good Question/Topic? 0
  • +

Replies To: Connect four game progam

#2 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3662
  • View blog
  • Posts: 11,472
  • Joined: 05-May 12

Re: Connect four game progam

Posted 10 March 2013 - 08:01 PM

I'm glad you know how to output a random number, but if you read your assignment, there is no need to use random numbers. So you'll have to try harder and show us that you are actually putting an effort to work on the assignment instead of hoping somebody here will just give you the code.
Was This Post Helpful? 0
  • +
  • -

#3 kelagar  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 10-March 13

Re: Connect four game progam

Posted 10 March 2013 - 10:10 PM

Thanks for the quick reply, but there are actually 2 parts to the assignment, the second part is where the two players are human and computer. That is the only case when the the random number generation is needed. If i know how to do the first part i can find out a way to do the second part myself.
Was This Post Helpful? 0
  • +
  • -

#4 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3662
  • View blog
  • Posts: 11,472
  • Joined: 05-May 12

Re: Connect four game progam

Posted 11 March 2013 - 06:17 AM

There is know we could have known that you had a second part to the assignment based on what you posted above describing your assignment.

So what work have you done on the first part?
Was This Post Helpful? 0
  • +
  • -

#5 kelagar  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 10-March 13

Re: Connect four game progam

Posted 11 March 2013 - 12:27 PM

Im just a beginner, so i start my work by making a flowchart on raptor then i transfer it to c++. I have got down the inputs,but im not sure how to display the results. Like if it should be just numbers or an actual grid with circles as the inputs.
Was This Post Helpful? 0
  • +
  • -

#6 snoopy11  Icon User is offline

  • Engineering ● Software
  • member icon

Reputation: 841
  • View blog
  • Posts: 2,472
  • Joined: 20-March 10

Re: Connect four game progam

Posted 11 March 2013 - 06:25 PM

Traditionally you build a grid with | and _ and put X's and O's in.

Regards

Snoopy.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1