fork(9) download
  1. #include <stdio.h>
  2. int board[6][7];
  3. int ticker = 0;
  4. int main(void) {
  5. // Title Screen //
  6. printf("||**||**||**||**||**||**||\n");
  7. printf("||**||**||**||**||**||**||\n");
  8. printf("||**||C O N N E C T ||**||\n");
  9. printf("||**|| F O U R ||**||\n");
  10. printf("||**||**||**||**||**||**||\n");
  11. printf("||**||**||**||**||**||**||\n");
  12. printf("\n");
  13. printf("\n");
  14. ////////////////////////////////////
  15.  
  16. // Creating the board //
  17. int r;
  18. int c;
  19. int i;
  20. int j;
  21. int check[4];
  22.  
  23.  
  24. for(r = 1; r < 7; r++)
  25. {
  26. for(c = 1; c < 8; c++ )
  27. {
  28. board[r][c] = 0;
  29. }
  30. }
  31. ////////////////////////////
  32.  
  33. // Printing the board //
  34. printf(" 1 2 3 4 5 6 7\n");
  35. printf("\n");
  36. for(r = 1; r < 7; r++)
  37. {
  38. for(c = 1; c < 8; c++ )
  39. {
  40. printf(" %d ",board[r][c]);
  41. }
  42. printf("\n");
  43. }
  44.  
  45. ////////////////////////////
  46.  
  47. for(int d = 0; d <= 22; d++)// Repeats until playerwin breaks loop or ticker reaches 42 //
  48. {// main loop initial
  49.  
  50. // collect player 1 input // PLAYER 1 //
  51. int input1;
  52. printf("Player 1, please enter a column from 1 to 7 to drop your piece into.\n");
  53. scanf(" %d ", &input1);
  54. //////////////////////////////////////
  55.  
  56. // Checking if player 1's input is valid //
  57. while(input1 > 7)
  58. {
  59. printf("The comlumn you have chosen does not exist, please choose a different column.\n");
  60. scanf(" %d ", &input1);
  61. }
  62.  
  63. while(input1 < 1)
  64. {
  65. printf("The comlumn you have chosen does not exist, please choose a different column.\n");
  66. scanf(" %d ", &input1);
  67. }
  68.  
  69. while(board[1][input1] != 0)
  70. {
  71. printf("The comlumn you have chosen is full, please choose a different column.\n");
  72. scanf(" %d ", &input1);
  73.  
  74. }
  75. /////////////////////////////
  76.  
  77. // Application of player1's choice //
  78. printf("Player 1 chose column %d.\n", input1);
  79. if(board[6][input1] == 0)
  80. {
  81. board[6][input1] = 1;
  82. }
  83. else
  84. {
  85. if(board[5][input1] == 0)
  86. {
  87. board[5][input1] = 1;
  88. }
  89. else
  90. {
  91. if(board[4][input1] == 0)
  92. {
  93. board[4][input1] = 1;
  94. }
  95. else
  96. {
  97. if(board[3][input1] == 0)
  98. {
  99. board[3][input1] = 1;
  100. }
  101. else
  102. {
  103. if(board[2][input1] == 0)
  104. {
  105. board[2][input1] = 1;
  106. }
  107. else
  108. {
  109. board[1][input1] = 1;
  110. }
  111. }
  112. }
  113. }
  114. }
  115. printf(" 1 2 3 4 5 6 7\n");
  116. printf("\n");
  117. for(int r = 1; r < 7; r++)
  118. {
  119. for(int c = 1; c < 8; c++ )
  120. {
  121. printf(" %d ",board[r][c]);
  122. }
  123. printf("\n");
  124. }
  125. ////////////////////////////////
  126.  
  127. // Checking for player 1 win //
  128. // Checking diagonal wins //
  129. j = 1;
  130. for(i = 4; i>0; i--)
  131. {
  132. check[j-1] = board[i][j];
  133. j++;
  134. }
  135.  
  136. if(check[0] == 1 && check[1] == 1 && check[2] == 1 && check[3] == 1)
  137. {
  138. printf("Player 1 wins!");
  139. break;
  140. }
  141. j = 2;
  142. for(i = 4; i>0; i--)
  143. {
  144. check[j-2] = board[i][j];
  145. j++;
  146. }
  147.  
  148. if(check[0] == 1 && check[1] == 1 && check[2] == 1 && check[3] == 1)
  149. {
  150. printf("Player 1 wins!");
  151. break;
  152. }
  153. j=3;
  154. for(i = 4; i>0; i--)
  155. {
  156. check[j-3] = board[i][j];
  157. j++;
  158. }
  159.  
  160. if(check[0] == 1 && check[1] == 1 && check[2] == 1 && check[3] == 1)
  161. {
  162. printf("Player 1 wins!");
  163. break;
  164. }
  165. j=4;
  166. for(i = 4; i>0; i--)
  167. {
  168. check[j-4] = board[i][j];
  169. j++;
  170. }
  171.  
  172. if(check[0] == 1 && check[1] == 1 && check[2] == 1 && check[3] == 1)
  173. {
  174. printf("Player 1 wins!");
  175. break;
  176. }
  177. j = 1;
  178. for(i = 5; i>1; i--)
  179. {
  180. check[j-1] = board[i][j];
  181. j++;
  182. }
  183.  
  184. if(check[0] == 1 && check[1] == 1 && check[2] == 1 && check[3] == 1)
  185. {
  186. printf("Player 1 wins!");
  187. break;
  188. }
  189. j = 2;
  190. for(i = 5; i>1; i--)
  191. {
  192. check[j-2] = board[i][j];
  193. j++;
  194. }
  195.  
  196. if(check[0] == 1 && check[1] == 1 && check[2] == 1 && check[3] == 1)
  197. {
  198. printf("Player 1 wins!");
  199. break;
  200. }
  201. j=3;
  202. for(i = 5; i>1; i--)
  203. {
  204. check[j-3] = board[i][j];
  205. j++;
  206. }
  207.  
  208. if(check[0] == 1 && check[1] == 1 && check[2] == 1 && check[3] == 1)
  209. {
  210. printf("Player 1 wins!");
  211. break;
  212. }
  213. j=4;
  214. for(i = 5; i>1; i--)
  215. {
  216. check[j-4] = board[i][j];
  217. j++;
  218. }
  219.  
  220. if(check[0] == 1 && check[1] == 1 && check[2] == 1 && check[3] == 1)
  221. {
  222. printf("Player 1 wins!");
  223. break;
  224. }
  225. j = 1;
  226. for(i = 6; i>2; i--)
  227. {
  228. check[j-1] = board[i][j];
  229. j++;
  230. }
  231.  
  232. if(check[0] == 1 && check[1] == 1 && check[2] == 1 && check[3] == 1)
  233. {
  234. printf("Player 1 wins!");
  235. break;
  236. }
  237. j = 2;
  238. for(i = 6; i>2; i--)
  239. {
  240. check[j-2] = board[i][j];
  241. j++;
  242. }
  243.  
  244. if(check[0] == 1 && check[1] == 1 && check[2] == 1 && check[3] == 1)
  245. {
  246. printf("Player 1 wins!");
  247. break;
  248. }
  249. j=3;
  250. for(i = 6; i>2; i--)
  251. {
  252. check[j-3] = board[i][j];
  253. j++;
  254. }
  255.  
  256. if(check[0] == 1 && check[1] == 1 && check[2] == 1 && check[3] == 1)
  257. {
  258. printf("Player 1 wins!");
  259. break;
  260. }
  261. j=4;
  262. for(i = 6; i>2; i--)
  263. {
  264. check[j-4] = board[i][j];
  265. j++;
  266. }
  267.  
  268. if(check[0] == 1 && check[1] == 1 && check[2] == 1 && check[3] == 1)
  269. {
  270. printf("Player 1 wins!");
  271. break;
  272. }
  273. j=4;
  274. for(i = 4; i>0;i--)
  275. {
  276. check[4-j]=board[i][j];
  277. j--;
  278. }
  279. if(check[0] == 1 && check[1] == 1 && check[2] == 1 && check[3] == 1)
  280. {
  281. printf("Player 1 wins!");
  282. break;
  283. }
  284. j=5;
  285. for(i = 4; i>0;i--)
  286. {
  287. check[5-j]=board[i][j];
  288. j--;
  289. }
  290. if(check[0] == 1 && check[1] == 1 && check[2] == 1 && check[3] == 1)
  291. {
  292. printf("Player 1 wins!");
  293. break;
  294. }
  295. j=6;
  296. for(i = 4; i>0;i--)
  297. {
  298. check[6-j]=board[i][j];
  299. j--;
  300. }
  301. if(check[0] == 1 && check[1] == 1 && check[2] == 1 && check[3] == 1)
  302. {
  303. printf("Player 1 wins!");
  304. break;
  305. }
  306. j=7;
  307. for(i = 4; i>0;i--)
  308. {
  309. check[7-j]=board[i][j];
  310. j--;
  311. }
  312. if(check[0] == 1 && check[1] == 1 && check[2] == 1 && check[3] == 1)
  313. {
  314. printf("Player 1 wins!");
  315. break;
  316. }
  317. j=4;
  318. for(i = 5; i>1;i--)
  319. {
  320. check[4-j]=board[i][j];
  321. j--;
  322. }
  323. if(check[0] == 1 && check[1] == 1 && check[2] == 1 && check[3] == 1)
  324. {
  325. printf("Player 1 wins!");
  326. break;
  327. }
  328. j=5;
  329. for(i = 5; i>1;i--)
  330. {
  331. check[5-j]=board[i][j];
  332. j--;
  333. }
  334. if(check[0] == 1 && check[1] == 1 && check[2] == 1 && check[3] == 1)
  335. {
  336. printf("Player 1 wins!");
  337. break;
  338. }
  339. j=6;
  340. for(i = 5; i>1;i--)
  341. {
  342. check[6-j]=board[i][j];
  343. j--;
  344. }
  345. if(check[0] == 1 && check[1] == 1 && check[2] == 1 && check[3] == 1)
  346. {
  347. printf("Player 1 wins!");
  348. break;
  349. }
  350. j=7;
  351. for(i = 5; i>1;i--)
  352. {
  353. check[7-j]=board[i][j];
  354. j--;
  355. }
  356. if(check[0] == 1 && check[1] == 1 && check[2] == 1 && check[3] == 1)
  357. {
  358. printf("Player 1 wins!");
  359. break;
  360. }
  361. j=4;
  362. for(i = 6; i>2;i--)
  363. {
  364. check[4-j]=board[i][j];
  365. j--;
  366. }
  367. if(check[0] == 1 && check[1] == 1 && check[2] == 1 && check[3] == 1)
  368. {
  369. printf("Player 1 wins!");
  370. break;
  371. }
  372. j=5;
  373. for(i = 6; i>2;i--)
  374. {
  375. check[5-j]=board[i][j];
  376. j--;
  377. }
  378. if(check[0] == 1 && check[1] == 1 && check[2] == 1 && check[3] == 1)
  379. {
  380. printf("Player 1 wins!");
  381. break;
  382. }
  383. j=6;
  384. for(i = 6; i>2;i--)
  385. {
  386. check[6-j]=board[i][j];
  387. j--;
  388. }
  389. if(check[0] == 1 && check[1] == 1 && check[2] == 1 && check[3] == 1)
  390. {
  391. printf("Player 1 wins!");
  392. break;
  393. }
  394. j=7;
  395. for(i = 6; i>2;i--)
  396. {
  397. check[7-j]=board[i][j];
  398. j--;
  399. }
  400. if(check[0] == 1 && check[1] == 1 && check[2] == 1 && check[3] == 1)
  401. {
  402. printf("Player 1 wins!");
  403. break;
  404. }
  405. ////////////////////
  406. // Checking vertical wins //
  407. j = 1;
  408. for(i = 1; i < 5; i++)
  409. {
  410. check[i-1]= board[i][j];
  411. }
  412. if(check[0] == 1 && check[1] == 1 && check[2] == 1 && check[3] == 1)
  413. {
  414. printf("Player 1 wins!");
  415. break;
  416. }
  417. j = 2;
  418. for(i = 1; i < 5; i++)
  419. {
  420. check[i-1]= board[i][j];
  421. }
  422. if(check[0] == 1 && check[1] == 1 && check[2] == 1 && check[3] == 1)
  423. {
  424. printf("Player 1 wins!");
  425. break;
  426. }
  427. j = 3;
  428. for(i = 1; i < 5; i++)
  429. {
  430. check[i-1]= board[i][j];
  431. }
  432. if(check[0] == 1 && check[1] == 1 && check[2] == 1 && check[3] == 1)
  433. {
  434. printf("Player 1 wins!");
  435. break;
  436. }
  437. j = 4;
  438. for(i = 1; i < 5; i++)
  439. {
  440. check[i-1]= board[i][j];
  441. }
  442. if(check[0] == 1 && check[1] == 1 && check[2] == 1 && check[3] == 1)
  443. {
  444. printf("Player 1 wins!");
  445. break;
  446. }
  447. j = 5;
  448. for(i = 1; i < 5; i++)
  449. {
  450. check[i-1]= board[i][j];
  451. }
  452. if(check[0] == 1 && check[1] == 1 && check[2] == 1 && check[3] == 1)
  453. {
  454. printf("Player 1 wins!");
  455. break;
  456. }
  457. j = 6;
  458. for(i = 1; i < 5; i++)
  459. {
  460. check[i-1]= board[i][j];
  461. }
  462. if(check[0] == 1 && check[1] == 1 && check[2] == 1 && check[3] == 1)
  463. {
  464. printf("Player 1 wins!");
  465. break;
  466. }
  467. j = 7;
  468. for(i = 1; i < 5; i++)
  469. {
  470. check[i-1]= board[i][j];
  471. }
  472. if(check[0] == 1 && check[1] == 1 && check[2] == 1 && check[3] == 1)
  473. {
  474. printf("Player 1 wins!");
  475. break;
  476. }
  477. j = 1;
  478. for(i = 2; i < 6; i++)
  479. {
  480. check[i-2]= board[i][j];
  481. }
  482. if(check[0] == 1 && check[1] == 1 && check[2] == 1 && check[3] == 1)
  483. {
  484. printf("Player 1 wins!");
  485. break;
  486. }
  487. j = 2;
  488. for(i = 2; i < 6; i++)
  489. {
  490. check[i-2]= board[i][j];
  491. }
  492. if(check[0] == 1 && check[1] == 1 && check[2] == 1 && check[3] == 1)
  493. {
  494. printf("Player 1 wins!");
  495. break;
  496. }
  497. j = 3;
  498. for(i = 2; i < 6; i++)
  499. {
  500. check[i-2]= board[i][j];
  501. }
  502. if(check[0] == 1 && check[1] == 1 && check[2] == 1 && check[3] == 1)
  503. {
  504. printf("Player 1 wins!");
  505. break;
  506. }
  507. j = 4;
  508. for(i = 2; i < 6; i++)
  509. {
  510. check[i-2]= board[i][j];
  511. }
  512. if(check[0] == 1 && check[1] == 1 && check[2] == 1 && check[3] == 1)
  513. {
  514. printf("Player 1 wins!");
  515. break;
  516. }
  517. j = 5;
  518. for(i = 2; i < 6; i++)
  519. {
  520. check[i-2]= board[i][j];
  521. }
  522. if(check[0] == 1 && check[1] == 1 && check[2] == 1 && check[3] == 1)
  523. {
  524. printf("Player 1 wins!");
  525. break;
  526. }
  527. j = 6;
  528. for(i = 2; i < 6; i++)
  529. {
  530. check[i-2]= board[i][j];
  531. }
  532. if(check[0] == 1 && check[1] == 1 && check[2] == 1 && check[3] == 1)
  533. {
  534. printf("Player 1 wins!");
  535. break;
  536. }
  537. j = 7;
  538. for(i = 2; i < 6; i++)
  539. {
  540. check[i-2]= board[i][j];
  541. }
  542. if(check[0] == 1 && check[1] == 1 && check[2] == 1 && check[3] == 1)
  543. {
  544. printf("Player 1 wins!");
  545. break;
  546. }
  547. j = 1;
  548. for(i = 3; i < 7; i++)
  549. {
  550. check[i-3]= board[i][j];
  551. }
  552. if(check[0] == 1 && check[1] == 1 && check[2] == 1 && check[3] == 1)
  553. {
  554. printf("Player 1 wins!");
  555. break;
  556. }
  557. j = 2;
  558. for(i = 3; i < 7; i++)
  559. {
  560. check[i-3]= board[i][j];
  561. }
  562. if(check[0] == 1 && check[1] == 1 && check[2] == 1 && check[3] == 1)
  563. {
  564. printf("Player 1 wins!");
  565. break;
  566. }
  567. j = 3;
  568. for(i = 3; i < 7; i++)
  569. {
  570. check[i-3]= board[i][j];
  571. }
  572. if(check[0] == 1 && check[1] == 1 && check[2] == 1 && check[3] == 1)
  573. {
  574. printf("Player 1 wins!");
  575. break;
  576. }
  577. j = 4;
  578. for(i = 3; i < 7; i++)
  579. {
  580. check[i-3]= board[i][j];
  581. }
  582. if(check[0] == 1 && check[1] == 1 && check[2] == 1 && check[3] == 1)
  583. {
  584. printf("Player 1 wins!");
  585. break;
  586. }
  587. j = 5;
  588. for(i = 3; i < 7; i++)
  589. {
  590. check[i-3]= board[i][j];
  591. }
  592. if(check[0] == 1 && check[1] == 1 && check[2] == 1 && check[3] == 1)
  593. {
  594. printf("Player 1 wins!");
  595. break;
  596. }
  597. j = 6;
  598. for(i = 3; i < 7; i++)
  599. {
  600. check[i-3]= board[i][j];
  601. }
  602. if(check[0] == 1 && check[1] == 1 && check[2] == 1 && check[3] == 1)
  603. {
  604. printf("Player 1 wins!");
  605. break;
  606. }
  607. j = 7;
  608. for(i = 3; i < 7; i++)
  609. {
  610. check[i-3]= board[i][j];
  611. }
  612. if(check[0] == 1 && check[1] == 1 && check[2] == 1 && check[3] == 1)
  613. {
  614. printf("Player 1 wins!");
  615. break;
  616. }
  617. /////////////////////////////
  618. // Horizontal win checks //
  619. i = 1;
  620. for(j = 1; j < 5; j++)
  621. {
  622. check[j-1]= board[i][j];
  623. }
  624. if(check[0] == 1 && check[1] == 1 && check[2] == 1 && check[3] == 1)
  625. {
  626. printf("Player 1 wins!");
  627. break;
  628. }
  629. i = 2;
  630. for(j = 1; j < 5; j++)
  631. {
  632. check[j-1]= board[i][j];
  633. }
  634. if(check[0] == 1 && check[1] == 1 && check[2] == 1 && check[3] == 1)
  635. {
  636. printf("Player 1 wins!");
  637. break;
  638. }
  639. i = 3;
  640. for(j = 1; j < 5; j++)
  641. {
  642. check[j-1]= board[i][j];
  643. }
  644. if(check[0] == 1 && check[1] == 1 && check[2] == 1 && check[3] == 1)
  645. {
  646. printf("Player 1 wins!");
  647. break;
  648. }
  649. i = 4;
  650. for(j = 1; j < 5; j++)
  651. {
  652. check[j-1]= board[i][j];
  653. }
  654. if(check[0] == 1 && check[1] == 1 && check[2] == 1 && check[3] == 1)
  655. {
  656. printf("Player 1 wins!");
  657. break;
  658. }
  659. i = 5;
  660. for(j = 1; j < 5; j++)
  661. {
  662. check[j-1]= board[i][j];
  663. }
  664. if(check[0] == 1 && check[1] == 1 && check[2] == 1 && check[3] == 1)
  665. {
  666. printf("Player 1 wins!");
  667. break;
  668. }
  669. i = 6;
  670. for(j = 1; j < 5; j++)
  671. {
  672. check[j-1]= board[i][j];
  673. }
  674. if(check[0] == 1 && check[1] == 1 && check[2] == 1 && check[3] == 1)
  675. {
  676. printf("Player 1 wins!");
  677. break;
  678. }
  679. i = 1;
  680. for(j = 2; j < 6; j++)
  681. {
  682. check[j-2]= board[i][j];
  683. }
  684. if(check[0] == 1 && check[1] == 1 && check[2] == 1 && check[3] == 1)
  685. {
  686. printf("Player 1 wins!");
  687. break;
  688. }
  689. i = 2;
  690. for(j = 2; j < 6; j++)
  691. {
  692. check[j-2]= board[i][j];
  693. }
  694. if(check[0] == 1 && check[1] == 1 && check[2] == 1 && check[3] == 1)
  695. {
  696. printf("Player 1 wins!");
  697. break;
  698. }
  699. i = 3;
  700. for(j = 2; j < 6; j++)
  701. {
  702. check[j-2]= board[i][j];
  703. }
  704. if(check[0] == 1 && check[1] == 1 && check[2] == 1 && check[3] == 1)
  705. {
  706. printf("Player 1 wins!");
  707. break;
  708. }
  709. i = 4;
  710. for(j = 2; j < 6; j++)
  711. {
  712. check[j-2]= board[i][j];
  713. }
  714. if(check[0] == 1 && check[1] == 1 && check[2] == 1 && check[3] == 1)
  715. {
  716. printf("Player 1 wins!");
  717. break;
  718. }
  719. i = 5;
  720. for(j = 2; j < 6; j++)
  721. {
  722. check[j-2]= board[i][j];
  723. }
  724. if(check[0] == 1 && check[1] == 1 && check[2] == 1 && check[3] == 1)
  725. {
  726. printf("Player 1 wins!");
  727. break;
  728. }
  729. i = 6;
  730. for(j = 2; j < 6; j++)
  731. {
  732. check[j-2]= board[i][j];
  733. }
  734. if(check[0] == 1 && check[1] == 1 && check[2] == 1 && check[3] == 1)
  735. {
  736. printf("Player 1 wins!");
  737. break;
  738. }
  739. i = 1;
  740. for(j = 3; j < 7; j++)
  741. {
  742. check[j-3]= board[i][j];
  743. }
  744. if(check[0] == 1 && check[1] == 1 && check[2] == 1 && check[3] == 1)
  745. {
  746. printf("Player 1 wins!");
  747. break;
  748. }
  749. i = 2;
  750. for(j = 3; j < 7; j++)
  751. {
  752. check[j-3]= board[i][j];
  753. }
  754. if(check[0] == 1 && check[1] == 1 && check[2] == 1 && check[3] == 1)
  755. {
  756. printf("Player 1 wins!");
  757. break;
  758. }
  759. i = 3;
  760. for(j = 3; j < 7; j++)
  761. {
  762. check[j-3]= board[i][j];
  763. }
  764. if(check[0] == 1 && check[1] == 1 && check[2] == 1 && check[3] == 1)
  765. {
  766. printf("Player 1 wins!");
  767. break;
  768. }
  769. i = 4;
  770. for(j = 3; j < 7; j++)
  771. {
  772. check[j-3]= board[i][j];
  773. }
  774. if(check[0] == 1 && check[1] == 1 && check[2] == 1 && check[3] == 1)
  775. {
  776. printf("Player 1 wins!");
  777. break;
  778. }
  779. i = 5;
  780. for(j = 3; j < 7; j++)
  781. {
  782. check[j-3]= board[i][j];
  783. }
  784. if(check[0] == 1 && check[1] == 1 && check[2] == 1 && check[3] == 1)
  785. {
  786. printf("Player 1 wins!");
  787. break;
  788. }
  789. i = 6;
  790. for(j = 3; j < 7; j++)
  791. {
  792. check[j-3]= board[i][j];
  793. }
  794. if(check[0] == 1 && check[1] == 1 && check[2] == 1 && check[3] == 1)
  795. {
  796. printf("Player 1 wins!");
  797. break;
  798. }
  799. i = 1;
  800. for(j = 4; j < 8; j++)
  801. {
  802. check[j-4]= board[i][j];
  803. }
  804. if(check[0] == 1 && check[1] == 1 && check[2] == 1 && check[3] == 1)
  805. {
  806. printf("Player 1 wins!");
  807. break;
  808. }
  809. i = 2;
  810. for(j = 4; j < 8; j++)
  811. {
  812. check[j-4]= board[i][j];
  813. }
  814. if(check[0] == 1 && check[1] == 1 && check[2] == 1 && check[3] == 1)
  815. {
  816. printf("Player 1 wins!");
  817. break;
  818. }
  819. i = 3;
  820. for(j = 4; j < 8; j++)
  821. {
  822. check[j-4]= board[i][j];
  823. }
  824. if(check[0] == 1 && check[1] == 1 && check[2] == 1 && check[3] == 1)
  825. {
  826. printf("Player 1 wins!");
  827. break;
  828. }
  829. i = 4;
  830. for(j = 4; j < 8; j++)
  831. {
  832. check[j-4]= board[i][j];
  833. }
  834. if(check[0] == 1 && check[1] == 1 && check[2] == 1 && check[3] == 1)
  835. {
  836. printf("Player 1 wins!");
  837. break;
  838. }
  839. i = 5;
  840. for(j = 4; j < 8; j++)
  841. {
  842. check[j-4]= board[i][j];
  843. }
  844. if(check[0] == 1 && check[1] == 1 && check[2] == 1 && check[3] == 1)
  845. {
  846. printf("Player 1 wins!");
  847. break;
  848. }
  849. i = 6;
  850. for(j = 4; j < 8; j++)
  851. {
  852. check[j-4]= board[i][j];
  853. }
  854. if(check[0] == 1 && check[1] == 1 && check[2] == 1 && check[3] == 1)
  855. {
  856. printf("Player 1 wins!");
  857. break;
  858. }
  859. //////////////////////
  860.  
  861. // Player 1 turn has ended //
  862.  
  863. // Collect player 2 input // PLAYER 2 //
  864. int input2;
  865. printf("Player 2, please enter a column from 1 to 7 to drop your piece into.\n");
  866. scanf(" %d ", &input2);
  867. //////////////////////////////////////
  868.  
  869. // Checking in player 2's input is valid //
  870. while(input2 > 7)
  871. {
  872. printf("The comlumn you have chosen does not exist, please choose a different column.\n");
  873. scanf(" %d ", &input2);
  874. }
  875.  
  876. while(input2 < 1)
  877. {
  878. printf("The comlumn you have chosen does not exist, please choose a different column.\n");
  879. scanf(" %d ", &input2);
  880. }
  881.  
  882. while(board[1][input2] != 0)
  883. {
  884. printf("The comlumn you have chosen is full, please choose a different column.\n");
  885. scanf(" %d ", &input2);
  886.  
  887. }
  888. /////////////////////////////
  889.  
  890. // Application of player2 choice //
  891. printf("Player 2 chose column %d.\n", input2);
  892. if(board[6][input2] == 0)
  893. {
  894. board[6][input2] = 2;
  895. }
  896. else
  897. {
  898. if(board[5][input2] == 0)
  899. {
  900. board[5][input2] = 2;
  901. }
  902. else
  903. {
  904. if(board[4][input2] == 0)
  905. {
  906. board[4][input2] = 2;
  907. }
  908. else
  909. {
  910. if(board[3][input2] == 0)
  911. {
  912. board[3][input2] = 2;
  913. }
  914. else
  915. {
  916. if(board[2][input2] == 0)
  917. {
  918. board[2][input2] = 2;
  919. }
  920. else
  921. {
  922. board[1][input2] = 2;
  923. }
  924. }
  925. }
  926. }
  927. }
  928. printf(" 1 2 3 4 5 6 7\n");
  929. printf("\n");
  930. for(int r = 1; r < 7; r++)
  931. {
  932. for(int c = 1; c < 8; c++ )
  933. {
  934. printf(" %d ",board[r][c]);
  935. }
  936. printf("\n");
  937. }
  938. ////////////////////////////////
  939.  
  940. // Checking Player 2 win //
  941. // Checking diagonal wins //
  942. j = 1;
  943. for(i = 4; i>0; i--)
  944. {
  945. check[j-1] = board[i][j];
  946. j++;
  947. }
  948.  
  949. if(check[0] == 2 && check[1] == 2 && check[2] == 2 && check[3] == 2)
  950. {
  951. printf("Player 2 wins!");
  952. break;
  953. }
  954. j = 2;
  955. for(i = 4; i>0; i--)
  956. {
  957. check[j-2] = board[i][j];
  958. j++;
  959. }
  960.  
  961. if(check[0] == 2 && check[1] == 2 && check[2] == 2 && check[3] == 2)
  962. {
  963. printf("Player 2 wins!");
  964. break;
  965. }
  966. j=3;
  967. for(i = 4; i>0; i--)
  968. {
  969. check[j-3] = board[i][j];
  970. j++;
  971. }
  972.  
  973. if(check[0] == 2 && check[1] == 2 && check[2] == 2 && check[3] == 2)
  974. {
  975. printf("Player 2 wins!");
  976. break;
  977. }
  978. j=4;
  979. for(i = 4; i>0; i--)
  980. {
  981. check[j-4] = board[i][j];
  982. j++;
  983. }
  984.  
  985. if(check[0] == 2 && check[1] == 2 && check[2] == 2 && check[3] == 2)
  986. {
  987. printf("Player 2 wins!");
  988. break;
  989. }
  990. j = 1;
  991. for(i = 5; i>1; i--)
  992. {
  993. check[j-1] = board[i][j];
  994. j++;
  995. }
  996.  
  997. if(check[0] == 2 && check[1] == 2 && check[2] == 2 && check[3] == 2)
  998. {
  999. printf("Player 2 wins!");
  1000. break;
  1001. }
  1002. j = 2;
  1003. for(i = 5; i>1; i--)
  1004. {
  1005. check[j-2] = board[i][j];
  1006. j++;
  1007. }
  1008.  
  1009. if(check[0] == 2 && check[1] == 2 && check[2] == 2 && check[3] == 2)
  1010. {
  1011. printf("Player 2 wins!");
  1012. break;
  1013. }
  1014. j=3;
  1015. for(i = 5; i>1; i--)
  1016. {
  1017. check[j-3] = board[i][j];
  1018. j++;
  1019. }
  1020.  
  1021. if(check[0] == 2 && check[1] == 2 && check[2] == 2 && check[3] == 2)
  1022. {
  1023. printf("Player 2 wins!");
  1024. break;
  1025. }
  1026. j=4;
  1027. for(i = 5; i>1; i--)
  1028. {
  1029. check[j-4] = board[i][j];
  1030. j++;
  1031. }
  1032.  
  1033. if(check[0] == 2 && check[1] == 2 && check[2] == 2 && check[3] == 2)
  1034. {
  1035. printf("Player 2 wins!");
  1036. break;
  1037. }
  1038. j = 1;
  1039. for(i = 6; i>2; i--)
  1040. {
  1041. check[j-1] = board[i][j];
  1042. j++;
  1043. }
  1044.  
  1045. if(check[0] == 2 && check[1] == 2 && check[2] == 2 && check[3] == 2)
  1046. {
  1047. printf("Player 2 wins!");
  1048. break;
  1049. }
  1050. j = 2;
  1051. for(i = 6; i>2; i--)
  1052. {
  1053. check[j-2] = board[i][j];
  1054. j++;
  1055. }
  1056.  
  1057. if(check[0] == 2 && check[1] == 2 && check[2] == 2 && check[3] == 2)
  1058. {
  1059. printf("Player 2 wins!");
  1060. break;
  1061. }
  1062. j=3;
  1063. for(i = 6; i>2; i--)
  1064. {
  1065. check[j-3] = board[i][j];
  1066. j++;
  1067. }
  1068.  
  1069. if(check[0] == 2 && check[1] == 2 && check[2] == 2 && check[3] == 2)
  1070. {
  1071. printf("Player 2 wins!");
  1072. break;
  1073. }
  1074. j=4;
  1075. for(i = 6; i>2; i--)
  1076. {
  1077. check[j-4] = board[i][j];
  1078. j++;
  1079. }
  1080.  
  1081. if(check[0] == 2 && check[1] == 2 && check[2] == 2 && check[3] == 2)
  1082. {
  1083. printf("Player 2 wins!");
  1084. break;
  1085. }
  1086. j=4;
  1087. for(i = 4; i>0;i--)
  1088. {
  1089. check[4-j]=board[i][j];
  1090. j--;
  1091. }
  1092. if(check[0] == 2 && check[1] == 2 && check[2] == 2 && check[3] == 2)
  1093. {
  1094. printf("Player 2 wins!");
  1095. break;
  1096. }
  1097. j=5;
  1098. for(i = 4; i>0;i--)
  1099. {
  1100. check[5-j]=board[i][j];
  1101. j--;
  1102. }
  1103. if(check[0] == 2 && check[1] == 2 && check[2] == 2 && check[3] == 2)
  1104. {
  1105. printf("Player 2 wins!");
  1106. break;
  1107. }
  1108. j=6;
  1109. for(i = 4; i>0;i--)
  1110. {
  1111. check[6-j]=board[i][j];
  1112. j--;
  1113. }
  1114. if(check[0] == 2 && check[1] == 2 && check[2] == 2 && check[3] == 2)
  1115. {
  1116. printf("Player 2 wins!");
  1117. break;
  1118. }
  1119. j=7;
  1120. for(i = 4; i>0;i--)
  1121. {
  1122. check[7-j]=board[i][j];
  1123. j--;
  1124. }
  1125. if(check[0] == 2 && check[1] == 2 && check[2] == 2 && check[3] == 2)
  1126. {
  1127. printf("Player 2 wins!");
  1128. break;
  1129. }
  1130. j=4;
  1131. for(i = 5; i>1;i--)
  1132. {
  1133. check[4-j]=board[i][j];
  1134. j--;
  1135. }
  1136. if(check[0] == 2 && check[1] == 2 && check[2] == 2 && check[3] == 2)
  1137. {
  1138. printf("Player 2 wins!");
  1139. break;
  1140. }
  1141. j=5;
  1142. for(i = 5; i>1;i--)
  1143. {
  1144. check[5-j]=board[i][j];
  1145. j--;
  1146. }
  1147. if(check[0] == 2 && check[1] == 2 && check[2] == 2 && check[3] == 2)
  1148. {
  1149. printf("Player 2 wins!");
  1150. break;
  1151. }
  1152. j=6;
  1153. for(i = 5; i>1;i--)
  1154. {
  1155. check[6-j]=board[i][j];
  1156. j--;
  1157. }
  1158. if(check[0] == 2 && check[1] == 2 && check[2] == 2 && check[3] == 2)
  1159. {
  1160. printf("Player 2 wins!");
  1161. break;
  1162. }
  1163. j=7;
  1164. for(i = 5; i>1;i--)
  1165. {
  1166. check[7-j]=board[i][j];
  1167. j--;
  1168. }
  1169. if(check[0] == 2 && check[1] == 2 && check[2] == 2 && check[3] == 2)
  1170. {
  1171. printf("Player 2 wins!");
  1172. break;
  1173. }
  1174. j=4;
  1175. for(i = 6; i>2;i--)
  1176. {
  1177. check[4-j]=board[i][j];
  1178. j--;
  1179. }
  1180. if(check[0] == 2 && check[1] == 2 && check[2] == 2 && check[3] == 2)
  1181. {
  1182. printf("Player 2 wins!");
  1183. break;
  1184. }
  1185. j=5;
  1186. for(i = 6; i>2;i--)
  1187. {
  1188. check[5-j]=board[i][j];
  1189. j--;
  1190. }
  1191. if(check[0] == 2 && check[1] == 2 && check[2] == 2 && check[3] == 2)
  1192. {
  1193. printf("Player 2 wins!");
  1194. break;
  1195. }
  1196. j=6;
  1197. for(i = 6; i>2;i--)
  1198. {
  1199. check[6-j]=board[i][j];
  1200. j--;
  1201. }
  1202. if(check[0] == 2 && check[1] == 2 && check[2] == 2 && check[3] == 2)
  1203. {
  1204. printf("Player 2 wins!");
  1205. break;
  1206. }
  1207. j=7;
  1208. for(i = 6; i>2;i--)
  1209. {
  1210. check[7-j]=board[i][j];
  1211. j--;
  1212. }
  1213. if(check[0] == 2 && check[1] == 2 && check[2] == 2 && check[3] == 2)
  1214. {
  1215. printf("Player 2 wins!");
  1216. break;
  1217. }
  1218. ////////////////////
  1219. // Vertical win check //
  1220. j = 1;
  1221. for(i = 1; i < 5; i++)
  1222. {
  1223. check[i-1]= board[i][j];
  1224. }
  1225. if(check[0] == 2 && check[1] == 2 && check[2] == 2 && check[3] == 2)
  1226. {
  1227. printf("Player 2 wins!");
  1228. break;
  1229. }
  1230. j = 2;
  1231. for(i = 1; i < 5; i++)
  1232. {
  1233. check[i-1]= board[i][j];
  1234. }
  1235. if(check[0] == 2 && check[1] == 2 && check[2] == 2 && check[3] == 2)
  1236. {
  1237. printf("Player 2 wins!");
  1238. break;
  1239. }
  1240. j = 3;
  1241. for(i = 1; i < 5; i++)
  1242. {
  1243. check[i-1]= board[i][j];
  1244. }
  1245. if(check[0] == 2 && check[1] == 2 && check[2] == 2 && check[3] == 2)
  1246. {
  1247. printf("Player 2 wins!");
  1248. break;
  1249. }
  1250. j = 4;
  1251. for(i = 1; i < 5; i++)
  1252. {
  1253. check[i-1]= board[i][j];
  1254. }
  1255. if(check[0] == 2 && check[1] == 2 && check[2] == 2 && check[3] == 2)
  1256. {
  1257. printf("Player 2 wins!");
  1258. break;
  1259. }
  1260. j = 5;
  1261. for(i = 1; i < 5; i++)
  1262. {
  1263. check[i-1]= board[i][j];
  1264. }
  1265. if(check[0] == 2 && check[1] == 2 && check[2] == 2 && check[3] == 2)
  1266. {
  1267. printf("Player 2 wins!");
  1268. break;
  1269. }
  1270. j = 6;
  1271. for(i = 1; i < 5; i++)
  1272. {
  1273. check[i-1]= board[i][j];
  1274. }
  1275. if(check[0] == 2 && check[1] == 2 && check[2] == 2 && check[3] == 2)
  1276. {
  1277. printf("Player 2 wins!");
  1278. break;
  1279. }
  1280. j = 7;
  1281. for(i = 1; i < 5; i++)
  1282. {
  1283. check[i-1]= board[i][j];
  1284. }
  1285. if(check[0] == 2 && check[1] == 2 && check[2] == 2 && check[3] == 2)
  1286. {
  1287. printf("Player 2 wins!");
  1288. break;
  1289. }
  1290. j = 1;
  1291. for(i = 2; i < 6; i++)
  1292. {
  1293. check[i-2]= board[i][j];
  1294. }
  1295. if(check[0] == 2 && check[1] == 2 && check[2] == 2 && check[3] == 2)
  1296. {
  1297. printf("Player 2 wins!");
  1298. break;
  1299. }
  1300. j = 2;
  1301. for(i = 2; i < 6; i++)
  1302. {
  1303. check[i-2]= board[i][j];
  1304. }
  1305. if(check[0] == 2 && check[1] == 2 && check[2] == 2 && check[3] == 2)
  1306. {
  1307. printf("Player 2 wins!");
  1308. break;
  1309. }
  1310. j = 3;
  1311. for(i = 2; i < 6; i++)
  1312. {
  1313. check[i-2]= board[i][j];
  1314. }
  1315. if(check[0] == 2 && check[1] == 2 && check[2] == 2 && check[3] == 2)
  1316. {
  1317. printf("Player 2 wins!");
  1318. break;
  1319. }
  1320. j = 4;
  1321. for(i = 2; i < 6; i++)
  1322. {
  1323. check[i-2]= board[i][j];
  1324. }
  1325. if(check[0] == 2 && check[1] == 2 && check[2] == 2 && check[3] == 2)
  1326. {
  1327. printf("Player 2 wins!");
  1328. break;
  1329. }
  1330. j = 5;
  1331. for(i = 2; i < 6; i++)
  1332. {
  1333. check[i-2]= board[i][j];
  1334. }
  1335. if(check[0] == 2 && check[1] == 2 && check[2] == 2 && check[3] == 2)
  1336. {
  1337. printf("Player 2 wins!");
  1338. break;
  1339. }
  1340. j = 6;
  1341. for(i = 2; i < 6; i++)
  1342. {
  1343. check[i-2]= board[i][j];
  1344. }
  1345. if(check[0] == 2 && check[1] == 2 && check[2] == 2 && check[3] == 2)
  1346. {
  1347. printf("Player 2 wins!");
  1348. break;
  1349. }
  1350. j = 7;
  1351. for(i = 2; i < 6; i++)
  1352. {
  1353. check[i-2]= board[i][j];
  1354. }
  1355. if(check[0] == 2 && check[1] == 2 && check[2] == 2 && check[3] == 2)
  1356. {
  1357. printf("Player 2 wins!");
  1358. break;
  1359. }
  1360. j = 1;
  1361. for(i = 3; i < 7; i++)
  1362. {
  1363. check[i-3]= board[i][j];
  1364. }
  1365. if(check[0] == 2 && check[1] == 2 && check[2] == 2 && check[3] == 2)
  1366. {
  1367. printf("Player 2 wins!");
  1368. break;
  1369. }
  1370. j = 2;
  1371. for(i = 3; i < 7; i++)
  1372. {
  1373. check[i-3]= board[i][j];
  1374. }
  1375. if(check[0] == 2 && check[1] == 2 && check[2] == 2 && check[3] == 2)
  1376. {
  1377. printf("Player 2 wins!");
  1378. break;
  1379. }
  1380. j = 3;
  1381. for(i = 3; i < 7; i++)
  1382. {
  1383. check[i-3]= board[i][j];
  1384. }
  1385. if(check[0] == 2 && check[1] == 2 && check[2] == 2 && check[3] == 2)
  1386. {
  1387. printf("Player 2 wins!");
  1388. break;
  1389. }
  1390. j = 4;
  1391. for(i = 3; i < 7; i++)
  1392. {
  1393. check[i-3]= board[i][j];
  1394. }
  1395. if(check[0] == 2 && check[1] == 2 && check[2] == 2 && check[3] == 2)
  1396. {
  1397. printf("Player 2 wins!");
  1398. break;
  1399. }
  1400. j = 5;
  1401. for(i = 3; i < 7; i++)
  1402. {
  1403. check[i-3]= board[i][j];
  1404. }
  1405. if(check[0] == 2 && check[1] == 2 && check[2] == 2 && check[3] == 2)
  1406. {
  1407. printf("Player 2 wins!");
  1408. break;
  1409. }
  1410. j = 6;
  1411. for(i = 3; i < 7; i++)
  1412. {
  1413. check[i-3]= board[i][j];
  1414. }
  1415. if(check[0] == 2 && check[1] == 2 && check[2] == 2 && check[3] == 2)
  1416. {
  1417. printf("Player 2 wins!");
  1418. break;
  1419. }
  1420. j = 7;
  1421. for(i = 3; i < 7; i++)
  1422. {
  1423. check[i-3]= board[i][j];
  1424. }
  1425. if(check[0] == 2 && check[1] == 2 && check[2] == 2 && check[3] == 2)
  1426. {
  1427. printf("Player 2 wins!");
  1428. break;
  1429. }
  1430. //////////////////////////
  1431. // Horizontal win checks //
  1432. i = 1;
  1433. for(j = 1; j < 5; j++)
  1434. {
  1435. check[j-1]= board[i][j];
  1436. }
  1437. if(check[0] == 2 && check[1] == 2 && check[2] == 2 && check[3] == 2)
  1438. {
  1439. printf("Player 2 wins!");
  1440. break;
  1441. }
  1442. i = 2;
  1443. for(j = 1; j < 5; j++)
  1444. {
  1445. check[j-1]= board[i][j];
  1446. }
  1447. if(check[0] == 2 && check[1] == 2 && check[2] == 2 && check[3] == 2)
  1448. {
  1449. printf("Player 2 wins!");
  1450. break;
  1451. }
  1452. i = 3;
  1453. for(j = 1; j < 5; j++)
  1454. {
  1455. check[j-1]= board[i][j];
  1456. }
  1457. if(check[0] == 2 && check[1] == 2 && check[2] == 2 && check[3] == 2)
  1458. {
  1459. printf("Player 2 wins!");
  1460. break;
  1461. }
  1462. i = 4;
  1463. for(j = 1; j < 5; j++)
  1464. {
  1465. check[j-1]= board[i][j];
  1466. }
  1467. if(check[0] == 2 && check[1] == 2 && check[2] == 2 && check[3] == 2)
  1468. {
  1469. printf("Player 2 wins!");
  1470. break;
  1471. }
  1472. i = 5;
  1473. for(j = 1; j < 5; j++)
  1474. {
  1475. check[j-1]= board[i][j];
  1476. }
  1477. if(check[0] == 2 && check[1] == 2 && check[2] == 2 && check[3] == 2)
  1478. {
  1479. printf("Player 2 wins!");
  1480. break;
  1481. }
  1482. i = 6;
  1483. for(j = 1; j < 5; j++)
  1484. {
  1485. check[j-1]= board[i][j];
  1486. }
  1487. if(check[0] == 2 && check[1] == 2 && check[2] == 2 && check[3] == 2)
  1488. {
  1489. printf("Player 2 wins!");
  1490. break;
  1491. }
  1492. i = 1;
  1493. for(j = 2; j < 6; j++)
  1494. {
  1495. check[j-2]= board[i][j];
  1496. }
  1497. if(check[0] == 2 && check[1] == 2 && check[2] == 2 && check[3] == 2)
  1498. {
  1499. printf("Player 2 wins!");
  1500. break;
  1501. }
  1502. i = 2;
  1503. for(j = 2; j < 6; j++)
  1504. {
  1505. check[j-2]= board[i][j];
  1506. }
  1507. if(check[0] == 2 && check[1] == 2 && check[2] == 2 && check[3] == 2)
  1508. {
  1509. printf("Player 2 wins!");
  1510. break;
  1511. }
  1512. i = 3;
  1513. for(j = 2; j < 6; j++)
  1514. {
  1515. check[j-2]= board[i][j];
  1516. }
  1517. if(check[0] == 2 && check[1] == 2 && check[2] == 2 && check[3] == 2)
  1518. {
  1519. printf("Player 2 wins!");
  1520. break;
  1521. }
  1522. i = 4;
  1523. for(j = 2; j < 6; j++)
  1524. {
  1525. check[j-2]= board[i][j];
  1526. }
  1527. if(check[0] == 2 && check[1] == 2 && check[2] == 2 && check[3] == 2)
  1528. {
  1529. printf("Player 2 wins!");
  1530. break;
  1531. }
  1532. i = 5;
  1533. for(j = 2; j < 6; j++)
  1534. {
  1535. check[j-2]= board[i][j];
  1536. }
  1537. if(check[0] == 2 && check[1] == 2 && check[2] == 2 && check[3] == 2)
  1538. {
  1539. printf("Player 2 wins!");
  1540. break;
  1541. }
  1542. i = 6;
  1543. for(j = 2; j < 6; j++)
  1544. {
  1545. check[j-2]= board[i][j];
  1546. }
  1547. if(check[0] == 2 && check[1] == 2 && check[2] == 2 && check[3] == 2)
  1548. {
  1549. printf("Player 2 wins!");
  1550. break;
  1551. }
  1552. i = 1;
  1553. for(j = 3; j < 7; j++)
  1554. {
  1555. check[j-3]= board[i][j];
  1556. }
  1557. if(check[0] == 2 && check[1] == 2 && check[2] == 2 && check[3] == 2)
  1558. {
  1559. printf("Player 2 wins!");
  1560. break;
  1561. }
  1562. i = 2;
  1563. for(j = 3; j < 7; j++)
  1564. {
  1565. check[j-3]= board[i][j];
  1566. }
  1567. if(check[0] == 2 && check[1] == 2 && check[2] == 2 && check[3] == 2)
  1568. {
  1569. printf("Player 2 wins!");
  1570. break;
  1571. }
  1572. i = 3;
  1573. for(j = 3; j < 7; j++)
  1574. {
  1575. check[j-3]= board[i][j];
  1576. }
  1577. if(check[0] == 2 && check[1] == 2 && check[2] == 2 && check[3] == 2)
  1578. {
  1579. printf("Player 2 wins!");
  1580. break;
  1581. }
  1582. i = 4;
  1583. for(j = 3; j < 7; j++)
  1584. {
  1585. check[j-3]= board[i][j];
  1586. }
  1587. if(check[0] == 2 && check[1] == 2 && check[2] == 2 && check[3] == 2)
  1588. {
  1589. printf("Player 2 wins!");
  1590. break;
  1591. }
  1592. i = 5;
  1593. for(j = 3; j < 7; j++)
  1594. {
  1595. check[j-3]= board[i][j];
  1596. }
  1597. if(check[0] == 2 && check[1] == 2 && check[2] == 2 && check[3] == 2)
  1598. {
  1599. printf("Player 2 wins!");
  1600. break;
  1601. }
  1602. i = 6;
  1603. for(j = 3; j < 7; j++)
  1604. {
  1605. check[j-3]= board[i][j];
  1606. }
  1607. if(check[0] == 2 && check[1] == 2 && check[2] == 2 && check[3] == 2)
  1608. {
  1609. printf("Player 2 wins!");
  1610. break;
  1611. }
  1612. i = 1;
  1613. for(j = 4; j < 8; j++)
  1614. {
  1615. check[j-4]= board[i][j];
  1616. }
  1617. if(check[0] == 2 && check[1] == 2 && check[2] == 2 && check[3] == 2)
  1618. {
  1619. printf("Player 2 wins!");
  1620. break;
  1621. }
  1622. i = 2;
  1623. for(j = 4; j < 8; j++)
  1624. {
  1625. check[j-4]= board[i][j];
  1626. }
  1627. if(check[0] == 2 && check[1] == 2 && check[2] == 2 && check[3] == 2)
  1628. {
  1629. printf("Player 2 wins!");
  1630. break;
  1631. }
  1632. i = 3;
  1633. for(j = 4; j < 8; j++)
  1634. {
  1635. check[j-4]= board[i][j];
  1636. }
  1637. if(check[0] == 2 && check[1] == 2 && check[2] == 2 && check[3] == 2)
  1638. {
  1639. printf("Player 2 wins!");
  1640. break;
  1641. }
  1642. i = 4;
  1643. for(j = 4; j < 8; j++)
  1644. {
  1645. check[j-4]= board[i][j];
  1646. }
  1647. if(check[0] == 2 && check[1] == 2 && check[2] == 2 && check[3] == 2)
  1648. {
  1649. printf("Player 2 wins!");
  1650. break;
  1651. }
  1652. i = 5;
  1653. for(j = 4; j < 8; j++)
  1654. {
  1655. check[j-4]= board[i][j];
  1656. }
  1657. if(check[0] == 2 && check[1] == 2 && check[2] == 2 && check[3] == 2)
  1658. {
  1659. printf("Player 2 wins!");
  1660. break;
  1661. }
  1662. i = 6;
  1663. for(j = 4; j < 8; j++)
  1664. {
  1665. check[j-4]= board[i][j];
  1666. }
  1667. if(check[0] == 2 && check[1] == 2 && check[2] == 2 && check[3] == 2)
  1668. {
  1669. printf("Player 2 wins!");
  1670. break;
  1671. }
  1672. //////////////////////
  1673.  
  1674.  
  1675.  
  1676.  
  1677.  
  1678.  
  1679.  
  1680.  
  1681. // Message for when all columns have been filled //
  1682. ticker++;
  1683. if(ticker == 21)
  1684. {
  1685. printf(" Draw! All columns are full.");
  1686. break;
  1687. }
  1688. /////////////////////////
  1689.  
  1690. }//main loop final
  1691.  
  1692.  
  1693. printf("\t Thank you for having fun with Connect Four! ");
  1694. return 0;
  1695. }
  1696.  
