SlideShare a Scribd company logo
I have to write a Connect Four game program. When a player takes their turn, they will select a
column in which to place a token. The token is placed at the top of the column and is allowed to
fall to the bottom, stacking on top of any previously placed tokens. Two players take turns placing
token colors of red or yellow. The first person to create four of their color token in a row,
horizontally or vertically, (NOT diagonally in this problem) wins and the game is over.
The program will display the board (7 columns and 6 rows), then ask for alternating players to
place a token in column 0 through 6. The process repeats until one player wins. You do not need
to check for a tie game, or if there is space in a chosen column.
The photos (shown below) contain the code for the game framework. It is required that I utilize
functions and write my code within the functions. The function signatures are provided for you in
the framework. Examine each one to see what will be needed by the end. I am given 2 functions to
start with: main() and display(board).
Part 1: Fill out the code for the placeToken function. It is given three parameters: (1) the board,
(2) the column in which to place a token, and (3) the token itself. The board is the two dimensional
list of characters, with spaces ' ' being empty locations. The column is a numerical index in which
to place the token, and the token is the character 'R' or 'Y'.
Start at the top row (index 0) and move down the rows until the row below is not ' ', then place the
token. Then return the row the token ended up in. You can test this out by running the program,
but the game won't end yet because the other functions are incomplete. Use control+C (command
+ C) to stop the game early.
Another way to approach this is to start at the bottom row and walk upwards until the space is ' '.
Part 2: Fill out the code for the winningMove function. The game is won if four tokens of the
same color line up either vertically or horizontally. Good functional design would have these
checks in their own functions. Fill in the code for winningMove such that it uses the 2 other check
functions (below). This function can be one line of code. The row and column parameters are the
location of the last move taken.
Part 3: Fill in the code for checkVertical, which checks for four in a line vertically (on the same
column) as the given row and column parameters. You only need to search outward from the row
and column parameters and not the whole board. Since new moves are controlled by gravity in
connect four, you only need to search downward. You can test if this is working by running the
program.
Part 4: Fill in the code for checkHorizontal, which checks for four in a line horizontally (on the
same row) as the given row and column parameters. You only need to search outward from the
row and column parameters and not the whole board. You can test if this is working by running the
program.
The last photo shows an example run.

More Related Content

PDF
Connect4.c2. Include the string.h header file3. Declare the foll.pdf
PDF
COnnect4Game
PDF
NO PAPER ANSWERS. ALL ANSWER SUBMISSIONS SHOULD BE ABLE TO RUN WIT.pdf
PPTX
PPT
Tic tac toe c++ programing
PDF
The following is my code for a connectn program. When I run my code .pdf
PDF
Proj1
PDF
Proj1
Connect4.c2. Include the string.h header file3. Declare the foll.pdf
COnnect4Game
NO PAPER ANSWERS. ALL ANSWER SUBMISSIONS SHOULD BE ABLE TO RUN WIT.pdf
Tic tac toe c++ programing
The following is my code for a connectn program. When I run my code .pdf
Proj1
Proj1

Similar to I have to write a Connect Four game program When a player t.pdf (20)

PPTX
tic-tac-toe: Game playing
PPTX
Real Life Uses of a Program (Tik Tok Toy Game) useing by C Programming
DOC
C++ projct
 
