首页 > 其他分享 >CAN201 In Class Test 1 Thursday Session

CAN201 In Class Test 1 Thursday Session

时间:2024-10-25 12:20:29浏览次数:8  
标签:guess clients client turn Session Test Bob server Class

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 gamelogic, 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".
  1. Game Start:o The game starts when all connected clients are "ready".1o The server generates a random number (e.g., 1-100).Gameplay:o The server prompts each client in turn to guess the number.o The server checks the guess:
  • If correct, the server announces the winner to all clients and ends the game.
  • If incorrect, the server informs all clients whether the guess is too high ortoo low, and then prompts the next client.o Next turn order: the player who guesses closest gets to guess first in the next turn.
  1. Game End: The game ends when a client guesses correctly. (To make it simpler, no restartis 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. When prompted, the client sends a guess to the server.o The client receives feedback from the server about their guess.
  1. Game End: Clients are notified when the game ends. (To make it simpler, no restart is

required. That means we only test once.)1When 代 写CAN201 In Class Test 1 Thursday Session we test your code, we will start two clients (two clients code should let the server know their

oining) 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 <server_ip> --port <port>Example:

python server.py --ip 192.168.0.100 --port 42345

  1. Client Execution (in terminal):python client.py --ip <server_ip> --port <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

aiting 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.

nter 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), anbroadcastingresults to all clients.o 1 point: Basic communication between the client and server is established, includingclient connection and name registration.o 0 point: No submission or incorrect submission.

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.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.

标签:guess,clients,client,turn,Session,Test,Bob,server,Class
From: https://www.cnblogs.com/goodlunn/p/18501700

相关文章

  • pytest 执行用例 将测试结果追加到表格并生成测试报告并推送至企微
    ReadExcel#-*-coding:utf-8-*-fromopenpyxlimportload_workbookimportosclassTestExcel():defget_TestExcel(self,file_name,sheet_name):print("======",os.getcwd())#workbook=load_workbook('Datas.xlsx......
  • hellojnitest
    新建项目新建一个Kotlin项目,项目名字hellojnitest在cpp目录下新建一个Biletion.c文件里面如下添加内容#include<jni.h>JNIEXPORTjstringJNICALLJava_com_example_hellojnitest_MainActivity_stringFromJNI(JNIEnv*env,jobjectobj){constchar*hello="......
  • AtCoder Regular Contest 185 题解
    A-modMGame2第一个观察是如果一个人手中还有2张牌,那么他一定不会被秒。这可以推出决定胜负的时刻一定是Alice和Bob手中只剩一张牌的时候,此时如果Alice被秒了,那么她就似了,否则她就赢了。考虑Alice什么时候能被秒。记决定胜负的时刻Alice手中的牌是\(a\),Bob手......
  • 机器学习中验证两个算法之间是否存在显著差距的t-test检验
    同一主题的简单分析版本,建议查看:机器学习领域中假设检验的使用本文内容为在上文基础上进一步分析版本。相关:t检验t检验应用条件t检验(t-test)t-test终极指南一文详解t检验t检验,亦称studentt检验(Student'sttest),主要用于样本含量较小(例如n<30),总体标准差σ未知的正......
  • Java中的反射(1)——Class类、访问字段、调用方法
            Java中的反射机制是一种强大的工具,它允许程序在运行时动态地检查类的结构、修改对象的属性或调用方法。反射可以打破封装,从而访问类的私有字段或方法,甚至可以在不提前知道类或方法的情况下,动态创建对象并调用它们。我们可以从以下三个方面来详细解析:Class类、......
  • Cookie、Session、Token三者的区别
    在数字世界的茫茫人海中,每一次点击、每一次登录,都伴随着身份认证与数据安全的较量。今天咱要来一场惊心动魄的技术探秘之旅,今天我要带你深入探索Web开发中那三个绕不开的名字——Cookie、Session、Token,它们不仅仅是技术名词,更是构建安全、高效用户交互的基石,看看它们在接口鉴权、......
  • AtCoder Beginner Contest 375 C题 (python解)
    PanasonicProgrammingContest2024(AtCoderBeginnerContest375)C-SpiralRotation(python解)**原题链接:[(https://atcoder.jp/contests/abc375/tasks/abc375_c)]题目简述:这道题要求对一个NxN的网格进行特定的螺旋旋转操作,而这个N总是偶数。在这里,网格中的每个单元......
  • AtCoder Beginner Contest 376
    A-CandyButton#include<bits/stdc++.h>usingnamespacestd;usingi32=int32_t;usingi64=longlong;usingvi=vector<int>;usingpii=pair<int,int>;i32main(){ ios::sync_with_stdio(false),cin.tie(nullptr); intn,c; ci......
  • 基于FPGA的64QAM基带通信系统,包含testbench,高斯信道模块,误码率统计模块,可以设置不
    1.算法仿真效果      本课题是在博主以前写的文章《m基于FPGA的64QAM调制解调通信系统verilog实现,包含testbench,不包含载波同步》的升级,升级内容包括信道模块(可以设置SNR),误码率统计,同时修正了数据输入频率问题,从而提升了系统的仿真效率。 vivado2019.2仿真结果如下(完......
  • 基于三帧差算法的运动目标检测系统FPGA实现,包含testbench和MATLAB辅助验证程序
    1.算法运行效果图预览(完整程序运行后无水印)   将FPGA的仿真结果导入到MATLAB中,分别得到MATLAB的结果和FPGA的结果:   2.算法运行软件版本vivado2019.2 matlab2022a 3.部分程序(完整版代码包含详细中文注释和操作步骤视频)`timescale1ns/1ps////C......