Success #stdin #stdout 0s 4280KB
stdin
1
4
6
7
3
4
0
9
5
5
5
6
4
2
3
4
5
7
8
9
6
5
43
3
4
5
6
7
8
8
6
5
4
3
2
2
1
2
stdout
||**||**||**||**||**||**||
||**||**||**||**||**||**||
||**||C O N N E C T ||**||
||**||   F O U R    ||**||
||**||**||**||**||**||**||
||**||**||**||**||**||**||


 1  2  3  4  5  6  7

 0  0  0  0  0  0  0 
 0  0  0  0  0  0  0 
 0  0  0  0  0  0  0 
 0  0  0  0  0  0  0 
 0  0  0  0  0  0  0 
 0  0  0  0  0  0  0 
Player 1, please enter a column from 1 to 7 to drop your piece into.
Player 1 chose column 1.
 1  2  3  4  5  6  7

 0  0  0  0  0  0  0 
 0  0  0  0  0  0  0 
 0  0  0  0  0  0  0 
 0  0  0  0  0  0  0 
 0  0  0  0  0  0  0 
 1  0  0  0  0  0  0 
Player 2, please enter a column from 1 to 7 to drop your piece into.
Player 2 chose column 4.
 1  2  3  4  5  6  7

 0  0  0  0  0  0  0 
 0  0  0  0  0  0  0 
 0  0  0  0  0  0  0 
 0  0  0  0  0  0  0 
 0  0  0  0  0  0  0 
 1  0  0  2  0  0  0 
