943,838 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 727
  • C++ RSS
Nov 28th, 2008
0

Help with connect 4 game

Expand Post »
Hi, im a newbie in programming with only couple of months experience.
This game is a connect 4 game but works basically like a tic tac toe because insted of a piece dropping at the bottom of the board, it would stay in the selected area like tic tac toe

The problems are that when the program asks for the input, it does not show X or O. I think i messed with "turn" and my function for board but i dont know how to fix it. Another thing is that the "Scores" for the players dont show up and I want my board to have labels from 0-4 for row and 0-4 as well as for column but im lost on how to do it xD. I havent wrote the part to see whos the winner yet and if a draw happens

heres the code

C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. using namespace std;
  3. #define X -1
  4. #define O 1
  5.  
  6. void Logo();
  7. void Board1(int board1[5][5]);
  8.  
  9. int main()
  10. {
  11. int player;
  12. int score1=0;
  13. int score2=0;
  14. int row;
  15. int col;
  16. int board1[5][5]={(0,0,0,0,0),
  17. (0,0,0,0,0),
  18. (0,0,0,0,0),
  19. (0,0,0,0,0),
  20. (0,0,0,0,0),
  21. (0,0,0,0,0)};
  22.  
  23. Logo();
  24. cout<<"Welcome to dash to four"<<endl;
  25.  
  26.  
  27. for (int turn=1; turn <= 25 ; turn++)
  28. {
  29. cout<<score1<<endl;
  30. cout<<score2<<endl;
  31.  
  32. Board1(board1);
  33.  
  34. if (turn%2==0)
  35. player=O;
  36. else
  37. player=X;
  38.  
  39. do
  40. {
  41. cout<<"Player "<<(player==X ? "X" : "O")<<"Please enter a input of Row then Colmn: ";
  42. cin>>row>>col;
  43. }
  44. while(row<0 || row>24 || col<0 || col>24 || board1[row][col] != 0 );
  45.  
  46. board1[row][col]=player;
  47. }
  48. if (board1[0][0]+board1[0][1]+board1[0][2]+board1[0][3]==-4)
  49. cout<<"Player 1 Sores!";
  50. score1++;
  51. if (board1[0][1]+board1[0][2]+board1[0][3]+board1[0][4]==-4)
  52. cout<<"Player 1 Sores!";
  53. score1++;
  54. if (board1[1][0]+board1[1][1]+board1[1][2]+board1[1][3]==-4)
  55. cout<<"Player 1 Sores!";
  56. score1++;
  57. if (board1[1][1]+board1[1][2]+board1[1][3]+board1[1][4]==-4)
  58. cout<<"Player 1 Sores!";
  59. score1++;
  60. if (board1[2][0]+board1[2][1]+board1[2][2]+board1[2][3]==-4)
  61. cout<<"Player 1 Sores!";
  62. score1++;
  63. if (board1[2][1]+board1[2][2]+board1[2][3]+board1[2][4]==-4)
  64. cout<<"Player 1 Sores!";
  65. score1++;
  66. if (board1[3][0]+board1[3][1]+board1[3][2]+board1[3][3]==-4)
  67. cout<<"Player 1 Sores!";
  68. score1++;
  69. if (board1[3][1]+board1[3][2]+board1[3][3]+board1[3][4]==-4)
  70. cout<<"Player 1 Sores!";
  71. score1++;
  72. if (board1[4][0]+board1[4][1]+board1[4][2]+board1[4][3]==-4)
  73. cout<<"Player 1 Sores!";
  74. score1++;
  75. if (board1[4][1]+board1[4][2]+board1[4][3]+board1[4][4]==-4)
  76. cout<<"Player 1 Sores!";
  77. score1++;
  78.  
  79. if (board1[0][0]+board1[1][0]+board1[2][0]+board1[3][0]==-4)
  80. cout<<"Player 1 Sores!";
  81. score1++;
  82. if (board1[1][0]+board1[2][0]+board1[3][0]+board1[4][0]==-4)
  83. cout<<"Player 1 Sores!";
  84. score1++;
  85. if (board1[0][1]+board1[1][1]+board1[2][1]+board1[3][1]==-4)
  86. cout<<"Player 1 Sores!";
  87. score1++;
  88. if (board1[1][1]+board1[2][1]+board1[3][1]+board1[4][1]==-4)
  89. cout<<"Player 1 Sores!";
  90. score1++;
  91. if (board1[0][2]+board1[1][2]+board1[2][2]+board1[3][2]==-4)
  92. cout<<"Player 1 Sores!";
  93. score1++;
  94. if (board1[1][2]+board1[2][2]+board1[3][2]+board1[4][2]==-4)
  95. cout<<"Player 1 Sores!";
  96. score1++;
  97. if (board1[0][3]+board1[1][3]+board1[2][3]+board1[3][3]==-4)
  98. cout<<"Player 1 Sores!";
  99. score1++;
  100. if (board1[1][3]+board1[2][3]+board1[3][3]+board1[4][3]==-4)
  101. cout<<"Player 1 Sores!";
  102. score1++;
  103. if (board1[0][4]+board1[1][4]+board1[2][4]+board1[3][4]==-4)
  104. cout<<"Player 1 Sores!";
  105. score1++;
  106. if (board1[1][4]+board1[2][4]+board1[3][4]+board1[4][4]==-4)
  107. cout<<"Player 1 Sores!";
  108. score1++;
  109.  
  110. if (board1[0][0]+board1[1][1]+board1[2][2]+board1[3][3]==-4)
  111. cout<<"Player 1 Sores!";
  112. score1++;
  113. if (board1[1][1]+board1[2][2]+board1[3][3]+board1[4][4]==-4)
  114. cout<<"Player 1 Sores!";
  115. score1++;
  116. if (board1[0][1]+board1[1][2]+board1[2][3]+board1[3][4]==-4)
  117. cout<<"Player 1 Sores!";
  118. score1++;
  119. if (board1[1][0]+board1[2][1]+board1[3][2]+board1[4][3]==-4)
  120. cout<<"Player 1 Sores!";
  121. score1++;
  122. if (board1[4][0]+board1[3][1]+board1[2][2]+board1[1][3]==-4)
  123. cout<<"Player 1 Sores!";
  124. score1++;
  125. if (board1[3][1]+board1[2][2]+board1[1][3]+board1[0][4]==-4)
  126. cout<<"Player 1 Sores!";
  127. score1++;
  128. if (board1[4][1]+board1[3][2]+board1[2][3]+board1[1][4]==-4)
  129. cout<<"Player 1 Sores!";
  130. score1++;
  131. if (board1[3][0]+board1[2][1]+board1[1][2]+board1[0][3]==-4)
  132. cout<<"Player 1 Sores!";
  133. score1++;
  134. if (board1[0][0]+board1[0][1]+board1[0][2]+board1[0][3]==4)
  135. cout<<"Player2 Scores!"<<endl;
  136. score2++;
  137. if (board1[0][1]+board1[0][2]+board1[0][3]+board1[0][4]==4)
  138. cout<<"Player2 Scores!"<<endl;
  139. score2++;
  140. if (board1[1][0]+board1[1][1]+board1[1][2]+board1[1][3]==4)
  141. cout<<"Player2 Scores!"<<endl;
  142. score2++;
  143. if (board1[1][1]+board1[1][2]+board1[1][3]+board1[1][4]==4)
  144. cout<<"Player2 Scores!"<<endl;
  145. score2++;
  146. if (board1[2][0]+board1[2][1]+board1[2][2]+board1[2][3]==4)
  147. cout<<"Player2 Scores!"<<endl;
  148. score2++;
  149. if (board1[2][1]+board1[2][2]+board1[2][3]+board1[2][4]==4)
  150. cout<<"Player2 Scores!"<<endl;
  151. score2++;
  152. if (board1[3][0]+board1[3][1]+board1[3][2]+board1[3][3]==4)
  153. cout<<"Player2 Scores!"<<endl;
  154. score2++;
  155. if (board1[3][1]+board1[3][2]+board1[3][3]+board1[3][4]==4)
  156. cout<<"Player2 Scores!"<<endl;
  157. score2++;
  158. if (board1[4][0]+board1[4][1]+board1[4][2]+board1[4][3]==4)
  159. cout<<"Player2 Scores!"<<endl;
  160. score2++;
  161. if (board1[4][1]+board1[4][2]+board1[4][3]+board1[4][4]==4)
  162. cout<<"Player2 Scores!"<<endl;
  163. score2++;
  164.  
  165. if (board1[0][0]+board1[1][0]+board1[2][0]+board1[3][0]==4)
  166. cout<<"Player2 Scores!"<<endl;
  167. score2++;
  168. if (board1[1][0]+board1[2][0]+board1[3][0]+board1[4][0]==4)
  169. cout<<"Player2 Scores!"<<endl;
  170. score2++;
  171. if (board1[0][1]+board1[1][1]+board1[2][1]+board1[3][1]==4)
  172. cout<<"Player2 Scores!"<<endl;
  173. score2++;
  174. if (board1[1][1]+board1[2][1]+board1[3][1]+board1[4][1]==4)
  175. cout<<"Player2 Scores!"<<endl;
  176. score2++;
  177. if (board1[0][2]+board1[1][2]+board1[2][2]+board1[3][2]==4)
  178. cout<<"Player2 Scores!"<<endl;
  179. score2++;
  180. if (board1[1][2]+board1[2][2]+board1[3][2]+board1[4][2]==4)
  181. cout<<"Player2 Scores!"<<endl;
  182. score2++;
  183. if (board1[0][3]+board1[1][3]+board1[2][3]+board1[3][3]==4)
  184. cout<<"Player2 Scores!"<<endl;
  185. score2++;
  186. if (board1[1][3]+board1[2][3]+board1[3][3]+board1[4][3]==4)
  187. cout<<"Player2 Scores!"<<endl;
  188. score2++;
  189. if (board1[0][4]+board1[1][4]+board1[2][4]+board1[3][4]==4)
  190. cout<<"Player2 Scores!"<<endl;
  191. score2++;
  192. if (board1[1][4]+board1[2][4]+board1[3][4]+board1[4][4]==4)
  193. cout<<"Player2 Scores!"<<endl;
  194. score2++;
  195.  
  196. if (board1[0][0]+board1[1][1]+board1[2][2]+board1[3][3]==4)
  197. cout<<"Player2 Scores!"<<endl;
  198. score2++;
  199. if (board1[1][1]+board1[2][2]+board1[3][3]+board1[4][4]==4)
  200. cout<<"Player2 Scores!"<<endl;
  201. score2++;
  202. if (board1[0][1]+board1[1][2]+board1[2][3]+board1[3][4]==4)
  203. cout<<"Player2 Scores!"<<endl;
  204. score2++;
  205. if (board1[1][0]+board1[2][1]+board1[3][2]+board1[4][3]==4)
  206. cout<<"Player2 Scores!"<<endl;
  207. score2++;
  208. if (board1[4][0]+board1[3][1]+board1[2][2]+board1[1][3]==4)
  209. cout<<"Player2 Scores!"<<endl;
  210. score2++;
  211. if (board1[3][1]+board1[2][2]+board1[1][3]+board1[0][4]==4)
  212. cout<<"Player2 Scores!"<<endl;
  213. score2++;
  214. if (board1[4][1]+board1[3][2]+board1[2][3]+board1[1][4]==4)
  215. cout<<"Player2 Scores!"<<endl;
  216. score2++;
  217. if (board1[3][0]+board1[2][1]+board1[1][2]+board1[0][3]==4)
  218. cout<<"Player2 Scores!"<<endl;
  219. score2++;
  220.  
  221. return 0;
  222. }
  223.  
  224. void Logo()
  225. {
  226. cout<<" ******************************"<<endl;
  227. cout<<" ************DASH TO*************"<<endl;
  228. cout<<" **********************************"<<endl;
  229. cout<<" *****************4******************"<<endl;
  230. cout<<"*****************4*4******************"<<endl;
  231. cout<<"****************4**4******************"<<endl;
  232. cout<<" **************444444****************"<<endl;
  233. cout<<" *****************4****************"<<endl;
  234. cout<<" ****************4***************"<<endl;
  235. cout<<" ******************************"<<endl;
  236. }
  237. void Board1(int board1[5][5])
  238. {
  239. cout << endl;
  240.  
  241. for (int row=0; row<5; row++)
  242. {
  243. for (int col=0; col<5; col++)
  244. {
  245. cout << "| ";
  246. if (board1[row][col] == 0) cout << " ";
  247. else if (board1[5][5] == -1) cout << "X";
  248. else if (board1[5][5] == 1) cout << "O";
  249. }
  250. cout << "\n-------------" << endl;
  251. }
  252. }

