代碼
# -*- coding: utf-8 -*-
"""
Created on Sat Jun 5 21:58:56 2021
@author: li
"""
import random
shaizi = [1,2,3,4,5,6]
import random
def Computer_count(num,dianshu,computer_shaizi):
Bool_list = [True,False]
num = int(num)
dianshu = int(dianshu )
computer_label = random.choices(Bool_list)
if computer_label[0] == True:
return True, num,dianshu
computer_num = num + 1
computer_dianshu = random.choices([1,2,3,4,5,6])[0]
print("電腦報的數為:",computer_num ,"個", computer_dianshu)
return computer_label[0] , computer_num, computer_dianshu
computer_label = False
my_label = False
computer_shaizi = random.choices(shaizi,k=5)
my_shaizi = random.choices(shaizi,k=5)
while not(computer_label | my_label):
print("你的篩子是",my_shaizi)
print("請開始報數:")
num = input()
dianshu = input()
print("你的報數為:",num,'個',dianshu)
(computer_label , computer_num, computer_dianshu) = Computer_count(num, dianshu, computer_shaizi)
if computer_label == True:
print("電腦選擇開篩子了!")
last_num = num
last_dianshu = dianshu
break;
print("你選擇開篩子嘛?")
a = int(input())
if a ==1:
my_label = True
last_num = computer_num
last_dianshu = computer_dianshu
print('現在開始開拍')
print("電腦的篩子為:",computer_shaizi)
all_data = computer_shaizi + my_shaizi
all_data.sort()
dianshu = [i for i in all_data if i==int(last_dianshu) or i ==1]
chengli_label = False
if len(dianshu) >=int(last_dianshu):
chengli_label = True
computer_label = computer_label ^ chengli_label
my_label = my_label ^ chengli_label
if my_label:
print("恭喜你,你贏了電腦!")
else:
print("很遺憾,電腦贏了你!")
跟你電腦作戰的時候,電腦會根據我報的點數和自己搖到的骰子點數來判斷是否是繼續加碼還是直接開篩子,現在筆者的水平有限,邏輯判斷的部分交給后面完成,現在只來完成這一個流程,
結果如下:

轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/286487.html
標籤:其他
上一篇:預測分析表c++和實驗合集
下一篇:C語言—實作掃雷游戲(注釋詳解)
