CS 0447代做、代写c/c++编程设计
CS 0447 Computer Organization and Assembly Language
Midterm Project – Connect 4
Introduction
In this project, you will implement a 2 player game in MIPS assembly: Connect 4 aka
Four-in-line. The game consists a board representing the play area. Two players face
each other and drop tokens, one at a time, until one of them manages to place four in
line!
Start early
The deadline will approach fast! Life happens, sickness happens, so if you start early,
you can minimize the impact. Do a little bit every day! 1 hour every day! 30 minutes
every day! SOMETHING!
Game mechanic
The game works like this:
1. Initially, the players have a blank board
2. Player 1 takes the first turn
Player 1, it's your turn.
Select a column to play. Must be between 0 and 6
-1
That play is invalid. Try again
Select a column to play. Must be between 0 and 6
7
That play is invalid. Try again
Select a column to play. Must be between 0 and 6
1
3. When a valid number is input, a token is placed in that column, at the
first (lowest) free position.
4. Next, it’s player 2 turn.
Player 2, it's your turn. Select a column to play. Must be between 0 and 6
5. The game ends when one of the players manages to place 4 tokens in
a horizontal, vertical, or diagonal line.
Congratulations player 1. You won!
Congratulations player 2. You won!
Your assignment
Plan
Plan your implementation which includes data structures you are planning to use,
user inputs that may be invalid and you need to account for, etc.
1. Think of which functions you will need to implement, and what they will do.
1) Start from the main function and split your program into multiple steps.
2) This plan is not going to be enforced, but it should be thought through.
2. Think of possible invalid user inputs, and how they will impact the program
negatively.
1) Board bounds.
2) Filling a column to the top.
Implement
Implement the MIPS assembly code that executes the game described above. Your
program will manage all interactions with the user and the board:
1. It begins by displaying a welcome message and an explanation of what the
user should do. How is the game played?
2. Print the empty board.
3. Then, the game begins, and your program will:
1) Ask player 1 to play:
▪ Ask and validate user input (MARS will crash if the user gives
no input or a letter, this is fine!)
▪ Don’t allow the user to select a non-existing tile.
▪ Don’t allow the user to select a full column.
▪ “Drop” the token into the board at the requested column. ▪ Check for a winning condition.
2) Ask player 2 to play:
▪ Ask and validate user input (MARS will crash if the user gives
no input or a letter, this is fine!)
▪ Don’t allow the user to select a non-existing tile!
▪ Don’t allow the user to select a full column!
▪ “Drop” the token into the board at the requested column.
▪ Check for a winning condition.
3) Repeat until one of the players wins or the board is full.
4. In the end, print a message letting the winning player know the game has
ended.
The welcome message
Bear in mind that you do your own thing, as long as it fits the project! So use the
welcome message to explain to the user exactly how it should play the game. Explain
the rules, and how the player can score points.
User input
Your program needs to ask the user in which column he/she wants to drop a token.
If the user inputs an invalid value, you inform the user of that and ask again.
You must validate the user input! The exact way you implement this is up to you. You
must ask the user to input something to select the column.
Representing the board
Feel free to implement all data structures that you need. However, it is suggested
you’d better use matrices. You can implement your board as a matrix of words to
keep the status of the game. Here is one suggestion:
board: .word
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
Note: The board refers only to the contents of the board, not the frame around the
tiles! The frame is always the same, it doesn’t need to be stored anywhere! If you
include the frame, it’ll make your life harder!
For the status of each tile, it is suggested to create a matrix of 0s (empty) 1s (player
1 tokens), and 2s (player 2 tokens). When you want to print each tile, you simply
need to check the status matrix to know if the tile was revealed.
if(board[i][j] == 0) { print('_') }
else if(board[i][j] == 1) { print('*') }
else { print('+') }
Check the example below:
The board - this is what you draw:
0 1 2 3 4 5 6
The matrix representing the board - contains 1s for player 1, and 2 player 2:
Board size
You can do one of two things: Easy route
The board should be a 7x6 matrix.
Configurable route
You can make it configurable if you so wish, and then adjust for difficulty. AT THE
TOP OF THE FILE! The simplest way is to name a number, like a #define in C. In
MARS you can do that like this:
.eqv BOARD_SIZE 42 # 7*6
.eqv BOARD_WIDTH 7
.eqv BOARD_HEIGHT 6
Then you can use the name instead of a number, i.e. in instructions that would
normally use a number (the code is nonsense, don’t use it):
lw $t0, 3($t1) -> lw $t0, N_PLAYS($t1)
li $t0, 3 -> li $t0, N_PLAYS
beq $t0, 3, _label -> beq $t0, N_PLAYS, _label
x: .word 3 -> x: .word N_PLAYS
arr: .word 0:100 -> arr: .word 0:BOARD_ELEMENTS
Or ask the user
Create variables, and ask what is the size of the board they want:
board_size: .word 42 # 7*6
board_width: .word 7
board_height: .word 6
Printing the board
The board must be shown to the user. Check the example below if you are not sure
how to proceed. The only requirement here is that Empty tiles must be empty, and
players should have different tokens to represent the tokens. The following
examples used an _ to represent empty tiles, * to represent “Player 1” tokens, and +
to represent “Player 2” tokens.
Ending the game
The game should end when one of the players successfully drops 4 tokens in line. At
that point, let the user know that the game has ended and who won. Example run
This is only an example. Feel free to ignore everything except functionality.
Welcome to connect-4 the MIPS version
This is a 2 player game, each player will take turns placing
a token.
The objective is to create a line of 4 consecutive tokens.
Good luck!
0 1 2 3 4 5 6
|_|_|_|_|_|_|_|
|_|_|_|_|_|_|_|
|_|_|_|_|_|_|_|
|_|_|_|_|_|_|_|
|_|_|_|_|_|_|_|
|_|_|_|_|_|_|_|
Select a column to play. Must be between 0 and 6
3
0 1 2 3 4 5 6
|_|_|_|_|_|_|_|
|_|_|_|_|_|_|_|
|_|_|_|_|_|_|_|
|_|_|_|_|_|_|_|
|_|_|_|_|_|_|_|
|_|_|_|*|_|_|_|
Select a column to play. Must be between 0 and 6
3
0 1 2 3 4 5 6
|_|_|_|_|_|_|_| |_|_|_|_|_|_|_|
|_|_|_|_|_|_|_|
|_|_|_|_|_|_|_|
|_|_|_|+|_|_|_|
|_|_|_|*|_|_|_|
Select a column to play. Must be between 0 and 6
4
0 1 2 3 4 5 6
|_|_|_|_|_|_|_|
|_|_|_|_|_|_|_|
|_|_|_|_|_|_|_|
|_|_|_|_|_|_|_|
|_|_|_|+|_|_|_|
|_|_|_|*|*|_|_|
Select a column to play. Must be between 0 and 6
5
0 1 2 3 4 5 6
|_|_|_|_|_|_|_|
|_|_|_|_|_|_|_|
|_|_|_|_|_|_|_|
|_|_|_|_|_|_|_|
|_|_|_|+|_|_|_|
|_|_|_|*|*|+|_|
Select a column to play. Must be between 0 and 6
2
0 1 2 3 4 5 6
|_|_|_|_|_|_|_| |_|_|_|_|_|_|_|
|_|_|_|_|_|_|_|
|_|_|_|_|_|_|_|
|_|_|_|+|_|_|_|
|_|_|*|*|*|+|_|
Select a column to play. Must be between 0 and 6
1
0 1 2 3 4 5 6
|_|_|_|_|_|_|_|
|_|_|_|_|_|_|_|
|_|_|_|_|_|_|_|
|_|_|_|_|_|_|_|
|_|_|_|+|_|_|_|
|_|+|*|*|*|+|_|
Select a column to play. Must be between 0 and 6
4
0 1 2 3 4 5 6
|_|_|_|_|_|_|_|
|_|_|_|_|_|_|_|
|_|_|_|_|_|_|_|
|_|_|_|_|_|_|_|
|_|_|_|+|*|_|_|
|_|+|*|*|*|+|_|
Select a column to play. Must be between 0 and 6
3
0 1 2 3 4 5 6
|_|_|_|_|_|_|_| |_|_|_|_|_|_|_|
|_|_|_|_|_|_|_|
|_|_|_|+|_|_|_|
|_|_|_|+|*|_|_|
|_|+|*|*|*|+|_|
Select a column to play. Must be between 0 and 6
5
0 1 2 3 4 5 6
|_|_|_|_|_|_|_|
|_|_|_|_|_|_|_|
|_|_|_|_|_|_|_|
|_|_|_|+|_|_|_|
|_|_|_|+|*|*|_|
|_|+|*|*|*|+|_|
Select a column to play. Must be between 0 and 6
2
0 1 2 3 4 5 6
|_|_|_|_|_|_|_|
|_|_|_|_|_|_|_|
|_|_|_|_|_|_|_|
|_|_|_|+|_|_|_|
|_|_|+|+|*|*|_|
|_|+|*|*|*|+|_|
Select a column to play. Must be between 0 and 6
5
0 1 2 3 4 5 6
|_|_|_|_|_|_|_| |_|_|_|_|_|_|_|
|_|_|_|_|_|_|_|
|_|_|_|+|_|*|_|
|_|_|+|+|*|*|_|
|_|+|*|*|*|+|_|
Select a column to play. Must be between 0 and 6
4
0 1 2 3 4 5 6
|_|_|_|_|_|_|_|
|_|_|_|_|_|_|_|
|_|_|_|_|_|_|_|
|_|_|_|+|+|*|_|
|_|_|+|+|*|*|_|
|_|+|*|*|*|+|_|
Select a column to play. Must be between 0 and 6
4
0 1 2 3 4 5 6
|_|_|_|_|_|_|_|
|_|_|_|_|_|_|_|
|_|_|_|_|*|_|_|
|_|_|_|+|+|*|_|
|_|_|+|+|*|*|_|
|_|+|*|*|*|+|_|
Select a column to play. Must be between 0 and 6
2
0 1 2 3 4 5 6
|_|_|_|_|_|_|_| |_|_|_|_|_|_|_|
|_|_|_|_|*|_|_|
|_|_|+|+|+|*|_|
|_|_|+|+|*|*|_|
|_|+|*|*|*|+|_|
Select a column to play. Must be between 0 and 6
0
0 1 2 3 4 5 6
|_|_|_|_|_|_|_|
|_|_|_|_|_|_|_|
|_|_|_|_|*|_|_|
|_|_|+|+|+|*|_|
|_|_|+|+|*|*|_|
|*|+|*|*|*|+|_|
Select a column to play. Must be between 0 and 6
0
0 1 2 3 4 5 6
|_|_|_|_|_|_|_|
|_|_|_|_|_|_|_|
|_|_|_|_|*|_|_|
|_|_|+|+|+|*|_|
|+|_|+|+|*|*|_|
|*|+|*|*|*|+|_|
Select a column to play. Must be between 0 and 6
1
0 1 2 3 4 5 6
|_|_|_|_|_|_|_| |_|_|_|_|_|_|_|
|_|_|_|_|*|_|_|
|_|_|+|+|+|*|_|
|+|*|+|+|*|*|_|
|*|+|*|*|*|+|_|
Select a column to play. Must be between 0 and 6
1
0 1 2 3 4 5 6
|_|_|_|_|_|_|_|
|_|_|_|_|_|_|_|
|_|_|_|_|*|_|_|
|_|+|+|+|+|*|_|
|+|*|+|+|*|*|_|
|*|+|*|*|*|+|_|
Congratulations player 2. You won.
Thanks for playing!