Really need help on fixing this thing asap
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
SobigR is offline Offline
3 posts
since Nov 2008
Nov 28th, 2008
0

Re: Help with connect 4 game

First off -- You know about loops, so what is that monstrosity of a list of
stuff deciding who has won. Why not use a loop.

The problem is actually in the last two else if statements.
board1[5][5] which does two things. (A) there is no board[5][5] the
array is ranged 0-4 + 0-4 so that is a random UNKNOWN memory location. (B) use didn't you mean [row][col].

(C) it is pain ugly.
c++ Syntax (Toggle Plain Text)
  1. const char PUnit[]="X 0";
  2. for(int row=0;row<5;row++)
  3. {
  4. for(int col=0;col<5;col++)
  5. std::cout<<PUnit[board1[row][col]];
  6. std::cout<<std::endl;
  7. }
Note that the idea in this code, effectively transform -1/0/1 into characters. You might want a if guard on the values BUT it is possible that is only in debug mode as you shouldn't be able to get out of the -1,0,1 range on board1.

p.s Sorry but there are other errors with your code. BUT how to test code is also part of the process of learning to program. (and is easily transferable to any other language -- most likely a more important skill than how to write C++. )
Last edited by StuXYZ; Nov 28th, 2008 at 5:24 am. Reason: I will try to write in sentenses first time :-)
Reputation Points: 732
Solved Threads: 134
Practically a Master Poster
StuXYZ is offline Offline
659 posts
since Nov 2008
Nov 28th, 2008
0

