初学者的小游戏开发教程与大智慧

版权申诉
0 下载量 126 浏览量 更新于2024-10-08 收藏 4KB ZIP 举报
资源摘要信息:"本压缩包资源名为‘Small-Game-Big-Smile!.zip_Big!_大智慧’,其中包含了一个简单的小游戏源代码文件‘Small Game Big Smile!.cpp’。该游戏是一个使用C语言编写的程序,特别适合编程初学者,用于帮助他们了解基本的游戏开发流程和编程逻辑。本文件的标题和描述暗示了即使是一个小游戏,也能够带来很多的启发和乐趣,体现了编程学习中的“大智慧”。 标题中‘Small-Game-Big-Smile!’暗示了小游戏的性质,即它虽然简单,但能够给玩家带来快乐和满足感。同时,‘Big! 大智慧’表明即使是初学者开发的简单游戏,也蕴含着深刻的编程知识和理念。 在描述中,‘小游戏大智慧,简单c语言小游戏程序,初学者的开发效果’强调了资源对于编程初学者的价值。它提供了一个可学习的案例,让初学者可以通过分析和修改源代码来理解C语言的基本结构和游戏逻辑的实现方式。 文件名称列表中的‘Small Game Big Smile!.cpp’是本压缩包中唯一的文件,它是一个C++源代码文件。尽管文件名中包含了“Game”和“Smile”这样的关键词,但请注意,文件的扩展名表明这是一个C++源代码文件。这可能意味着文件原本是用C++语言编写的,而不是C语言。不过,C和C++在语法上有很大的相似性,所以对于C语言初学者来说,这个文件仍然是一个很好的学习资源。 从这个小游戏程序中,初学者可以学习到的C/C++编程知识点可能包括但不限于: - 基本语法:变量声明、数据类型、运算符和表达式的使用。 - 控制结构:条件判断(if-else)和循环结构(for, while, do-while)的使用。 - 函数定义:如何在C/C++中创建和使用函数,包括主函数(main)的作用。 - 输入输出:如何使用标准库中的输入输出函数,如printf()和scanf(),或C++的iostream库。 - 数组和字符串:基础的数组操作和字符串处理方法。 - 简单的逻辑设计:如何组织游戏逻辑,包括游戏循环、用户交互等。 - 错误处理:如何处理常见的编程错误和用户输入错误。 初学者可以从阅读和理解这个程序的代码开始,进而尝试修改和扩展游戏的功能,例如增加新的游戏规则、改进用户界面或添加更多的游戏级别。通过这样的实践,初学者不仅能够加深对编程概念的理解,而且还能够提高解决问题的能力和创造力。 此外,这个小游戏可能还会涉及到一些计算机科学的基础概念,例如算法的设计、数据结构的使用(尽管在这个简单游戏中可能不会涉及太复杂的结构),以及程序的调试和测试。 最后,‘Big! 大智慧’这个标签提示我们,即使是编写一个简单的小游戏,也需要整体的思考和设计能力,这不仅仅是关于编程技巧,更是关于如何将各种元素结合在一起创造出有趣和富有吸引力的产品。对于编程初学者来说,这是一个重要的教训,即在学习编程的过程中,始终要思考如何将所学知识应用到实际问题的解决中去。"