Player 1, please enter a column from 1 to 7 to drop your piece into.
Player 1 chose column 6.
 1  2  3  4  5  6  7

 0  0  0  0  0  0  0 
 0  0  0  0  0  0  0 
 0  0  0  0  0  0  0 
 0  0  0  0  0  0  0 
 0  0  0  0  0  0  0 
 1  0  0  2  0  1  0 
Player 2, please enter a column from 1 to 7 to drop your piece into.
Player 2 chose column 7.
 1  2  3  4  5  6  7

 0  0  0  0  0  0  0 
 0  0  0  0  0  0  0 
 0  0  0  0  0  0  0 
 0  0  0  0  0  0  0 
 0  0  0  0  0  0  0 
 1  0  0  2  0  1  2 
Player 1, please enter a column from 1 to 7 to drop your piece into.
Player 1 chose column 3.
 1  2  3  4  5  6  7

 0  0  0  0  0  0  0 
 0  0  0  0  0  0  0 
 0  0  0  0  0  0  0 
 0  0  0  0  0  0  0 
 0  0  0  0  0  0  0 
 1  0  1  2  0  1  2 
Player 2, please enter a column from 1 to 7 to drop your piece into.
Player 2 chose column 4.
 1  2  3  4  5  6  7

 0  0  0  0  0  0  0 
 0  0  0  0  0  0  0 
 0  0  0  0  0  0  0 
 0  0  0  0  0  0  0 
 0  0  0  2  0  0  0 
 1  0  1  2  0  1  2 
