首页
编程语言
数据库
网络开发
Algorithm算法
移动开发
系统相关
金融统计
人工智能
其他
首页
>
> 详细
CAN201讲解 、python语言程序辅导
CAN201 In Class Test 1 Thursday Session 2
Multiplayer Number Guessing Game (UDP Sockets)
Objective
This in class test is required to use Python for socket programming. You will create a multiplayer “number guessing” game using UDP sockets programming, with one server and multiple clients (two clients for testing).
Task Description
You need to implement two simple programs: a server and a client. The server manages the game logic, while the clients communicate with the server to participate in the game.
Game Rules:
Server Behavior
1. Initialization: The server listens/waits on a specified IP and port.
2. Client Connection:
o When a client connects, the server asks for the client’s name.
o After receiving the name, the client is marked as "ready". 3. Game Start:
o The game starts when all connected clients are "ready".1
o The server generates a random number (e.g., 1-100). 4. Gameplay:
o The server prompts each client in turn to guess the number. o The server checks the guess:
§ Ifcorrect,theserverannouncesthewinnertoallclientsandendsthegame.
§ If incorrect, the server informs all clients whether the guess is too high or
too low, and then prompts the next client.
o Next turn order: the player who guesses closest gets to guess first in the next turn. 5. Game End: The game ends when a client guesses correctly. (To make it simpler, no restart
is required. That means we only test once.)
Client Behavior
1. Connect to Server: Clients connect to the server using its IP and port of the server.
2. Submit Name: Clients send their name when prompted by the server.
3. Gameplay:
o Clients wait for their turn to guess.
o When prompted, the client sends a guess to the server.
o The client receives feedback from the server about their guess.
6. Game End: Clients are notified when the game ends. (To make it simpler, no restart is required. That means we only test once.)
1 When we test your code, we will start two clients (two clients code should let the server know their joining) first, and then enter client’s name one by one.
Implementation Requirements
• Language: Python 3.x
• Sockets: Use socket module, UDP protocol.
• Error Handling: Implement basic error handling for invalid inputs.
Program Execution
1. Server Execution (in terminal):
python server.py --ip
--port
Example:
python server.py --ip 192.168.0.100 --port 42345
2. Client Execution (in terminal):
python client.py --ip
--port
Example:
python client.py --ip 192.168.0.100 --port 42345
Submission
Package server.py and client.py into a zip file and submit it to Learningmall’s submission link.
Sample Interaction
Server Output
Server started on 192.168.0.100:42345 Client connected: (192.168.0.101, 54321) Client connected: (192.168.0.102, 54322) Received name: Alice
Received name: Bob
All clients are ready. Starting the game. Random number generated: 42
Prompting Alice to guess.
Received guess 30 from Alice. Too low. Prompting Bob to guess.
Received guess 50 from Bob. Too high. Prompting Bob to guess.
Received guess 42 from Bob. Bob wins! Client Output (Alice)
Connected to server at 192.168.0.100:42345 Enter your name: Alice
Waiting for other players...
Game started!
Your turn to guess.
Enter your guess: 30
Your guess is too low.
Waiting for your turn...
Bob guessed 50. The guess is too high.
Waiting for your turn...
Bob guessed 42 and won the game!
Client Output (Bob)
Connected to server at 192.168.0.100:42345 Enter your name: Bob
Waiting for other players...
Game started!
Waiting for your turn...
Alice guessed 30. The guess is too low. Your turn to guess.
Enter your guess: 50
Your guess is too high.
Your turn to guess.
Enter your guess: 42
Congratulations! You guessed the number!
Grading Criteria (Total: 5 points)
1. Functionality (2 points)
o 2 points: Correct implementation of game logic, including generating a random number,
prompting clients to guess in turn, evaluating the guess (higher/lower), and broadcasting
results to all clients.
o 1 point: Basic communication between the client and server is established, including
client connection and name registration.
o 0 point: No submission or incorrect submission.
2. Code Quality and Standards (1 point)
o 1 point: Code is well-structured, with appropriate comments, clear variable naming,
and logical organization.
o 0.5 points: The submitted program has no major syntax errors and can run correctly. o 0 point: No submission or incorrect submission.
3. Timely Submission (2 point)
o 2 points: Complete submission of server.py and client.py files during the lab. o 1 point: Complete submission of server.py and client.py files within 24 hours. o 0 points: Incomplete or late submission or missing any file.
联系我们
QQ:99515681
邮箱:99515681@qq.com
工作时间:8:00-21:00
微信:codinghelp
热点文章
更多
讲解 econ1202 – quantitativ...
2024-11-22
辅导 msds 490: healthcare an...
2024-11-22
讲解 civl 326 geotechnical d...
2024-11-22
辅导 term paper medicine whe...
2024-11-22
讲解 eng3004 course work辅导...
2024-11-22
讲解 ee512: stochastic proce...
2024-11-22
辅导 geog100 ol01 - fall 202...
2024-11-22
辅导 st5226: spatial statist...
2024-11-22
讲解 ece 101a engineering el...
2024-11-22
讲解 database development an...
2024-11-22
讲解 comp3134 business intel...
2024-11-22
讲解 practice exam 2, math 3...
2024-11-22
讲解 project 4: advanced opt...
2024-11-22
辅导 38003 organisational be...
2024-11-22
辅导 economic growth调试spss
2024-11-22
辅导 ee512: stochastic proce...
2024-11-22
讲解 eesb04 "principles of h...
2024-11-22
辅导 am2060 final assignment...
2024-11-22
辅导 acfim0035 fundamentals ...
2024-11-22
辅导 stat 612 (fall 2024) ho...
2024-11-22
热点标签
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: 99515681 微信:codinghelp
© 2024
www.7daixie.com
站长地图
程序辅导网!