PDF
#In this project you will write a program play TicTacToe #using tw.pdf
PDF
#In this project you will write a program play TicTacToe #using tw.pdf
PDF
Advanced level school Python programming. Needs helps. thanks in.pdf
DOCX
This is an individual project, to be completed on your own. It i.docx
PPT
Tic tac toe on c++ project
DOCX
Artificial intelligence - python
PDF
AI CHALLENGE ADMIN
PDF
Please follow the data 1) For Line 23 In the IF - Condition yo.pdf
PDF
Please help with this. program must be written in C# .. All of the g.pdf
PDF
Description For this part of the assignment, you will create a Grid .pdf
DOCX
PROJECT(voting system, rock paper scissor, emoji creation , tick tack toe in ...
TXT
Tic tac toe
PDF
Write a C++ program which generates and displays a random walk acros.pdf
PDF
Artificial Intelligence Practical Manual.pdf
PPTX
python.pptx
PDF
P1
PDF
In Java using Eclipse, Im suppose to write a class that encapsulat.pdf
tic-tac-toe: Game playing
Real Life Uses of a Program (Tik Tok Toy Game) useing by C Programming
C++ projct
 
#In this project you will write a program play TicTacToe #using tw.pdf
#In this project you will write a program play TicTacToe #using tw.pdf
Advanced level school Python programming. Needs helps. thanks in.pdf
This is an individual project, to be completed on your own. It i.docx
Tic tac toe on c++ project
Artificial intelligence - python
AI CHALLENGE ADMIN
Please follow the data 1) For Line 23 In the IF - Condition yo.pdf
Please help with this. program must be written in C# .. All of the g.pdf
Description For this part of the assignment, you will create a Grid .pdf
PROJECT(voting system, rock paper scissor, emoji creation , tick tack toe in ...
Tic tac toe
Write a C++ program which generates and displays a random walk acros.pdf
Artificial Intelligence Practical Manual.pdf
python.pptx
P1
In Java using Eclipse, Im suppose to write a class that encapsulat.pdf
Ad

More from aayushmaany2k14 (20)

PDF
7 In pea plants round R is dominant to wrinkled r A h.pdf
PDF
7 In cats some are black some are orange and some are ca.pdf
PDF
7 You have just discovered a new fungal species from Yellow.pdf
PDF
7 Write the MIPS code to implement the for loop below Use .pdf
PDF
7 Given the diagram above describe the order of events in .pdf
PDF
7 Ontario Resources a natural energy supplier borrowed 8.pdf
PDF
7 Let XiiZ+1i2path dM263681c0701839752119c34.pdf
PDF
7 Essay What is the difference between efficiency and equ.pdf
PDF
7 What is most true about the following B2B promotional too.pdf
PDF
7 What do foxes and birds have in common a They are both .pdf
PDF
7 Using terms from the key on the right correctly identify.pdf
PDF
7 Using node 1 as the root perform a BFS for node 6 Detai.pdf
PDF
8 The residents of Elk Meadows and Valley View are experien.pdf
PDF
8 What would be the most possible interaction between the s.pdf
PDF
8 A unique structure in vertebrate embryos is the somite S.pdf
PDF
7 Kate has a utility function Uxy4xpath dM95702c.pdf
PDF
8 Protein synthesis begins when in the nucleus of each cell.pdf
PDF
729 David is going to purchase two stocks to form the initi.pdf
PDF
8 IPOsinitial public offerings of stockcreate billions of.pdf
PDF
8 Agreement and disagreement among economists Suppose that .pdf
7 In pea plants round R is dominant to wrinkled r A h.pdf
7 In cats some are black some are orange and some are ca.pdf
7 You have just discovered a new fungal species from Yellow.pdf
7 Write the MIPS code to implement the for loop below Use .pdf
7 Given the diagram above describe the order of events in .pdf
7 Ontario Resources a natural energy supplier borrowed 8.pdf
7 Let XiiZ+1i2path dM263681c0701839752119c34.pdf
7 Essay What is the difference between efficiency and equ.pdf
7 What is most true about the following B2B promotional too.pdf
7 What do foxes and birds have in common a They are both .pdf
7 Using terms from the key on the right correctly identify.pdf
7 Using node 1 as the root perform a BFS for node 6 Detai.pdf
8 The residents of Elk Meadows and Valley View are experien.pdf
8 What would be the most possible interaction between the s.pdf
8 A unique structure in vertebrate embryos is the somite S.pdf
7 Kate has a utility function Uxy4xpath dM95702c.pdf
8 Protein synthesis begins when in the nucleus of each cell.pdf
729 David is going to purchase two stocks to form the initi.pdf
8 IPOsinitial public offerings of stockcreate billions of.pdf
8 Agreement and disagreement among economists Suppose that .pdf
Ad

Recently uploaded (20)

PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
Microbial disease of the cardiovascular and lymphatic systems
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PPTX
Cell Structure & Organelles in detailed.
PPTX
Institutional Correction lecture only . . .
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
01-Introduction-to-Information-Management.pdf
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
Complications of Minimal Access Surgery at WLH
PDF
Computing-Curriculum for Schools in Ghana
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PPTX
Lesson notes of climatology university.
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
human mycosis Human fungal infections are called human mycosis..pptx
Microbial disease of the cardiovascular and lymphatic systems
Pharmacology of Heart Failure /Pharmacotherapy of CHF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
Module 4: Burden of Disease Tutorial Slides S2 2025
Cell Structure & Organelles in detailed.
Institutional Correction lecture only . . .
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
01-Introduction-to-Information-Management.pdf
Abdominal Access Techniques with Prof. Dr. R K Mishra
Complications of Minimal Access Surgery at WLH
Computing-Curriculum for Schools in Ghana
Final Presentation General Medicine 03-08-2024.pptx
VCE English Exam - Section C Student Revision Booklet
Anesthesia in Laparoscopic Surgery in India
Final Presentation General Medicine 03-08-2024.pptx
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Lesson notes of climatology university.

I have to write a Connect Four game program When a player t.pdf

  • 1. I have to write a Connect Four game program. When a player takes their turn, they will select a column in which to place a token. The token is placed at the top of the column and is allowed to fall to the bottom, stacking on top of any previously placed tokens. Two players take turns placing token colors of red or yellow. The first person to create four of their color token in a row, horizontally or vertically, (NOT diagonally in this problem) wins and the game is over. The program will display the board (7 columns and 6 rows), then ask for alternating players to place a token in column 0 through 6. The process repeats until one player wins. You do not need to check for a tie game, or if there is space in a chosen column. The photos (shown below) contain the code for the game framework. It is required that I utilize functions and write my code within the functions. The function signatures are provided for you in the framework. Examine each one to see what will be needed by the end. I am given 2 functions to start with: main() and display(board). Part 1: Fill out the code for the placeToken function. It is given three parameters: (1) the board, (2) the column in which to place a token, and (3) the token itself. The board is the two dimensional list of characters, with spaces ' ' being empty locations. The column is a numerical index in which to place the token, and the token is the character 'R' or 'Y'. Start at the top row (index 0) and move down the rows until the row below is not ' ', then place the token. Then return the row the token ended up in. You can test this out by running the program, but the game won't end yet because the other functions are incomplete. Use control+C (command + C) to stop the game early. Another way to approach this is to start at the bottom row and walk upwards until the space is ' '. Part 2: Fill out the code for the winningMove function. The game is won if four tokens of the same color line up either vertically or horizontally. Good functional design would have these checks in their own functions. Fill in the code for winningMove such that it uses the 2 other check functions (below). This function can be one line of code. The row and column parameters are the location of the last move taken. Part 3: Fill in the code for checkVertical, which checks for four in a line vertically (on the same column) as the given row and column parameters. You only need to search outward from the row and column parameters and not the whole board. Since new moves are controlled by gravity in connect four, you only need to search downward. You can test if this is working by running the program. Part 4: Fill in the code for checkHorizontal, which checks for four in a line horizontally (on the same row) as the given row and column parameters. You only need to search outward from the row and column parameters and not the whole board. You can test if this is working by running the program. The last photo shows an example run.