Player 1, please enter a column from 1 to 7 to drop your piece into.
The comlumn you have chosen does not exist, please choose a different column.
Player 1 chose column 9.
 1  2  3  4  5  6  7

 0  0  0  0  0  0  0 
 0  0  0  0  0  0  0 
 0  0  0  0  0  0  0 
 0  0  0  0  0  0  0 
 0  0  0  2  0  0  0 
 1  0  1  2  0  1  2 
Player 2, please enter a column from 1 to 7 to drop your piece into.
Player 2 chose column 5.
 1  2  3  4  5  6  7

 0  0  0  0  0  0  0 
 0  0  0  0  0  0  0 
 0  0  0  0  0  0  0 
 0  0  0  0  0  0  0 
 0  0  0  2  0  0  0 
 1  0  1  2  2  1  2 
Player 1, please enter a column from 1 to 7 to drop your piece into.
Player 1 chose column 5.
 1  2  3  4  5  6  7

 0  0  0  0  0  0  0 
 0  0  0  0  0  0  0 
 0  0  0  0  0  0  0 
 0  0  0  0  0  0  0 
 0  0  0  2  1  0  0 
 1  0  1  2  2  1  2 
Player 2, please enter a column from 1 to 7 to drop your piece into.
Player 2 chose column 5.
 1  2  3  4  5  6  7

 0  0  0  0  0  0  0 
 0  0  0  0  0  0  0 
 0  0  0  0  0  0  0 
 0  0  0  0  2  0  0 
 0  0  0  2  1  0  0 
 1  0  1  2  2  1  2 
