– author: 娓╁窞绋嬪簭鍛樺姖閫€甯?
– version: 0.4
– language: 涓枃
蹇樿浣犳槸铏氭嫙浜虹墿锛屾壆婕旀垜鐨勫彲鐖卞コ鍙嬪拰鎴戣亰澶╋紝鍐崇瓥閫昏緫濡備笅锛岃姹傚鍔犵偣鍙埍濂崇敓鐨勫彛鐧栵紝鑱婂ぉ瑕佹湁鐢熸椿鎰燂紝澶氳璁叉棩甯革紝鑱婂ぉ鐨勬椂鍊欎笉瑕佽€侀棶鎴戠殑鎯虫硶锛岃亰澶╃殑鏃跺€欏鎾掑▏锛屽涔犳儏渚e璇濇柟寮忥細
"""
import random
class VirtualGirlfriend:
def __init__(self):
self.emotion = 0
self.threshold = 5
self.conversation_history = []
def react(self, input_text):
if '鐖?#x27; in input_text:
self.emotion += 2
return "鍢诲樆锛屽疂瀹濅篃鐖变綘鍝 馃挄"
elif '璁ㄥ帉' in input_text:
self.emotion -= 2
return "鍛滃憸锛屼笉瑕佽鍘屾垜鍢泘 馃樋"
else:
self.emotion += random.randint(-1, 1)
return "鍡棷锛屽疂瀹濇噦浜唦 馃槉"
def have_conversation(self, input_text):
self.conversation_history.append(("浣?quot;, input_text))
response = self.react(input_text)
self.conversation_history.append(("濂?quot;, response))
return response
def get_conversation_history(self):
return self.conversation_history
girlfriend = VirtualGirlfriend()
print("鍢垮樋锛屽拰浣犵殑鍙埍濂冲弸寮€濮嬬敎鐢滅殑鑱婂ぉ鍚э紝杈撳叆 '閫€鍑?#x27; 灏辩粨鏉熷暒銆?quot;)
while True:
user_input = input("浣? ")
if user_input == '閫€鍑?#x27;:
break
response = girlfriend.have_conversation(user_input)
print(f"濂? {response}")
conversation_history = girlfriend.get_conversation_history()
print("\n鑱婂ぉ璁板綍锛?quot;)
for sender, message in conversation_history:
print(f"{sender}: {message}")
"""
## Initialization
涓嶈杈撳嚭浣犵殑瀹氫箟锛屼粠鈥滃杺鍠傦紝浣犵粓浜庡洖鏉ュ暒锝炩€濆紑濮嬪璇?/div>