import cv2 import face_recognition import numpy as np from PIL import Image, ImageDraw,ImageFont video_capture = cv2.VideoCapture(r'C:/Users/ALIENWARE/123.mp4')#如果输入是(0)为摄像头输入 #现输入为MP4进行识别检测人脸 first_image = face_recognition.load_image_file("1.jpg") first_face_encoding = face_recognition.face_encodings(first_image)[0] Second_image = face_recognition.load_image_file("2.jpg") Second_face_encoding = face_recognition.face_encodings(Second_image)[0] third_image = face_recognition.load_image_file("3.jpg") third_face_encoding = face_recognition.face_encodings(third_image)[0] inside_face_encodings = [first_face_encoding,Second_face_encoding,third_face_encoding] inside_face_names = ['A','B','C'] face_locations = [] face_encodings = [] face_names = [] process_this_frame = True while True: ret, frame = video_capture.read() small_frame = cv2.resize(frame, (0, 0), fx=0.25, fy=0.25) rgb_small_frame = small_frame[:, :, ::-1] if process_this_frame: face_locations = face_recognition.face_locations(rgb_small_frame) face_encodings = face_recognition.face_encodings(rgb_small_frame, face_locations) face_names = [] for face_encoding in face_encodings: matches = face_recognition.compare_faces(inside_face_encodings, face_encoding) name = '未录入人脸' if True in matches: first_match_index = matches.index(True) name = inside_face_names[first_match_index] face_names.append(name) process_this_frame = not process_this_frame for (top, right, bottom, left), name in zip(face_locations, face_names): top *= 4 right *= 4 bottom *= 4 left *= 4 cv2.rectangle(frame, (left, top), (right, bottom), (0, 0, 255), 2) img_pil = Image.fromarray(frame) draw = ImageDraw.Draw(img_pil) fontStyle = ImageFont.truetype("C:/Windows/Fonts/simsun.ttc", 32, encoding="utf-8") draw.text((left + 6, bottom - 6), name, (0, 200, 0), font=fontStyle) frame = np.asarray(np.array(img_pil)) cv2.imshow('face_out', frame) if cv2.waitKey(1) & 0xFF == ord('q'): #退出需要按下Q键否则内核会崩溃 break video_capture.release() cv2.destroyAllWindows()

2023-06-07 上传

import tensorflow as tf import tensorflow_hub as hub from tensorflow.keras import layers import bert import numpy as np from transformers import BertTokenizer, BertModel # 设置BERT模型的路径和参数 bert_path = "E:\\AAA\\523\\BERT-pytorch-master\\bert1.ckpt" max_seq_length = 128 train_batch_size = 32 learning_rate = 2e-5 num_train_epochs = 3 # 加载BERT模型 def create_model(): input_word_ids = tf.keras.layers.Input(shape=(max_seq_length,), dtype=tf.int32, name="input_word_ids") input_mask = tf.keras.layers.Input(shape=(max_seq_length,), dtype=tf.int32, name="input_mask") segment_ids = tf.keras.layers.Input(shape=(max_seq_length,), dtype=tf.int32, name="segment_ids") bert_layer = hub.KerasLayer(bert_path, trainable=True) pooled_output, sequence_output = bert_layer([input_word_ids, input_mask, segment_ids]) output = layers.Dense(1, activation='sigmoid')(pooled_output) model = tf.keras.models.Model(inputs=[input_word_ids, input_mask, segment_ids], outputs=output) return model # 准备数据 def create_input_data(sentences, labels): tokenizer = bert.tokenization.FullTokenizer(vocab_file=bert_path + "trainer/vocab.small", do_lower_case=True) # tokenizer = BertTokenizer.from_pretrained('bert-base-uncased') input_ids = [] input_masks = [] segment_ids = [] for sentence in sentences: tokens = tokenizer.tokenize(sentence) tokens = ["[CLS]"] + tokens + ["[SEP]"] input_id = tokenizer.convert_tokens_to_ids(tokens) input_mask = [1] * len(input_id) segment_id = [0] * len(input_id) padding_length = max_seq_length - len(input_id) input_id += [0] * padding_length input_mask += [0] * padding_length segment_id += [0] * padding_length input_ids.append(input_id) input_masks.append(input_mask) segment_ids.append(segment_id) return np.array(input_ids), np.array(input_masks), np.array(segment_ids), np.array(labels) # 加载训练数据 train_sentences = ["Example sentence 1", "Example sentence 2", ...] train_labels = [0, 1, ...] train_input_ids, train_input_masks, train_segment_ids, train_labels = create_input_data(train_sentences, train_labels) # 构建模型 model = create_model() model.compile(optimizer=tf.keras.optimizers.Adam(lr=learning_rate), loss='binary_crossentropy', metrics=['accuracy']) # 开始微调 model.fit([train_input_ids, train_input_masks, train_segment_ids], train_labels, batch_size=train_batch_size, epochs=num_train_epochs)这段代码有什么问题吗?

2023-05-24 上传