save to file
This commit is contained in:
1 parent
acd9bc0829
commit
8a7c745c44
2 files changed
+119
-44
No files matched your search
Generated
+20
-4
@@ -4,7 +4,10 @@
|
|||||||
<option name="autoReloadType" value="SELECTIVE" />
|
<option name="autoReloadType" value="SELECTIVE" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="aaf4cea1-996f-4616-a7e8-5aebcf6aea3e" name="Changes" comment="save to file wins, loose, draw and dif" />
|
<list default="true" id="aaf4cea1-996f-4616-a7e8-5aebcf6aea3e" name="Changes" comment="">
|
||||||
|
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/BotForTelegramm/Fox_hahBot.py" beforeDir="false" afterPath="$PROJECT_DIR$/BotForTelegramm/Fox_hahBot.py" afterDir="false" />
|
||||||
|
</list>
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||||
@@ -44,6 +47,8 @@
|
|||||||
"keyToString": {
|
"keyToString": {
|
||||||
"ASKED_SHARE_PROJECT_CONFIGURATION_FILES": "true",
|
"ASKED_SHARE_PROJECT_CONFIGURATION_FILES": "true",
|
||||||
"ModuleVcsDetector.initialDetectionPerformed": "true",
|
"ModuleVcsDetector.initialDetectionPerformed": "true",
|
||||||
|
"Python.Fox_hahBot.executor": "Run",
|
||||||
|
"Python.filemanager.executor": "Run",
|
||||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||||
"RunOnceActivity.git.unshallow": "true",
|
"RunOnceActivity.git.unshallow": "true",
|
||||||
"git-widget-placeholder": "main",
|
"git-widget-placeholder": "main",
|
||||||
@@ -160,7 +165,15 @@
|
|||||||
<option name="project" value="LOCAL" />
|
<option name="project" value="LOCAL" />
|
||||||
<updated>1775141509258</updated>
|
<updated>1775141509258</updated>
|
||||||
</task>
|
</task>
|
||||||
<option name="localTasksCounter" value="12" />
|
<task id="LOCAL-00012" summary="del commments">
|
||||||
|
<option name="closed" value="true" />
|
||||||
|
<created>1775199686999</created>
|
||||||
|
<option name="number" value="00012" />
|
||||||
|
<option name="presentableId" value="LOCAL-00012" />
|
||||||
|
<option name="project" value="LOCAL" />
|
||||||
|
<updated>1775199686999</updated>
|
||||||
|
</task>
|
||||||
|
<option name="localTasksCounter" value="13" />
|
||||||
<servers />
|
<servers />
|
||||||
</component>
|
</component>
|
||||||
<component name="UpdateCopyrightCheckinHandler">
|
<component name="UpdateCopyrightCheckinHandler">
|
||||||
@@ -171,7 +184,9 @@
|
|||||||
<map>
|
<map>
|
||||||
<entry key="MAIN">
|
<entry key="MAIN">
|
||||||
<value>
|
<value>
|
||||||
<State />
|
<State>
|
||||||
|
<option name="LONG_EDGES_VISIBLE" value="true" />
|
||||||
|
</State>
|
||||||
</value>
|
</value>
|
||||||
</entry>
|
</entry>
|
||||||
</map>
|
</map>
|
||||||
@@ -187,7 +202,8 @@
|
|||||||
<MESSAGE value="test3" />
|
<MESSAGE value="test3" />
|
||||||
<MESSAGE value="test4" />
|
<MESSAGE value="test4" />
|
||||||
<MESSAGE value="save to file wins, loose, draw and dif" />
|
<MESSAGE value="save to file wins, loose, draw and dif" />
|
||||||
<option name="LAST_COMMIT_MESSAGE" value="save to file wins, loose, draw and dif" />
|
<MESSAGE value="del commments" />
|
||||||
|
<option name="LAST_COMMIT_MESSAGE" value="del commments" />
|
||||||
<option name="OPTIMIZE_IMPORTS_BEFORE_PROJECT_COMMIT" value="true" />
|
<option name="OPTIMIZE_IMPORTS_BEFORE_PROJECT_COMMIT" value="true" />
|
||||||
<option name="REFORMAT_BEFORE_PROJECT_COMMIT" value="true" />
|
<option name="REFORMAT_BEFORE_PROJECT_COMMIT" value="true" />
|
||||||
<option name="REARRANGE_BEFORE_PROJECT_COMMIT" value="true" />
|
<option name="REARRANGE_BEFORE_PROJECT_COMMIT" value="true" />
|
||||||
|
|||||||
@@ -1,59 +1,118 @@
|
|||||||
import random
|
import random
|
||||||
|
|
||||||
import telebot
|
import telebot
|
||||||
|
from telebot import types
|
||||||
|
|
||||||
import filemanager
|
import filemanager
|
||||||
|
|
||||||
token = "8379986047:AAGr74CT6Y2a8moIWL4Otsntu1CjozdF9ec"
|
token = "8379986047:AAGr74CT6Y2a8moIWL4Outspent1CajoledF9ec"
|
||||||
|
|
||||||
bot = telebot.TeleBot(token)
|
bot = telebot.TeleBot(token)
|
||||||
|
|
||||||
|
keyboard = types.ReplyKeyboardMarkup(resize_keyboard=True)
|
||||||
|
button1 = types.KeyboardButton("Камень")
|
||||||
|
button2 = types.KeyboardButton("Ножницы")
|
||||||
|
button3 = types.KeyboardButton("Бумага")
|
||||||
|
keyboard.add(button1, button2, button3)
|
||||||
|
|
||||||
|
userLink = {}
|
||||||
wins = {}
|
wins = {}
|
||||||
loose = {}
|
looses = {}
|
||||||
draw = {}
|
draws = {}
|
||||||
dif = {}
|
dif = {}
|
||||||
|
|
||||||
|
Rock = {}
|
||||||
|
Paper = {}
|
||||||
|
Scissors = {}
|
||||||
|
|
||||||
def addUserIfNotExist(message):
|
def addUserIfNotExist(message):
|
||||||
if not wins[message.from_user.id]:
|
uid = message.chat.id
|
||||||
wins[message.from_user.id] = 0
|
if uid not in userLink: userLink[uid] = 0 # персональный счётчик
|
||||||
|
filemanager.save_to_file(uid.txt, uid)
|
||||||
|
if uid not in wins: wins[uid] = 0
|
||||||
filemanager.save_to_file(wins.txt, wins)
|
filemanager.save_to_file(wins.txt, wins)
|
||||||
if not loose[message.from_user.id]:
|
if uid not in looses: looses[uid] = 0
|
||||||
loose[message.from_user.id] = 0
|
filemanager.save_to_file(looses.txt, looses)
|
||||||
filemanager.save_to_file(loose.txt, loose)
|
if uid not in draws: draws[uid] = 0
|
||||||
if not draw[message.from_user.id]:
|
filemanager.save_to_file(draws.txt, draws)
|
||||||
draw[message.from_user.id] = 0
|
if uid not in Rock: Rock[uid] = 0
|
||||||
filemanager.save_to_file(draw.txt, draw)
|
filemanager.save_to_file(Rock.txt, Rock)
|
||||||
if not dif[message.from_user.id]:
|
if uid not in Paper: Paper[uid] = 0
|
||||||
dif[message.from_user.id] = 0
|
filemanager.save_to_file(Paper.txt, Paper)
|
||||||
filemanager.save_to_file(dif.txt, dif)
|
if uid not in Scissors: Scissors[uid] = 0
|
||||||
|
filemanager.save_to_file(Scissors.txt, Scissors)
|
||||||
|
return userLink.get(uid)
|
||||||
|
|
||||||
@bot.message_handler(commands=['start'])
|
@bot.message_handler(commands=['start'])
|
||||||
def start(message):
|
def start(message):
|
||||||
bot.send_message(message.chat.id, 'Привет, это игра "Камень, ножницы, бумага"')
|
addUserIfNotExist(message)
|
||||||
|
bot.send_message(message.chat.id, 'Привет! Выбери уровень:\n/easy\n/normal\n/hard\n/mega_hard',
|
||||||
|
reply_markup=keyboard)
|
||||||
|
|
||||||
@bot.message_handler(commands=['rules'])
|
|
||||||
def rules(message):
|
|
||||||
bot.send_message(message.chat.id, 'Правила: выбираешь "Камень", "Ножницы" или "Бумага", если ты выиграл я напишу, а если нет, то ладно')
|
|
||||||
|
|
||||||
@bot.message_handler(func=lambda message:True)
|
@bot.message_handler(commands=['easy', 'normal', 'hard', 'mega_hard'])
|
||||||
|
def difficulty(message):
|
||||||
|
addUserIfNotExist(message)
|
||||||
|
if message.text == "/easy":
|
||||||
|
userLink[message.chat.id] = 1
|
||||||
|
elif message.text == "/normal":
|
||||||
|
userLink[message.chat.id] = 2
|
||||||
|
elif message.text == "/hard":
|
||||||
|
userLink[message.chat.id] = 3
|
||||||
|
elif message.text == "/mega_hard":
|
||||||
|
userLink[message.chat.id] = 4
|
||||||
|
bot.send_message(message.chat.id, f"Уровень {message.text} выбран")
|
||||||
|
|
||||||
|
|
||||||
|
@bot.message_handler(func=lambda message: True)
|
||||||
def main_game(message):
|
def main_game(message):
|
||||||
ans = random.randint(1,3) #1 - камень, 2 - бумага, 3 - ножницы
|
level = addUserIfNotExist(message)
|
||||||
if message.text == "Камень" and ans == 1:
|
u_move = message.text.lower()
|
||||||
bot.send_message(message.chat.id, "Ничья")
|
uid = message.chat.id
|
||||||
elif message.text == "Камень" and ans == 2:
|
|
||||||
bot.send_message(message.chat.id, "ХАХАХАХ!!! ТЫ ПРОИГРАЛ!")
|
|
||||||
elif message.text == "Камень" and ans == 3:
|
|
||||||
bot.send_message(message.chat.id, "НУУ БЛИИИН!!! ТЫ ВЫИГРАЛ!")
|
|
||||||
elif message.text == "Бумага" and ans == 2:
|
|
||||||
bot.send_message(message.chat.id, "Ничья")
|
|
||||||
elif message.text == "Бумага" and ans == 3:
|
|
||||||
bot.send_message(message.chat.id, "ХАХАХАХ!!! ТЫ ПРОИГРАЛ!")
|
|
||||||
elif message.text == "Бумага" and ans == 1:
|
|
||||||
bot.send_message(message.chat.id, "НУУ БЛИИИН!!! ТЫ ВЫИГРАЛ!")
|
|
||||||
elif message.text == "Ножницы" and ans == 1:
|
|
||||||
bot.send_message(message.chat.id, "ХАХАХАХ!!! ТЫ ПРОИГРАЛ!")
|
|
||||||
elif message.text == "Ножницы" and ans == 2:
|
|
||||||
bot.send_message(message.chat.id, "НУУ БЛИИИН!!! ТЫ ВЫИГРАЛ!")
|
|
||||||
elif message.text == "Ножницы" and ans == 3:
|
|
||||||
bot.send_message(message.chat.id, "Ничья")
|
|
||||||
|
|
||||||
bot.infinity_polling()
|
if u_move not in ["камень", "ножницы", "бумага"]:
|
||||||
|
bot.send_message(uid, "Используй кнопки!")
|
||||||
|
return
|
||||||
|
|
||||||
|
if u_move == "камень":
|
||||||
|
Rock[uid] += 1
|
||||||
|
elif u_move == "ножницы":
|
||||||
|
Scissors[uid] += 1
|
||||||
|
elif u_move == "бумага":
|
||||||
|
Paper[uid] += 1
|
||||||
|
|
||||||
|
if level == 1:
|
||||||
|
botans = "Ножницы" if u_move == "камень" else "Камень" if u_move == "бумага" else "Бумага"
|
||||||
|
elif level == 3:
|
||||||
|
botans = "Бумага" if u_move == "камень" else "Камень" if u_move == "ножницы" else "Ножницы"
|
||||||
|
elif level == 4:
|
||||||
|
stats = {"камень": Rock[uid], "ножницы": Scissors[uid], "бумага": Paper[uid]}
|
||||||
|
fav = max(stats, key=stats.get)
|
||||||
|
if fav == "камень":
|
||||||
|
botans = "Бумага"
|
||||||
|
elif fav == "ножницы":
|
||||||
|
botans = "Камень"
|
||||||
|
else:
|
||||||
|
botans = "Ножницы"
|
||||||
|
else:
|
||||||
|
botans = random.choice(["Камень", "Ножницы", "Бумага"])
|
||||||
|
|
||||||
|
bot_move_low = botans.lower()
|
||||||
|
if bot_move_low == u_move:
|
||||||
|
bot.send_message(uid, "Мой ход: {botans}\nНичья!", reply_markup=keyboard)
|
||||||
|
draws[uid] += 1
|
||||||
|
elif (u_move == "камень" and bot_move_low == "ножницы") or \
|
||||||
|
(u_move == "ножницы" and bot_move_low == "бумага") or \
|
||||||
|
(u_move == "бумага" and bot_move_low == "камень"):
|
||||||
|
bot.send_message(uid, f"Мой ход: {botans}\nПобеда!", reply_markup=keyboard)
|
||||||
|
wins[uid] += 1
|
||||||
|
else:
|
||||||
|
bot.send_message(uid, f"Мой ход: {botans}\nПроиграл!", reply_markup=keyboard)
|
||||||
|
looses[uid] += 1
|
||||||
|
|
||||||
|
bot.infinity_polling()
|
||||||
|
|
||||||
|
# 1. if uid not in Rock/Paper/Scissors: создают персональный счетчик для каждого игрока, чтобы бот не путал статистику разных людей.
|
||||||
|
# 2. Rock[uid] += 1 (и аналоги): при каждом ходе пользователя бот «запоминает», какую кнопку вы нажали, прибавляя единицу к соответствующему счетчику.
|
||||||
|
# 3. stats = {"камень": Rock[uid]...}: перед своим ходом бот «смотрит» в вашу историю и собирает все ваши нажатия в одну таблицу.
|
||||||
|
# 4. max(stats, key=stats.get): бот вычисляет, какой ход в этой таблице встречается чаще всего.
|
||||||
|
# 5. if fav == "камень": botans = "Бумага": бот делает ход, который побеждает ваш самый популярный вариант.
|
||||||
Reference in new issue
Block a user