-- program is finished running --

Project Stages
In order to help you be aware of your progress, it is recommended to use a series of
mile markers to help you divide up the work. You can ignore these if you wish.
However, if you find you need some direction, by all means follow along.
Stage 1 - Create the main loop logic and user interaction
The tedious part of this program will be to create all the strings, display them to the
user, and get user input. It is also the simpler bit. During the first stage, it is
suggested you focus on creating an application that prints the strings to the user,
implements the main loop, and asks the user for input (don’t forget to make sure the
input column is valid!). At this stage you don’t have to worry about saving the input,
etc. If you finish early, move on to stage 2 and try to display the board. You can edit
the matrix manually to “simulate” some plays have occurred.
Stage 2 - The board
Now that you display all strings to the user, and get all information from the user,
you can move on to implement the next step: displaying the board and dropping
tokens as requested by the user. In this stage, create the data structure that
represents the board - matrix. Implement functions that help you access the matrix.
You can start by implementing the code that prints the board to the user, as it will
help you debug. Then, use the user input to drop a token. When the user chooses a
column, you may spiral down the column to find the first empty cell.
If you finish early, move on to stage 3 and try to find winning game conditions
for horizontal and vertical 4-in-line.
Stage 3 - Winning the game
Since you know where the token was dropped, the easiest way, probably not the
smartest, is to check the matrix entries around the dropped token. For example, this
was the last dropped token:
0 1 2 3 4 5 6
|_|_|_|_|_|_|_|
|_|_|_|_|_|_|_|
|_|_|_|_|*|_|_|
|_|_|_|_|_|_|_|
|_|_|_|_|_|_|_|
|_|_|_|_|_|_|_|
You can check the following 4 regions of interest:
1
0 1 2 3 4 5 6
|_|_|_|_|_|_|_|
|_|_|_|_|_|_|_|
|_|?|?|?|*|?|?|
|_|_|_|_|_|_|_|
|_|_|_|_|_|_|_| |_|_|_|_|_|_|_|
2
0 1 2 3 4 5 6
|_|_|_|_|?|_|_|
|_|_|_|_|?|_|_|
|_|_|_|_|*|_|_|
|_|_|_|_|?|_|_|
|_|_|_|_|?|_|_|
|_|_|_|_|?|_|_|
3
0 1 2 3 4 5 6
|_|_|?|_|_|_|_|
|_|_|_|?|_|_|_|
|_|_|_|_|*|_|_|
|_|_|_|_|_|?|_|
|_|_|_|_|_|_|?|
|_|_|_|_|_|_|_|
4
0 1 2 3 4 5 6
|_|_|_|_|_|_|?|
|_|_|_|_|_|?|_|
|_|_|_|_|*|_|_|
|_|_|_|?|_|_|_|
|_|_|?|_|_|_|_|
|_|?|_|_|_|_|_| Also, don’t forget to stop the game if the board is full. (Just keep track of how
many tokens were dropped.)
Helpful Tidbits
Starting the code
This is a very simple program in a higher-level language! But it is much more
complex in assembly. As such, here is some advice for developing your program.
Plan and start by writing high-level comments on how you plan to approach the
problem:
• If you are not sure what to write, start with the items in the “Your
assignment” section of the project :)
• Then add detail to those comments.
• If you need, write the program in a high-level language, draw a diagram,
write pseudo-code, and then translate that into MISP assembly.
Testing
DO NOT TRY TO WRITE THE WHOLE PROGRAM BEFORE TESTING IT!
• It’s the easiest way to get overwhelmed and confused without knowing what
to do!
• Implement small parts of the code and test them!
Split your code into functions
Use functions! They will help you manage the cognitive load. Here is a starting point!
main:
jal print_welcome
jal display_board