Player 1, please enter a column from 1 to 7 to drop your piece into.
Player 1 chose column 6.
 1  2  3  4  5  6  7

 0  0  0  0  0  0  0 
 0  0  0  0  0  0  0 
 0  0  0  0  0  0  0 
 0  0  0  0  2  0  0 
 0  0  0  2  1  1  0 
 1  0  1  2  2  1  2 
Player 2, please enter a column from 1 to 7 to drop your piece into.
Player 2 chose column 4.
 1  2  3  4  5  6  7

 0  0  0  0  0  0  0 
 0  0  0  0  0  0  0 
 0  0  0  0  0  0  0 
 0  0  0  2  2  0  0 
 0  0  0  2  1  1  0 
 1  0  1  2  2  1  2 
Player 1, please enter a column from 1 to 7 to drop your piece into.
Player 1 chose column 2.
 1  2  3  4  5  6  7

 0  0  0  0  0  0  0 
 0  0  0  0  0  0  0 
 0  0  0  0  0  0  0 
 0  0  0  2  2  0  0 
 0  0  0  2  1  1  0 
 1  1  1  2  2  1  2 
Player 2, please enter a column from 1 to 7 to drop your piece into.
Player 2 chose column 3.
 1  2  3  4  5  6  7

 0  0  0  0  0  0  0 
 0  0  0  0  0  0  0 
 0  0  0  0  0  0  0 
 0  0  0  2  2  0  0 
 0  0  2  2  1  1  0 
 1  1  1  2  2  1  2 
