首页
网站开发
桌面应用
管理软件
微信开发
App开发
嵌入式软件
工具软件
数据采集与分析
其他
首页
>
> 详细
Python编程调试、讲解ITP 115程序、Python编程辅导 辅导R语言编程|解析C/C++编程
项目预算:
开发周期:
发布时间:
要求地区:
ITP 115 – Programming in Python
2021-03-30 Page 1 of 8
Assignment 8 – Tic Tac Toe
Goals
• Create a two player Tic Tac Toe game
• Continue working with loops and lists
• Create functions (parameters, return values, using a main function)
Requirements
• In PyCharm, create a new project named a8_last_first where last is your last/family
name and first is your preferred first name.
• Create a new Python file named a#_last_first, where # is replaced with the number of
this assignment, last is your last/family name, and first is your preferred first name.
• At the top of the Python file, create comments in the following format (replace the
name and email with your actual information and write text for the description):
# Name, USC email
# ITP 115, Spring 2021
# Assignment 8
# Description:
# Describe what this program does.
• You will create a program that uses functions to simulate a two player game of Tic Tac
Toe. The program will allow the two players to place an "x" or an "o" somewhere on
the board and determine when someone wins or when a stalemate is reached.
• In order to keep track of the Tic Tac Toe board, you will use a list of 9 single character
strings, each representing a spot on the board. The board begins with numbers (0-8):
0 1 2
3 4 5
6 7 8
Which is represented in list form as:
["0", "1", "2", "3", "4", "5", "6", "7", "8"]
Where the numbers on the board and in the list correspond with same index positions
in the list. As the game advances, the numbers will be replaced with x’s and o’s.
• You may not use any global variables or constants in your code.
ITP 115 – Programming in Python
2021-03-30 Page 2 of 8
Functions provided for you
• To help you out, we have provided two functions for you to use: a Tic Tac Toe solver
(which tells the current state of the game) and a print board function (which displays
the Tic Tac Toe board). They are located in the TicTacToeHelper.py file provided.
o You will need to put the TicTacToeHelper.py in the same folder as the Python
file for this assignment. Thus add it to the project you created for this
assignment.
o To use a function in your code, place the line "import TicTacToeHelper" at
the top of your code. Importing TicTacToeHelper gives you access to functions
that were defined in a different file.
o To use the solver function, the syntax is:
TicTacToeHelper.checkForWinner(board_list, move_counter)
§ Parameter 1: board_list is a list of strings representing the Tic Tac Toe
board
§ Parameter 2: move_counter is an integer representing the total number
of moves that have been made
§ Return value: a single character string:
• "x" if x won
• "o" if o won
• "n" if there is not winner
• "s" if the game reached a stalemate (full board with no winners)
o To use the print board function, the syntax is:
TicTacToeHelper.printUglyBoard(board_list)
§ Parameter: board_list is a list of strings representing the Tic Tac Toe
board
§ Return value: None
§ Takes the list representing the board and prints it out for the user to see
(the board does not have to exactly match the sample outputs, but it
should show the board as three rows).
ITP 115 – Programming in Python
2021-03-30 Page 3 of 8
Functions for you to create
• Implement the following functions:
o isValidMove(boardList, spot)
§ Parameter 1: a list representing the board
§ Parameter 2: an integer corresponding to the index position that a user
would like to place their letter on
§ Return value: a boolean value
§ This function should look at the specified spot on the board. Return
True if the spot is open. Return False if the spot is taken or if the spot
parameter is not a valid index.
o updateBoard(boardList, spot, playerLetter)
§ Parameter 1: a list representing the board
§ Parameter 2: an integer corresponding to the index position that a user
would like to place their letter on
§ Parameter 3: a string representing the user’s letter ("x" or "o")
§ Return value: None
§ Takes the current board list and places the player’s letter in the specified
spot on the board.
o playGame()
§ Parameter: None
§ Return value: None
§ Create a list variable to represent the board. It should be a list of strings
with the numbers 0-8.
§ Create an int variable to keep track of the total number of moves that
have been made. It is the move counter for the game.
§ Using a while loop, allow each player to take a turn until the game ends.
Note: only one player should take a turn per loop iteration, meaning
you should use a variable that alternates between player x and player o.
§ At each turn, ask the current player what position they would like to put
their letter on the board. Check that the selected spot is valid by calling
the isValidMove() function and then update the board with the
move by calling the updateBoard() function if the move is valid. If the
spot is not valid, keep asking the user for a position on the board until
their move is valid.
§ Call the checkForWinner() function that is located in the
TicTacToeHelper module to control the while loop to determine when
the game is over. The game is over when the checkForWinner() function
does not return an "n".
ITP 115 – Programming in Python
2021-03-30 Page 4 of 8
§ Print out final board at the end of the game and a message about who
won or if there was a stalemate. Look at the sample output.
o main()
§ Parameter: None
§ Return value: None
§ Print the message: "Welcome to Tic Tac Toe!".
§ Call the playGame() function to play a round of Tic Tac Toe.
§ Use a while loop to allow the user to keep playing a new game of Tic Tac
Toe until they decide to stop playing.
Sample Output 1
Welcome to Tic Tac Toe!
0 1 2
3 4 5
6 7 8
Player x, pick a spot: -1
Invalid move, please try again.
Player x, pick a spot: 0
x 1 2
3 4 5
6 7 8
Player o, pick a spot: 0
Invalid move, please try again.
Player o, pick a spot: 4
x 1 2
3 o 5
6 7 8
Player x, pick a spot: 1
x x 2
3 o 5
6 7 8
Player o, pick a spot: 1
Invalid move, please try again.
Player o, pick a spot: 2
x x o
3 o 5
6 7 8
Player x, pick a spot: 3
ITP 115 – Programming in Python
2021-03-30 Page 5 of 8
x x o
x o 5
6 7 8
Player o, pick a spot: 6
x x o
x o 5
o 7 8
Game Over!
Player o is the winner!
Would you like to play another round? (y/n): n
Goodbye!
Sample Output 2
Welcome to Tic Tac Toe!
0 1 2
3 4 5
6 7 8
Player x, pick a spot: 0
x 1 2
3 4 5
6 7 8
Player o, pick a spot: 1
x o 2
3 4 5
6 7 8
Player x, pick a spot: 8
x o 2
3 4 5
6 7 x
Player o, pick a spot: 4
x o 2
3 o 5
6 7 x
Player x, pick a spot: 7
x o 2
ITP 115 – Programming in Python
2021-03-30 Page 6 of 8
3 o 5
6 x x
Player o, pick a spot: 6
x o 2
3 o 5
o x x
Player x, pick a spot: 2
x o x
3 o 5
o x x
Player o, pick a spot: 5
x o x
3 o o
o x x
Player x, pick a spot: 3
x o x
x o o
o x x
Game Over!
Stalemate reached!
Would you like to play another round? (y/n): y
0 1 2
3 4 5
6 7 8
Player x, pick a spot:
.
.
.
(continue the game until the user does not want to play another round)
ITP 115 – Programming in Python
2021-03-30 Page 7 of 8
Extra Credit
• Print pretty board:
o Instead of printing the board out as shown above, define a new function called
printPrettyBoard with the same inputs (board list) and return value (none)
as the printUglyBoard function provided to you, but instead prints the Tic
Tac Toe board out to look like:
0 | 1 | 2
---------
3 | 4 | 5
---------
6 | 7 | 8
o This function should use loops to print the board out. Wherever you print the
board out in your original code, use this new function instead.
• Play against the computer:
o Allow the user the option to play against the computer or another user. When
playing against the computer, the computer’s moves can be random.
• Allow the user to choose which player begins:
o Give the user the option of starting the game as either player x or player o. This
will determine who makes the first move.
ITP 115 – Programming in Python
2021-03-30 Page 8 of 8
Deliverables and Submission Instructions
• Since you created a project in PyCharm named a8_last_first, you already have a folder
with your Python source code (a8_last_first.py) and the TicTacToeHelper.py file. Delete
any extraneous files and/or folders.
• Compress the folder (make a zip file). This cannot be done within PyCharm. Find the
folder on your computer and compress it.
a. Windows:
1. Using File Explorer, select the appropriate folder
2. Right click
3. Send to ->
4. Compressed (zipped) folder
b. Mac OSX:
1. Using Finder, select the appropriate folder
2. Right click
3. Compress “FileName”
• Upload the zip file to your Blackboard section:
1. On Blackboard, navigate to the appropriate assignment item.
2. Click on the specific item for this assignment.
3. Click on the Browse My Computer button and select your zip file.
4. Click the Submit button.
Grading
Item Points
Tic Tac Toe 35
Total* 35
* Points will be deducted for poor code style, lack of error checking, improper submission.
软件开发、广告设计客服
QQ:99515681
邮箱:99515681@qq.com
工作时间:8:00-23:00
微信:codinghelp
热点项目
更多
代做ceng0013 design of a pro...
2024-11-13
代做mech4880 refrigeration a...
2024-11-13
代做mcd1350: media studies a...
2024-11-13
代写fint b338f (autumn 2024)...
2024-11-13
代做engd3000 design of tunab...
2024-11-13
代做n1611 financial economet...
2024-11-13
代做econ 2331: economic and ...
2024-11-13
代做cs770/870 assignment 8代...
2024-11-13
代写amath 481/581 autumn qua...
2024-11-13
代做ccc8013 the process of s...
2024-11-13
代写csit040 – modern comput...
2024-11-13
代写econ 2070: introduc2on t...
2024-11-13
代写cct260, project 2 person...
2024-11-13
热点标签
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
联系我们
- QQ: 9951568
© 2021
www.rj363.com
软件定制开发网!