_main_loop:
...
_main_player1:

j _main_loop

Submission
Submit a single ZIP file with your project named studentID_MidtermProj.zip
(e.g., 2023141520000_ MidtermProj.zip). In the zip file, there should be NO folder,
just the following files: • Your connect.asm file. (Put your name and student ID at the top of the file in
the comments!)
• A readme.txt file (DO NOT SUBMIT A README.DOCX/README.PDF. SUBMIT
A PLAIN TEXT FILE. PLEASE.) which should contain: a) your name, b) your
student ID, c) anything that does not work, d) anything else you think might
help the grader grade your project more easily.
Submit into the Blackboard. Let me know immediately if there are any problems
submitting your work.

热门主题

课程名

mktg2509 csci 2600 38170 lng302 csse3010 phas3226 77938 arch1162 engn4536/engn6536 acx5903 comp151101 phl245 cse12 comp9312 stat3016/6016 phas0038 comp2140 6qqmb312 xjco3011 rest0005 ematm0051 5qqmn219 lubs5062m eee8155 cege0100 eap033 artd1109 mat246 etc3430 ecmm462 mis102 inft6800 ddes9903 comp6521 comp9517 comp3331/9331 comp4337 comp6008 comp9414 bu.231.790.81 man00150m csb352h math1041 eengm4100 isys1002 08 6057cem mktg3504 mthm036 mtrx1701 mth3241 eeee3086 cmp-7038b cmp-7000a ints4010 econ2151 infs5710 fins5516 fin3309 fins5510 gsoe9340 math2007 math2036 soee5010 mark3088 infs3605 elec9714 comp2271 ma214 comp2211 infs3604 600426 sit254 acct3091 bbt405 msin0116 com107/com113 mark5826 sit120 comp9021 eco2101 eeen40700 cs253 ece3114 ecmm447 chns3000 math377 itd102 comp9444 comp(2041|9044) econ0060 econ7230 mgt001371 ecs-323 cs6250 mgdi60012 mdia2012 comm221001 comm5000 ma1008 engl642 econ241 com333 math367 mis201 nbs-7041x meek16104 econ2003 comm1190 mbas902 comp-1027 dpst1091 comp7315 eppd1033 m06 ee3025 msci231 bb113/bbs1063 fc709 comp3425 comp9417 econ42915 cb9101 math1102e chme0017 fc307 mkt60104 5522usst litr1-uc6201.200 ee1102 cosc2803 math39512 omp9727 int2067/int5051 bsb151 mgt253 fc021 babs2202 mis2002s phya21 18-213 cege0012 mdia1002 math38032 mech5125 07 cisc102 mgx3110 cs240 11175 fin3020s eco3420 ictten622 comp9727 cpt111 de114102d mgm320h5s bafi1019 math21112 efim20036 mn-3503 fins5568 110.807 bcpm000028 info6030 bma0092 bcpm0054 math20212 ce335 cs365 cenv6141 ftec5580 math2010 ec3450 comm1170 ecmt1010 csci-ua.0480-003 econ12-200 ib3960 ectb60h3f cs247—assignment tk3163 ics3u ib3j80 comp20008 comp9334 eppd1063 acct2343 cct109 isys1055/3412 math350-real math2014 eec180 stat141b econ2101 msinm014/msing014/msing014b fit2004 comp643 bu1002 cm2030
联系我们
EMail: 99515681@qq.com
QQ: 99515681
留学生作业帮-留学生的知心伴侣!
工作时间:08:00-21:00
python代写
微信客服:codinghelp
站长地图