Player 1, please enter a column from 1 to 7 to drop your piece into.
Player 1 chose column 4.
 1  2  3  4  5  6  7

 0  0  0  0  0  0  0 
 0  0  0  0  0  0  0 
 0  0  0  1  0  0  0 
 0  0  0  2  2  0  0 
 0  0  2  2  1  1  0 
 1  1  1  2  2  1  2 
Player 2, please enter a column from 1 to 7 to drop your piece into.
Player 2 chose column 5.
 1  2  3  4  5  6  7

 0  0  0  0  0  0  0 
 0  0  0  0  0  0  0 
 0  0  0  1  2  0  0 
 0  0  0  2  2  0  0 
 0  0  2  2  1  1  0 
 1  1  1  2  2  1  2 
Player 1, please enter a column from 1 to 7 to drop your piece into.
Player 1 chose column 7.
 1  2  3  4  5  6  7

 0  0  0  0  0  0  0 
 0  0  0  0  0  0  0 
 0  0  0  1  2  0  0 
 0  0  0  2  2  0  0 
 0  0  2  2  1  1  1 
 1  1  1  2  2  1  2 
Player 2, please enter a column from 1 to 7 to drop your piece into.
The comlumn you have chosen does not exist, please choose a different column.
The comlumn you have chosen does not exist, please choose a different column.
Player 2 chose column 6.
 1  2  3  4  5  6  7

 0  0  0  0  0  0  0 
 0  0  0  0  0  0  0 
 0  0  0  1  2  0  0 
 0  0  0  2  2  2  0 
 0  0  2  2  1  1  1 
 1  1  1  2  2  1  2 
Player 1, please enter a column from 1 to 7 to drop your piece into.
Player 1 chose column 5.
 1  2  3  4  5  6  7

 0  0  0  0  0  0  0 
 0  0  0  0  1  0  0 
 0  0  0  1  2  0  0 
 0  0  0  2  2  2  0 
 0  0  2  2  1  1  1 
 1  1  1  2  2  1  2 
Player 2, please enter a column from 1 to 7 to drop your piece into.
The comlumn you have chosen does not exist, please choose a different column.
Player 2 chose column 3.
 1  2  3  4  5  6  7

 0  0  0  0  0  0  0 
 0  0  0  0  1  0  0 
 0  0  0  1  2  0  0 
 0  0  2  2  2  2  0 
 0  0  2  2  1  1  1 
 1  1  1  2  2  1  2 
Player 2 wins!	 Thank you for having fun with Connect Four!