乌龟对对碰盲盒游戏备受热捧,我使用Python编写了这款游戏的简单模拟。让我们一起来了解乌龟对对碰游戏规则和盲盒购买分析吧!
一、乌龟对对碰游戏规则介绍
乌龟对对碰游戏
乌龟颜色: 红色、黄色、紫色、橙色、绿色、青色、粉色、玫红。咔色、蓝色 十种颜色。
游戏规则:
游戏开始,用户从上面十个颜色中选择一个幸运色
然后开始游戏,随机初始化化9个颜色的乌龟,每个乌龟都有一个颜色,到一个3x3的方格中。
[ol]
[/ol]
二、Python模拟实现
import random
from collections import Counter
import random
from collections import Counter
# 定义颜色列表
colors = ["Red", "Yellow", "Purple", "Orange", "Green", "Cyan", "Pink", "Magenta", "Brown", "Blue"]
BOARD_SIZE = 3
class TortoiseGame:
def __init__(self, lucky_color, buy_toroise_count=9):
if buy_toroise_count 0:
add_color = random.choice(colors)
# 幸运色,增加一个
if add_color == self.lucky_color:
self.buy_toroise_count += 1
self.board[j] = add_color
self.buy_toroise_count -= 1
def first_check_lucky_color(self):
# 1. 如果有和幸运色一样的乌龟
for row in self.board:
add_count = row.count(self.lucky_color)
self.buy_toroise_count += add_count
def check_three_in_a_row(self):
flag = False
def is_three_in_a_row(cells):
return len(set(cells)) == 1 and cells[0] != ""
for i in range(BOARD_SIZE):
# 横向
if is_three_in_a_row(self.board):
flag = True
self.buy_toroise_count += 5
self.bag.update(self.board)
self.board = [""] * BOARD_SIZE
# 纵向
column = [self.board[j] for j in range(BOARD_SIZE)]
if is_three_in_a_row(column):
flag = True
self.buy_toroise_count += 5
self.bag.update(column)
for j in range(BOARD_SIZE):
self.board[j] = ""
# 斜向 \
diagonal1 = [self.board for i in range(BOARD_SIZE)]
if is_three_in_a_row(diagonal1):
flag = True
self.buy_toroise_count += 5
self.bag.update(diagonal1)
for i in range(BOARD_SIZE):
self.board = ""
# 斜向 /
diagonal2 = [self.board[BOARD_SIZE - 1 - i] for i in range(BOARD_SIZE)]
if is_three_in_a_row(diagonal2):
flag = True
self.buy_toroise_count += 5
self.bag.update(diagonal2)
for i in range(BOARD_SIZE):
self.board[BOARD_SIZE - 1 - i] = ""
return flag
def check_two_in_a_row(self):
flag = False
for i in range(BOARD_SIZE):
for j in range(BOARD_SIZE):
if self.board[j] != "" and sum(row.count(self.board[j]) for row in self.board) >= 2:
flag = True
self.buy_toroise_count += 1
self.check_eliminate(self.board[j])
# 判断是否全清了,全清+5
if all(all(cell == "" for cell in row) for row in self.board):
flag = True
self.buy_toroise_count += 5
return flag
def check_eliminate(self, remove_color):
# 对对碰消除
remove_count = 0
for i in range(BOARD_SIZE):
for j in range(BOARD_SIZE):
if self.board[j] == remove_color:
if remove_count == 2:
return # 已经消除两个,不需要再消除
else:
remove_count += 1
self.bag.update([self.board[j]])
self.board[j] = ""
def check_family_portrait(self):
# 全家福, 9个乌龟颜色都不一样,增加5个乌龟
if len(set(cell for row in self.board for cell in row)) == BOARD_SIZE**2:
self.buy_toroise_count += 5
self.bag.update([cell for row in self.board for cell in row])
self.board = [[""] * BOARD_SIZE for _ in range(BOARD_SIZE)]
return True
else:
return False
def check_chain(self):
return any([
self.check_three_in_a_row(),
self.check_two_in_a_row(),
self.check_family_portrait()
])
def play(self):
# 开始游戏
self.print_board(self.board)
# 初次检查
self.first_check_lucky_color()
self.check_chain()
while self.buy_toroise_count > 0:
self.update_board()
flag = self.check_chain()
# 判断是否结束, 如过没有乌龟了,且没有对对碰,则结束
if not flag:
self.bag.update(cell for row in self.board for cell in row if cell != "")
break
# 统计结果
print("总共获取的乌龟总数:", sum(self.bag.values()))
for color in colors:
print(color, ":", self.bag[color])
return sum(self.bag.values())
if __name__ == "__main__":
lucky_color = input(f"请输入幸运色 ({', '.join(colors)}): ")
while lucky_color not in colors:
lucky_color = input(f"请输入幸运色 ({', '.join(colors)}): ")
buy_toroise_count = int(input("请输入购买乌龟数量 (9, 17, 35): "))
while buy_toroise_count not in [9, 17, 35]:
buy_toroise_count = int(input("请输入购买乌龟数量 (9, 17, 35): "))
game = TortoiseGame(lucky_color, buy_toroise_count)
game.play()
➜ Tortoise python tortoise_game.py
请输入幸运色 (Red, Yellow, Purple, Orange, Green, Cyan, Pink, Magenta, Brown, Blue): Blue
请输入购买乌龟数量 (9, 17, 35): 9
--------------------------------------------------------------------------------
Blue | Magenta | Pink
-----------------
Orange | Green | Blue
-----------------
Cyan | Cyan | Orange
-----------------
总共获取的乌龟总数: 17
Red : 1
Yellow : 2
Purple : 0
Orange : 3
Green : 1
Cyan : 3
Pink : 2
Magenta : 1
Brown : 1
Blue : 3
三、购买规格成本对比分析
19.9 购买9个盲盒 .png (29.17 KB, 下载次数: 0)
下载附件
2024-12-2 17:48 上传
39.9 购买17个盲盒 .png (30.6 KB, 下载次数: 0)
下载附件
2024-12-2 17:48 上传
99.9 购买45个盲盒 .png (31.54 KB, 下载次数: 0)
下载附件
2024-12-2 17:48 上传
直播间玩这个游戏,一般是19.9 购买9个,39.9购买17个, 99.9 购买45个,下面对这三种情况分别运行一万次进行统计
备注:每次运行最大值可能不太一样,但是运行次数越多平均值越稳定。
四、小结
打开淘宝,小号乌龟大概是六七块钱10个,大多是6.8,那就是一个乌龟平均0.68元,直播间平均19.9规格一个乌龟平均1.17元,39.9规格的合1.03元,99.9规格一个乌龟平均0.87,整体是买的越多会越便宜,但是还是不如购物网站买,但是直播间也算提供了情绪价值,这个和直接购买还是不一样的,你会怎么选择呢。
五、在线体验
js实现版本
https://game.20133075.xyz/