Re: Help with connect 4 game

What the heck is X?

Replace
C++ Syntax (Toggle Plain Text)
  1. if (turn%2==0)
  2. player=O;
  3. else
  4. player=X;

by

C++ Syntax (Toggle Plain Text)
  1. player = turn % 2;

and
C++ Syntax (Toggle Plain Text)
  1. cout<<"Player "<<(player==X ? "X" : "O")<<"Please enter a input of Row then Colmn: ";

by

C++ Syntax (Toggle Plain Text)
  1. cout<<"Player "<<(player==0 ? "X" : "O")<<"Please enter a input of Row then Colmn: ";

and it should work (didn't test it!)
Last edited by jencas; Nov 28th, 2008 at 5:26 am.
Reputation Points: 395
Solved Threads: 71
Posting Whiz
jencas is offline Offline
362 posts
since Dec 2007
Nov 28th, 2008
0

Re: Help with connect 4 game

i dont know what to say...so...
C++ Syntax (Toggle Plain Text)
  1. void Board1(int board1[5][5])
  2. {
  3. cout << endl;
  4.  
  5. for (int row=0; row<5; row++)
  6. {
  7. for (int col=0; col<5; col++)
  8. {
  9. cout << "| ";
  10. if (board1[row][col] == 0) cout << " ";
  11. else if (board1[row][col] == -1) cout << "X";
  12. else if (board1[row][col] == 1) cout << "O";
  13. }
  14. cout << "\n-------------" << endl;
  15. }
  16. }
Reputation Points: 47
Solved Threads: 69
Posting Whiz
cikara21 is offline Offline
340 posts
since Jul 2008
Nov 28th, 2008
1

Re: Help with connect 4 game

X is....
C++ Syntax (Toggle Plain Text)
  1. #define X -1
  2. #define O 1
rite!!....
Last edited by cikara21; Nov 28th, 2008 at 5:35 am.
Reputation Points: 47
Solved Threads: 69
Posting Whiz
cikara21 is offline Offline
340 posts
since Jul 2008
Nov 28th, 2008
0

Re: Help with connect 4 game

ok so i reviewed my program and saw a lot and i mean a lot of mistakes xD. so i fixed them and now...

my problem now is i cant label the rows as 0 1 2 3 4
i can only label the columns xD
and i have no idea on how to check if a tie happens

i know its ugly, ive just started to learn to program last 2 months and just 2 days of class per week
Last edited by SobigR; Nov 28th, 2008 at 7:30 am. Reason: forgot to type somthing
Reputation Points: 10
Solved Threads: 0
Newbie Poster
SobigR is offline Offline
3 posts
since Nov 2008
Nov 28th, 2008
0

Re: Help with connect 4 game

I encountered another problem

i labeled my columns already (not good though) but when i ran the program and if someone wins, say player X, it still asks for input though someone already won and i still cant figure out properly how to check for a tie AND I BADLY NEED THIS THING TO WORK

C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. using namespace std;
  3. #define X -1
  4. #define O 1
  5.  
  6. void Logo();
  7. void Board1(int board1[5][5]);
  8.  
  9. int main()
  10. {
  11. int player;
  12. int row;
  13. int col;
  14. int turn;
  15. int board1[5][5]={(0,0,0,0,0),
  16. (0,0,0,0,0),
  17. (0,0,0,0,0),
  18. (0,0,0,0,0),
  19. (0,0,0,0,0),
  20. (0,0,0,0,0)};
  21.  
  22. Logo();
  23. cout<<"Welcome to dash to four"<<endl;
  24.  
  25.  
  26. for (turn=1; turn<=25 ; turn++)
  27. {
  28.  
  29. Board1(board1);
  30.  
  31. if (turn%2==0)
  32. player=O;
  33. else
  34. player=X;
  35.  
  36. do
  37. {
  38. cout<<"Player "<<(player==X ? "X" : "O")<<" Please input of Row then Column: ";
  39. cin>>row>>col;
  40. }
  41. while(row<0 || row>24 || col<0 || col>24 || board1[row][col] != 0 );
  42.  
  43. board1[row][col]=player;
  44.  
  45.  
  46. if (board1[0][0]+board1[0][1]+board1[0][2]+board1[0][3]==-4)
  47. cout<<"Player X Wins!"<<endl;
  48. if (board1[0][1]+board1[0][2]+board1[0][3]+board1[0][4]==-4)
  49. cout<<"Player X Wins!"<<endl;
  50. if (board1[1][0]+board1[1][1]+board1[1][2]+board1[1][3]==-4)
  51. cout<<"Player X Wins!"<<endl;
  52. if (board1[1][1]+board1[1][2]+board1[1][3]+board1[1][4]==-4)
  53. cout<<"Player X Wins!"<<endl;
  54. if (board1[2][0]+board1[2][1]+board1[2][2]+board1[2][3]==-4)
  55. cout<<"Player X Wins!"<<endl;
  56. if (board1[2][1]+board1[2][2]+board1[2][3]+board1[2][4]==-4)
  57. cout<<"Player X Wins!"<<endl;
  58. if (board1[3][0]+board1[3][1]+board1[3][2]+board1[3][3]==-4)
  59. cout<<"Player X Wins!"<<endl;
  60. if (board1[3][1]+board1[3][2]+board1[3][3]+board1[3][4]==-4)
  61. cout<<"Player X Wins!"<<endl;
  62. if (board1[4][0]+board1[4][1]+board1[4][2]+board1[4][3]==-4)
  63. cout<<"Player X Wins!"<<endl;
  64. if (board1[4][1]+board1[4][2]+board1[4][3]+board1[4][4]==-4)
  65. cout<<"Player X Wins!"<<endl;
  66.  
  67. if (board1[0][0]+board1[1][0]+board1[2][0]+board1[3][0]==-4)
  68. cout<<"Player X Wins!"<<endl;
  69. if (board1[1][0]+board1[2][0]+board1[3][0]+board1[4][0]==-4)
  70. cout<<"Player X Wins!"<<endl;
  71. if (board1[0][1]+board1[1][1]+board1[2][1]+board1[3][1]==-4)
  72. cout<<"Player X Wins!"<<endl;
  73. if (board1[1][1]+board1[2][1]+board1[3][1]+board1[4][1]==-4)
  74. cout<<"Player X Wins!"<<endl;
  75. if (board1[0][2]+board1[1][2]+board1[2][2]+board1[3][2]==-4)
  76. cout<<"Player X Wins!"<<endl;
  77. if (board1[1][2]+board1[2][2]+board1[3][2]+board1[4][2]==-4)
  78. cout<<"Player X Wins!"<<endl;
  79. if (board1[0][3]+board1[1][3]+board1[2][3]+board1[3][3]==-4)
  80. cout<<"Player X Wins!"<<endl;
  81. if (board1[1][3]+board1[2][3]+board1[3][3]+board1[4][3]==-4)
  82. cout<<"Player X Wins!"<<endl;
  83. if (board1[0][4]+board1[1][4]+board1[2][4]+board1[3][4]==-4)
  84. cout<<"Player X Wins!"<<endl;
  85. if (board1[1][4]+board1[2][4]+board1[3][4]+board1[4][4]==-4)
  86. cout<<"Player X Wins!"<<endl;
  87.  
  88. if (board1[0][0]+board1[1][1]+board1[2][2]+board1[3][3]==-4)
  89. cout<<"Player X Wins!"<<endl;
  90. if (board1[1][1]+board1[2][2]+board1[3][3]+board1[4][4]==-4)
  91. cout<<"Player X Wins!"<<endl;
  92. if (board1[0][1]+board1[1][2]+board1[2][3]+board1[3][4]==-4)
  93. cout<<"Player X Wins!"<<endl;
  94. if (board1[1][0]+board1[2][1]+board1[3][2]+board1[4][3]==-4)
  95. cout<<"Player X Wins!"<<endl;
  96. if (board1[4][0]+board1[3][1]+board1[2][2]+board1[1][3]==-4)
  97. cout<<"Player X Wins!"<<endl;
  98. if (board1[3][1]+board1[2][2]+board1[1][3]+board1[0][4]==-4)
  99. cout<<"Player X Wins!"<<endl;
  100. if (board1[4][1]+board1[3][2]+board1[2][3]+board1[1][4]==-4)
  101. cout<<"Player X Wins!"<<endl;
  102. if (board1[3][0]+board1[2][1]+board1[1][2]+board1[0][3]==-4)
  103. cout<<"Player X Wins!"<<endl;
  104.  
  105.  
  106. if (board1[0][0]+board1[0][1]+board1[0][2]+board1[0][3]==4)
  107. cout<<"Player O Wins!"<<endl;
  108. if (board1[0][1]+board1[0][2]+board1[0][3]+board1[0][4]==4)
  109. cout<<"Player O Wins!"<<endl;
  110. if (board1[1][0]+board1[1][1]+board1[1][2]+board1[1][3]==4)
  111. cout<<"Player O Wins!"<<endl;
  112. if (board1[1][1]+board1[1][2]+board1[1][3]+board1[1][4]==4)
  113. cout<<"Player O Wins!"<<endl;
  114. if (board1[2][0]+board1[2][1]+board1[2][2]+board1[2][3]==4)
  115. cout<<"Player O Wins!"<<endl;
  116. if (board1[2][1]+board1[2][2]+board1[2][3]+board1[2][4]==4)
  117. cout<<"Player O Wins!"<<endl;
  118. if (board1[3][0]+board1[3][1]+board1[3][2]+board1[3][3]==4)
  119. cout<<"Player O Wins!"<<endl;
  120. if (board1[3][1]+board1[3][2]+board1[3][3]+board1[3][4]==4)
  121. cout<<"Player O Wins!"<<endl;
  122. if (board1[4][0]+board1[4][1]+board1[4][2]+board1[4][3]==4)
  123. cout<<"Player O Wins!"<<endl;
  124. if (board1[4][1]+board1[4][2]+board1[4][3]+board1[4][4]==4)
  125. cout<<"Player O Wins!"<<endl;
  126.  
  127. if (board1[0][0]+board1[1][0]+board1[2][0]+board1[3][0]==4)
  128. cout<<"Player O Wins!"<<endl;
  129. if (board1[1][0]+board1[2][0]+board1[3][0]+board1[4][0]==4)
  130. cout<<"Player O Wins!"<<endl;
  131. if (board1[0][1]+board1[1][1]+board1[2][1]+board1[3][1]==4)
  132. cout<<"Player O Wins!"<<endl;
  133. if (board1[1][1]+board1[2][1]+board1[3][1]+board1[4][1]==4)
  134. cout<<"Player O Wins!"<<endl;
  135. if (board1[0][2]+board1[1][2]+board1[2][2]+board1[3][2]==4)
  136. cout<<"Player O Wins!"<<endl;
  137. if (board1[1][2]+board1[2][2]+board1[3][2]+board1[4][2]==4)
  138. cout<<"Player O Wins!"<<endl;
  139. if (board1[0][3]+board1[1][3]+board1[2][3]+board1[3][3]==4)
  140. cout<<"Player O Wins!"<<endl;
  141. if (board1[1][3]+board1[2][3]+board1[3][3]+board1[4][3]==4)
  142. cout<<"Player O Wins!"<<endl;
  143. if (board1[0][4]+board1[1][4]+board1[2][4]+board1[3][4]==4)
  144. cout<<"Player O Wins!"<<endl;
  145. if (board1[1][4]+board1[2][4]+board1[3][4]+board1[4][4]==4)
  146. cout<<"Player O Wins!"<<endl;
  147.  
  148. if (board1[0][0]+board1[1][1]+board1[2][2]+board1[3][3]==4)
  149. cout<<"Player O Wins!"<<endl;
  150. if (board1[1][1]+board1[2][2]+board1[3][3]+board1[4][4]==4)
  151. cout<<"Player O Wins!"<<endl;
  152. if (board1[0][1]+board1[1][2]+board1[2][3]+board1[3][4]==4)
  153. cout<<"Player O Wins!"<<endl;
  154. if (board1[1][0]+board1[2][1]+board1[3][2]+board1[4][3]==4)
  155. cout<<"Player O Wins!"<<endl;
  156. if (board1[4][0]+board1[3][1]+board1[2][2]+board1[1][3]==4)
  157. cout<<"Player O Wins!"<<endl;
  158. if (board1[3][1]+board1[2][2]+board1[1][3]+board1[0][4]==4)
  159. cout<<"Player O Wins!"<<endl;
  160. if (board1[4][1]+board1[3][2]+board1[2][3]+board1[1][4]==4)
  161. cout<<"Player O Wins!"<<endl;
  162. if (board1[3][0]+board1[2][1]+board1[1][2]+board1[0][3]==4)
  163. cout<<"Player O Wins!"<<endl;
  164. if (turn==26)
  165. cout<<"Draw!"<<endl;
  166. system("cls");
  167. }
  168.  
  169. return 0;
  170. }
  171.  
  172. void Logo()
  173. {
  174. cout<<" ******************************"<<endl;
  175. cout<<" ************DASH TO*************"<<endl;
  176. cout<<" **********************************"<<endl;
  177. cout<<" *****************4******************"<<endl;
  178. cout<<"*****************4*4******************"<<endl;
  179. cout<<"****************4**4******************"<<endl;
  180. cout<<" **************444444****************"<<endl;
  181. cout<<" *****************4****************"<<endl;
  182. cout<<" ****************4***************"<<endl;
  183. cout<<" ******************************"<<endl;
  184. }
  185. void Board1(int board1[5][5])
  186. {
  187. int counter=0;
  188. cout<<endl;
  189. cout<<" 0 1 2 3 4"<<endl;
  190. cout<<"---------------------"<<endl;
  191. for (int row=0; row<5; row++)
  192. {
  193. for (int col=0; col<5; col++)
  194. {
  195. cout<<"| ";
  196. if (board1[row][col]==0) cout<<" ";
  197. else if (board1[row][col]==-1) cout<<"X";
  198. else if (board1[row][col]==1) cout<<"O";
  199. }
  200. cout<<"\n---------------------"<<counter<<endl;
  201. counter++;
  202.  
  203. }
  204. }
Last edited by SobigR; Nov 28th, 2008 at 9:01 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
SobigR is offline Offline
3 posts
since Nov 2008
Nov 28th, 2008
0

Re: Help with connect 4 game

Let me see now. But sorry, a set of things were pointed out
(A) have you removed the #define ?
(B) have you improved the stupid do I win section
(C) Have you made ANY changes above the simplest 5=row, 5=col,
like actually improve the loop

Answers on a postcard please ..... Beyond that I am prepared to look at you ugly code for a total of the amount of time required to make your changes.
Reputation Points: 732
Solved Threads: 134
Practically a Master Poster
StuXYZ is offline Offline
659 posts
since Nov 2008
Dec 6th, 2008
0

Re: Help with connect 4 game

try to use if..else if..else..
Reputation Points: 47
Solved Threads: 69
Posting Whiz
cikara21 is offline Offline
340 posts
since Jul 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Win32 API or OOP using Win32 API
Next Thread in C++ Forum Timeline: Calling a function by a variable





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC