-
个人简介
奇葩的梗
// | __ \ __ \ // ___|___ / \ ___|___ / \ // /|\ / ____ \ /|\ / ____ \ // / | \ / | / | \ / | // / | \ | |__| / | \ | |__| // | \_____/ | \_____/ // | | // _____ // |_____| \ | // | |_____| | // | \ | // | \__|__/ ______|_____ // \ / \ / /|\ / \ // / \ / | \ / \ // / \ \| / \ // // //
有好东西噢《。@¥¥@。》
-
[ 《c++ 基础代码》]
找到的人可以复制《~ ¥ ¥ ~》
include<>
头文件include<bits/stdc++.h>
用这个就够了using namespace std;
命名空间int main(){
return 0;
}
主函数include<bits/stdc++.h> using namespace std; int main(){ return 0; }
-
[system 的运用 ]
-
[C++加重词 ]
//加重词 转义字符号 int float double short long long long long double char bool for while using namespace true 1 false 0 or || not ! and && return if else switch case rand break default continue const static void unsigned do
- [系统自带函数 ]
- 1,开根号
sqrt();
- 2, 最大值
max({a,b,c})
- 3, 最小值
min({a,b,c})
- 加密程序
#include<cstring> #include<iostream> #include<string> #include<cmath> #include<cstdio> using namespace std; int main() { char str[1001]; int a,f,l,cnt=0; int x,y,d; cout<<"加密程序:\n加密1,解密2."<<endl; cin>>a; if(a==1){ cout<<"加密程序\n请输入加密内容:"; cin>>str; cout<<"请再次确认:"<<str<<endl; cout<<"输入六位密码:"<<endl; while(true){ cin>>l; if(l/100000<10&&l/100000>0){ break; }else{ cout<<"密码不符合要求,请重新输入。"<<endl; } } cout<<"正在加密中······"<<endl; for(int i=0;i<strlen(str);i++){ x=cnt; cout<<str[i]<<"-"<<(int)str[i]<<"-"<<cnt<<"-"; if(x==0)y=l%1000000/100000; if(x==1)y=l%100000/10000; if(x==2)y=l%10000/1000; if(x==3)y=l%1000/100; if(x==4)y=l%100/10; if(x==5)y=l%10/1; cout<<x<<"-"<<y<<"-"; cnt+=1; d=str[i]; d+=y; if(d>=128){ d-=95; str[i]=d; cout<<d<<"-"<<str[i]<<endl; }else{ if(d==127){ str[i]='b'; cout<<d<<"-b\n"; }else{ str[i]=d; cout<<d<<"-"<<str[i]<<endl; } } } cout<<endl<<endl<<"加密结果为:"<<endl; for(int i=0;i<strlen(str);i++){ cout<<str[i]; } } if(a==2) { cout<<"解密程序\n一起输入请选1,分开输入请选2"<<endl; cin>>f; if(f==1){ cout<<"请输入密号:(数字1遍输完按Enter)"<<endl; cin>>l; l=l%1000000; cin>>str; } if(f==2){ cout<<"请输入解密内容:"; cin>>str; cout<<"请再次确认:"<<str<<endl; cout<<"输入六位密码:"<<endl; while(true){ cin>>l; if(l/100000<10&&l/100000>0){ break; }else{ cout<<"密码不符合要求,请重新输入。"<<endl; } } } cout<<"正在解密中······"<<endl; for(int i=0;i<strlen(str);i++){ cout<<i<<"**== {"<<cnt; x=cnt; cout<<str[i]<<"-"<<(int)str[i]<<"-"<<cnt<<"-"; if(x==0)y=l%1000000/100000; if(x==1)y=l%100000/10000; if(x==2)y=l%10000/1000; if(x==3)y=l%1000/100; if(x==4)y=l%100/10; if(x==5)y=l%10/1; cout<<x<<"-_"<<y<<"-_"; cnt=(cnt+1)%6; d=str[i]; d-=y; cout<<d<<" --"; if(d < 32){ d += 95; } cout<<d<<"}=={"<<(char)d<<"}"<<endl; str[i]=d; } cout<<endl<<endl<<"解密结果为:"<<endl; for(int i=0;i<strlen(str);i++){ cout<<str[i]; } } return 0; }
- [python五子棋 ]
<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>五子棋画图板</title> <script src="https://cdn.tailwindcss.com"></script> <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.7.2/css/all.min.css" rel="stylesheet"> <script> tailwind.config = { theme: { extend: { colors: { primary: '#8B4513', secondary: '#D2B48C', board: '#E6B87C', dark: '#333333', win: '#FF5252', forbidden: '#FF9800', }, fontFamily: { sans: ['Inter', 'system-ui', 'sans-serif'], }, } } } </script> <style type="text/tailwindcss"> @layer utilities { .board-shadow { box-shadow: 0 8px 30px rgba(0, 0, 0, 0.15); } .piece-transition { transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1); } .hover-cell:hover::before { content: ''; position: absolute; width: 80%; height: 80%; border-radius: 50%; background-color: rgba(0, 0, 0, 0.08); } .win-line { animation: pulse 1.5s infinite; } @keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.6; } } .forbidden-mark { animation: forbidden-pulse 1.5s infinite; } @keyframes forbidden-pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.1); } } .slide-in { animation: slide-in 0.5s forwards; } @keyframes slide-in { from { transform: translateY(-20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } } .fade-in { animation: fade-in 0.5s forwards; } @keyframes fade-in { from { opacity: 0; } to { opacity: 1; } } } </style> </head> <body class="bg-gradient-to-br from-amber-50 to-amber-100 min-h-screen flex flex-col items-center justify-center p-4 font-sans text-dark overflow-x-hidden"> <!-- 开始界面 --> <div id="start-screen" class="fixed inset-0 z-50 flex flex-col items-center justify-center bg-gradient-to-br from-amber-50 to-amber-100 p-6 fade-in"> <div class="max-w-2xl w-full bg-white rounded-2xl shadow-2xl overflow-hidden transform transition-all duration-500 hover:shadow-xl"> <div class="bg-primary p-6 text-white text-center"> <h1 class="text-4xl font-bold mb-2">五子棋画图板</h1> <p class="text-amber-100">体验经典五子棋游戏,支持AI对战和禁手规则</p> </div> <div class="p-6"> <div class="mb-6"> <h2 class="text-xl font-semibold mb-3 text-primary">选择游戏模式</h2> <div class="grid grid-cols-1 md:grid-cols-2 gap-4"> <label class="game-mode-card bg-white border-2 border-primary/20 rounded-xl p-4 cursor-pointer transition-all duration-300 hover:border-primary hover:shadow-md"> <input type="radio" name="game-mode" value="pvp" class="hidden" checked> <div class="flex flex-col items-center"> <i class="fa-solid fa-users text-3xl text-primary mb-3"></i> <h3 class="font-medium text-lg">玩家对战</h3> <p class="text-sm text-gray-500 mt-2">与朋友面对面游戏</p> </div> </label> <label class="game-mode-card bg-white border-2 border-primary/20 rounded-xl p-4 cursor-pointer transition-all duration-300 hover:border-primary hover:shadow-md"> <input type="radio" name="game-mode" value="pve" class="hidden"> <div class="flex flex-col items-center"> <i class="fa-solid fa-robot text-3xl text-primary mb-3"></i> <h3 class="font-medium text-lg">AI对战</h3> <p class="text-sm text-gray-500 mt-2">挑战智能AI</p> </div> </label> </div> </div> <div class="mb-6"> <h2 class="text-xl font-semibold mb-3 text-primary">游戏设置</h2> <div class="space-y-4"> <div class="flex items-center justify-between"> <span class="font-medium">启用禁手规则</span> <label class="relative inline-flex items-center cursor-pointer"> <input type="checkbox" id="forbidden-rule" class="sr-only peer" checked> <div class="w-11 h-6 bg-gray-200 peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-primary"></div> </label> </div> <div class="flex items-center justify-between"> <span class="font-medium">AI难度</span> <select id="ai-difficulty" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-primary focus:border-primary p-2.5"> <option value="easy">简单</option> <option value="medium" selected>中等</option> <option value="hard">困难</option> </select> </div> </div> </div> <div class="flex flex-col sm:flex-row gap-4"> <button id="start-game" class="bg-primary hover:bg-primary/90 text-white py-3 px-6 rounded-lg transition-all duration-300 transform hover:scale-105 font-medium flex-1"> 开始游戏 </button> <button id="show-history" class="bg-white border border-primary text-primary hover:bg-primary/5 py-3 px-6 rounded-lg transition-all duration-300 font-medium flex-1"> 游戏记录 </button> </div> </div> </div> <div class="mt-8 text-center text-gray-500 text-sm"> <p>使用提示:空格切换模式,Ctrl+Z撤销,N开始新游戏</p> </div> </div> <!-- 游戏记录界面 --> <div id="history-screen" class="fixed inset-0 z-50 flex items-center justify-center bg-black/50 opacity-0 pointer-events-none transition-opacity duration-300"> <div class="bg-white rounded-2xl shadow-2xl max-w-2xl w-full max-h-[80vh] flex flex-col transform scale-95 transition-transform duration-300"> <div class="bg-primary p-4 flex justify-between items-center"> <h2 class="text-xl font-bold text-white">游戏记录</h2> <button id="close-history" class="text-white hover:text-amber-100"> <i class="fa-solid fa-times text-xl"></i> </button> </div> <div id="history-list" class="p-4 overflow-y-auto flex-1"> <!-- 游戏记录将在这里动态生成 --> <div class="text-center text-gray-500 py-8"> <i class="fa-solid fa-folder-open text-4xl mb-3 text-gray-300"></i> <p>暂无游戏记录</p> </div> </div> <div class="p-4 border-t border-gray-200"> <button id="clear-history" class="w-full bg-gray-100 hover:bg-gray-200 text-gray-700 py-2 px-4 rounded-lg transition-all duration-300"> 清空记录 </button> </div> </div> </div> <!-- 主游戏界面 --> <div id="game-screen" class="w-full max-w-4xl mx-auto opacity-0 pointer-events-none transition-opacity duration-300"> <header class="text-center mb-6"> <h1 class="text-[clamp(1.8rem,5vw,2.5rem)] font-bold text-primary mb-2">五子棋画图板</h1> <p class="text-gray-600">在棋盘上点击放置棋子,右键点击可以移除棋子</p> </header> <main class="flex flex-col md:flex-row gap-6 items-center justify-center"> <!-- 五子棋棋盘 --> <div class="relative board-shadow rounded-lg overflow-hidden"> <canvas id="board" class="bg-board rounded-lg cursor-pointer"></canvas> <!-- 棋子提示 --> <div id="piece-preview" class="absolute w-0 h-0 bg-black/10 rounded-full pointer-events-none opacity-0 transition-opacity duration-200"></div> <!-- 胜利提示 --> <div id="win-message" class="absolute inset-0 flex items-center justify-center bg-black/50 opacity-0 pointer-events-none transition-opacity duration-500"> <div class="bg-white p-6 rounded-xl shadow-2xl text-center transform scale-90 transition-transform duration-500"> <h2 id="winner-text" class="text-2xl font-bold mb-4 text-primary">黑棋胜利!</h2> <button id="new-game" class="bg-primary hover:bg-primary/90 text-white py-2 px-6 rounded-lg transition-all duration-300 transform hover:scale-105"> 开始新游戏 </button> </div> </div> <!-- 禁手提示 --> <div id="forbidden-message" class="absolute bottom-4 left-1/2 transform -translate-x-1/2 bg-red-500 text-white py-2 px-4 rounded-lg shadow-lg opacity-0 transition-opacity duration-300"> <p>禁手!此位置不可落子</p> </div> </div> <!-- 控制面板 --> <div class="w-full md:w-64 flex flex-col gap-4"> <div class="bg-white rounded-xl p-5 shadow-lg"> <h2 class="text-lg font-semibold mb-4 text-primary">当前状态</h2> <div class="flex items-center gap-3 mb-4"> <div id="current-player" class="w-6 h-6 rounded-full bg-black"></div> <span>当前:<span id="player-text" class="font-medium">黑棋</span></span> </div> <div class="flex items-center gap-3 mb-4"> <div id="game-mode-indicator" class="flex items-center gap-2 text-sm text-gray-600"> <i class="fa-solid fa-users text-primary"></i> <span>玩家对战</span> </div> </div> <div class="flex flex-col gap-3"> <button id="back-to-menu" class="bg-gray-200 hover:bg-gray-300 text-gray-700 py-2 px-4 rounded-lg transition-all duration-300 transform hover:scale-105 flex items-center justify-center gap-2"> <i class="fa-solid fa-arrow-left"></i> <span>返回菜单</span> </button> <button id="clear-board" class="bg-primary hover:bg-primary/90 text-white py-2 px-4 rounded-lg transition-all duration-300 transform hover:scale-105 flex items-center justify-center gap-2"> <i class="fa-solid fa-eraser"></i> <span>清空棋盘</span> </button> <button id="undo" class="bg-gray-200 hover:bg-gray-300 text-gray-700 py-2 px-4 rounded-lg transition-all duration-300 transform hover:scale-105 flex items-center justify-center gap-2"> <i class="fa-solid fa-undo"></i> <span>撤销</span> </button> <button id="toggle-mode" class="bg-secondary hover:bg-secondary/90 text-primary py-2 px-4 rounded-lg transition-all duration-300 transform hover:scale-105 flex items-center justify-center gap-2"> <i class="fa-solid fa-pencil"></i> <span>绘画模式</span> </button> </div> </div> <div class="bg-white rounded-xl p-5 shadow-lg"> <h2 class="text-lg font-semibold mb-4 text-primary">操作指南</h2> <ul class="space-y-2 text-sm text-gray-600"> <li class="flex items-start gap-2"> <i class="fa-solid fa-circle-dot text-primary mt-1"></i> <span>左键点击:放置棋子</span> </li> <li class="flex items-start gap-2"> <i class="fa-solid fa-circle-dot text-primary mt-1"></i> <span>右键点击:移除棋子</span> </li> <li class="flex items-start gap-2"> <i class="fa-solid fa-circle-dot text-primary mt-1"></i> <span>绘画模式:可以自由绘制标记</span> </li> <li class="flex items-start gap-2"> <i class="fa-solid fa-circle-dot text-primary mt-1"></i> <span>撤销:取消上一步操作</span> </li> </ul> </div> </div> </main> <footer class="mt-8 text-center text-gray-500 text-sm"> <p>五子棋画图板 © 2025</p> </footer> </div> <script> document.addEventListener('DOMContentLoaded', () => { // 获取DOM元素 const startScreen = document.getElementById('start-screen'); const gameScreen = document.getElementById('game-screen'); const historyScreen = document.getElementById('history-screen'); const historyList = document.getElementById('history-list'); const startGameBtn = document.getElementById('start-game'); const showHistoryBtn = document.getElementById('show-history'); const closeHistoryBtn = document.getElementById('close-history'); const clearHistoryBtn = document.getElementById('clear-history'); const backToMenuBtn = document.getElementById('back-to-menu'); const forbiddenMessage = document.getElementById('forbidden-message'); const gameModeIndicator = document.getElementById('game-mode-indicator'); // 棋盘配置 const BOARD_SIZE = 15; // 15x15的棋盘 const CELL_SIZE = 30; // 每个格子的大小 const PIECE_SIZE = CELL_SIZE * 0.7; // 棋子大小(已调小) const BOARD_PADDING = CELL_SIZE; // 棋盘边距 // 获取Canvas元素和相关DOM元素 const canvas = document.getElementById('board'); const ctx = canvas.getContext('2d'); const piecePreview = document.getElementById('piece-preview'); const currentPlayer = document.getElementById('current-player'); const playerText = document.getElementById('player-text'); const clearBoardBtn = document.getElementById('clear-board'); const undoBtn = document.getElementById('undo'); const toggleModeBtn = document.getElementById('toggle-mode'); const newGameBtn = document.getElementById('new-game'); const forbiddenRuleCheckbox = document.getElementById('forbidden-rule'); const aiDifficultySelect = document.getElementById('ai-difficulty'); // 设置Canvas尺寸 canvas.width = BOARD_PADDING * 2 + CELL_SIZE * (BOARD_SIZE - 1); canvas.height = canvas.width; // 计算棋盘实际大小和单元格大小 const boardDimension = canvas.width - BOARD_PADDING * 2; const cellDimension = boardDimension / (BOARD_SIZE - 1); // 状态变量 let board = Array(BOARD_SIZE).fill().map(() => Array(BOARD_SIZE).fill(null)); let currentColor = 'black'; // 初始为黑棋 let isDrawingMode = false; // 默认不是绘画模式 let isGameOver = false; // 游戏是否结束 let winLine = []; // 获胜的五个棋子位置 let history = []; // 用于撤销操作 let isAiMode = false; // 是否启用AI模式 let isAiThinking = false; // AI是否正在思考 let currentGameMode = 'pvp'; // 当前游戏模式 let isForbiddenRuleEnabled = true; // 是否启用禁手规则 let aiDifficulty = 'medium'; // AI难度 // 游戏历史记录 let gameHistory = JSON.parse(localStorage.getItem('gomokuHistory') || '[]'); // 更新历史记录显示 function updateHistoryDisplay() { if (gameHistory.length === 0) { historyList.innerHTML = ` <div class="text-center text-gray-500 py-8"> <i class="fa-solid fa-folder-open text-4xl mb-3 text-gray-300"></i> <p>暂无游戏记录</p> </div> `; return; } historyList.innerHTML = ''; gameHistory.forEach((game, index) => { const historyItem = document.createElement('div'); historyItem.className = 'border-b border-gray-100 p-4 hover:bg-gray-50 transition-colors duration-200'; const date = new Date(game.timestamp); const formattedDate = `${date.getFullYear()}-${(date.getMonth()+1).toString().padStart(2, '0')}-${date.getDate().toString().padStart(2, '0')} ${date.getHours().toString().padStart(2, '0')}:${date.getMinutes().toString().padStart(2, '0')}`; historyItem.innerHTML = ` <div class="flex justify-between items-start"> <div> <h3 class="font-medium">${game.winner}胜利 - ${game.mode}</h3> <p class="text-sm text-gray-500 mt-1">${formattedDate}</p> </div> <button class="text-primary hover:text-primary/80 text-sm view-history" data-index="${index}"> 查看详情 </button> </div> `; historyList.appendChild(historyItem); }); // 添加查看详情事件监听 document.querySelectorAll('.view-history').forEach(btn => { btn.addEventListener('click', (e) => { const index = parseInt(e.currentTarget.dataset.index); viewHistoryDetail(gameHistory[index]); }); }); } // 查看历史记录详情 function viewHistoryDetail(game) { // 这里可以实现查看历史记录详情的功能 alert(`查看历史记录:\n\n模式:${game.mode}\n胜利者:${game.winner}\n日期:${new Date(game.timestamp).toLocaleString()}\n\n注:完整回放功能将在未来版本中添加。`); } // 保存游戏结果到历史记录 function saveGameResult(winner) { const gameResult = { timestamp: Date.now(), winner, mode: currentGameMode === 'pvp' ? '玩家对战' : `AI对战(${aiDifficulty})`, board: JSON.parse(JSON.stringify(board)) }; gameHistory.unshift(gameResult); // 限制历史记录数量为100条 if (gameHistory.length > 100) { gameHistory.pop(); } // 保存到本地存储 localStorage.setItem('gomokuHistory', JSON.stringify(gameHistory)); // 更新历史记录显示 updateHistoryDisplay(); } // 绘制棋盘 function drawBoard() { // 绘制背景 ctx.fillStyle = '#E6B87C'; ctx.fillRect(0, 0, canvas.width, canvas.height); // 绘制网格线 ctx.strokeStyle = '#8B4513'; ctx.lineWidth = 1; // 绘制横线和竖线 for (let i = 0; i < BOARD_SIZE; i++) { // 横线 ctx.beginPath(); ctx.moveTo(BOARD_PADDING, BOARD_PADDING + i * cellDimension); ctx.lineTo(canvas.width - BOARD_PADDING, BOARD_PADDING + i * cellDimension); ctx.stroke(); // 竖线 ctx.beginPath(); ctx.moveTo(BOARD_PADDING + i * cellDimension, BOARD_PADDING); ctx.lineTo(BOARD_PADDING + i * cellDimension, canvas.height - BOARD_PADDING); ctx.stroke(); } // 绘制五个黑点 const dots = [ {x: 3, y: 3}, {x: 3, y: 11}, {x: 7, y: 7}, {x: 11, y: 3}, {x: 11, y: 11} ]; dots.forEach(dot => { ctx.beginPath(); ctx.arc( BOARD_PADDING + dot.x * cellDimension, BOARD_PADDING + dot.y * cellDimension, 4, 0, 2 * Math.PI ); ctx.fillStyle = '#333'; ctx.fill(); }); // 绘制棋子 for (let y = 0; y < BOARD_SIZE; y++) { for (let x = 0; x < BOARD_SIZE; x++) { if (board[y][x]) { // 检查是否是获胜的五个棋子 const isWinningPiece = winLine.some(pos => pos.x === x && pos.y === y); drawPiece(x, y, board[y][x], isWinningPiece); } } } } // 绘制棋子 function drawPiece(x, y, color, isWinning = false) { const centerX = BOARD_PADDING + x * cellDimension; const centerY = BOARD_PADDING + y * cellDimension; // 绘制阴影 ctx.beginPath(); ctx.arc(centerX, centerY, PIECE_SIZE * 0.95, 0, 2 * Math.PI); ctx.fillStyle = 'rgba(0, 0, 0, 0.2)'; ctx.fill(); // 绘制棋子 ctx.beginPath(); ctx.arc(centerX, centerY, PIECE_SIZE * 0.9, 0, 2 * Math.PI); // 渐变效果 const gradient = ctx.createRadialGradient( centerX - PIECE_SIZE * 0.3, centerY - PIECE_SIZE * 0.3, PIECE_SIZE * 0.1, centerX, centerY, PIECE_SIZE ); if (color === 'black' || color === 'black-marker') { gradient.addColorStop(0, isWinning ? '#FF5252' : '#555'); gradient.addColorStop(1, isWinning ? '#B71C1C' : '#000'); } else { gradient.addColorStop(0, isWinning ? '#FFCDD2' : '#fff'); gradient.addColorStop(1, isWinning ? '#EF9A9A' : '#ddd'); } ctx.fillStyle = gradient; ctx.fill(); // 高光效果 ctx.beginPath(); ctx.arc( centerX - PIECE_SIZE * 0.3, centerY - PIECE_SIZE * 0.3, PIECE_SIZE * 0.15, 0, 2 * Math.PI ); ctx.fillStyle = color === 'black' || color === 'black-marker' ? 'rgba(255, 255, 255, isWinning ? 0.4 : 0.2)' : 'rgba(255, 255, 255, isWinning ? 0.8 : 0.6)'; ctx.fill(); // 如果是禁手位置,添加标记 if (color === 'black' && isForbiddenRuleEnabled && checkForbidden(x, y)) { drawForbiddenMark(x, y); } // 如果是获胜的棋子,添加额外的高亮效果 if (isWinning) { ctx.beginPath(); ctx.arc(centerX, centerY, PIECE_SIZE * 1.1, 0, 2 * Math.PI); ctx.strokeStyle = 'rgba(255, 82, 82, 0.6)'; ctx.lineWidth = 3; ctx.setLineDash([5, 3]); ctx.stroke(); ctx.setLineDash([]); } } // 绘制禁手标记 function drawForbiddenMark(x, y) { const centerX = BOARD_PADDING + x * cellDimension; const centerY = BOARD_PADDING + y * cellDimension; ctx.beginPath(); ctx.arc(centerX, centerY, PIECE_SIZE * 0.6, 0, 2 * Math.PI); ctx.strokeStyle = 'rgba(255, 152, 0, 0.8)'; ctx.lineWidth = 2; ctx.setLineDash([3, 2]); ctx.stroke(); ctx.setLineDash([]); // 绘制X标记 ctx.beginPath(); ctx.moveTo(centerX - PIECE_SIZE * 0.4, centerY - PIECE_SIZE * 0.4); ctx.lineTo(centerX + PIECE_SIZE * 0.4, centerY + PIECE_SIZE * 0.4); ctx.moveTo(centerX - PIECE_SIZE * 0.4, centerY + PIECE_SIZE * 0.4); ctx.lineTo(centerX + PIECE_SIZE * 0.4, centerY - PIECE_SIZE * 0.4); ctx.strokeStyle = 'rgba(255, 152, 0, 0.8)'; ctx.lineWidth = 2; ctx.stroke(); } // 绘制标记(绘画模式) function drawMarker(x, y, color) { const centerX = BOARD_PADDING + x * cellDimension; const centerY = BOARD_PADDING + y * cellDimension; ctx.beginPath(); ctx.arc(centerX, centerY, PIECE_SIZE * 0.4, 0, 2 * Math.PI); ctx.fillStyle = color === 'black' ? 'rgba(0, 0, 0, 0.5)' : 'rgba(255, 255, 255, 0.7)'; ctx.fill(); ctx.beginPath(); ctx.arc(centerX, centerY, PIECE_SIZE * 0.4, 0, 2 * Math.PI); ctx.strokeStyle = color === 'black' ? 'rgba(0, 0, 0, 0.8)' : 'rgba(200, 200, 200, 0.9)'; ctx.lineWidth = 2; ctx.stroke(); } // 坐标转换:从鼠标位置到棋盘坐标 function getBoardPosition(clientX, clientY) { const rect = canvas.getBoundingClientRect(); const x = clientX - rect.left; const y = clientY - rect.top; const boardX = Math.round((x - BOARD_PADDING) / cellDimension); const boardY = Math.round((y - BOARD_PADDING) / cellDimension); if (boardX >= 0 && boardX < BOARD_SIZE && boardY >= 0 && boardY < BOARD_SIZE) { return { x: boardX, y: boardY }; } return null; } // 更新预览棋子位置 function updatePreviewPosition(clientX, clientY) { if (isGameOver || isAiThinking) return; const rect = canvas.getBoundingClientRect(); const boardPos = getBoardPosition(clientX, clientY); if (boardPos && !board[boardPos.y][boardPos.x]) { // 检查禁手规则 const isForbidden = isForbiddenRuleEnabled && currentColor === 'black' && checkForbidden(boardPos.x, boardPos.y); const centerX = BOARD_PADDING + boardPos.x * cellDimension; const centerY = BOARD_PADDING + boardPos.y * cellDimension; piecePreview.style.width = `${PIECE_SIZE}px`; piecePreview.style.height = `${PIECE_SIZE}px`; piecePreview.style.left = `${centerX - PIECE_SIZE/2}px`; piecePreview.style.top = `${centerY - PIECE_SIZE/2}px`; piecePreview.style.backgroundColor = isForbidden ? 'rgba(255, 152, 0, 0.3)' : currentColor === 'black' ? 'rgba(0, 0, 0, 0.2)' : 'rgba(255, 255, 255, 0.4)'; piecePreview.style.opacity = '1'; } else { piecePreview.style.opacity = '0'; } } // 切换玩家 function togglePlayer() { currentColor = currentColor === 'black' ? 'white' : 'black'; currentPlayer.style.backgroundColor = currentColor; playerText.textContent = currentColor === 'black' ? '黑棋' : '白棋'; } // 检查是否是禁手位置 function checkForbidden(x, y) { // 只有黑棋有禁手 if (currentColor !== 'black') return false; // 模拟落子 board[y][x] = 'black'; let isForbidden = false; // 长连禁手(六子及以上) if (checkLineLength(x, y, 6)) { isForbidden = true; } // 双三禁手 if (checkDoubleThree(x, y)) { isForbidden = true; } // 双四禁手 if (checkDoubleFour(x, y)) { isForbidden = true; } // 移除模拟的棋子 board[y][x] = null; return isForbidden; } // 检查指定方向的连子长度 function checkLineLength(x, y, targetLength) { const directions = [ {dx: 1, dy: 0}, // 水平 {dx: 0, dy: 1}, // 垂直 {dx: 1, dy: 1}, // 右下对角线 {dx: 1, dy: -1} // 右上对角线 ]; for (const dir of directions) { let count = 1; // 正方向检查 for (let i = 1; i < 6; i++) { const newX = x + dir.dx * i; const newY = y + dir.dy * i; if (newX < 0 || newX >= BOARD_SIZE || newY < 0 || newY >= BOARD_SIZE) break; if (board[newY][newX] !== 'black') break; count++; } // 反方向检查 for (let i = 1; i < 6; i++) { const newX = x - dir.dx * i; const newY = y - dir.dy * i; if (newX < 0 || newX >= BOARD_SIZE || newY < 0 || newY >= BOARD_SIZE) break; if (board[newY][newX] !== 'black') break; count++; } if (count >= targetLength) { return true; } } return false; } // 检查双三禁手 function checkDoubleThree(x, y) { const directions = [ {dx: 1, dy: 0}, // 水平 {dx: 0, dy: 1}, // 垂直 {dx: 1, dy: 1}, // 右下对角线 {dx: 1, dy: -1} // 右上对角线 ]; let threeCount = 0; for (const dir of directions) { if (checkThree(x, y, dir)) { threeCount++; } } return threeCount >= 2; } // 检查是否形成活三 function checkThree(x, y, dir) { let count = 1; let blockedEnds = 0; // 正方向检查 for (let i = 1; i < 6; i++) { const newX = x + dir.dx * i; const newY = y + dir.dy * i; if (newX < 0 || newX >= BOARD_SIZE || newY < 0 || newY >= BOARD_SIZE) { blockedEnds++; break; } if (board[newY][newX] === 'white') { blockedEnds++; break; } if (board[newY][newX] === null) { break; } count++; } // 反方向检查 for (let i = 1; i < 6; i++) { const newX = x - dir.dx * i; const newY = y - dir.dy * i; if (newX < 0 || newX >= BOARD_SIZE || newY < 0 || newY >= BOARD_SIZE) { blockedEnds++; break; } if (board[newY][newX] === 'white') { blockedEnds++; break; } if (board[newY][newX] === null) { break; } count++; } // 活三条件:3个子,且有两个开放端 return count === 3 && blockedEnds === 0; } // 检查双四禁手 function checkDoubleFour(x, y) { const directions = [ {dx: 1, dy: 0}, // 水平 {dx: 0, dy: 1}, // 垂直 {dx: 1, dy: 1}, // 右下对角线 {dx: 1, dy: -1} // 右上对角线 ]; let fourCount = 0; for (const dir of directions) { if (checkFour(x, y, dir)) { fourCount++; } } return fourCount >= 2; } // 检查是否形成活四或冲四 function checkFour(x, y, dir) { let count = 1; let blockedEnds = 0; // 正方向检查 for (let i = 1; i < 6; i++) { const newX = x + dir.dx * i; const newY = y + dir.dy * i; if (newX < 0 || newX >= BOARD_SIZE || newY < 0 || newY >= BOARD_SIZE) { blockedEnds++; break; } if (board[newY][newX] === 'white') { blockedEnds++; break; } if (board[newY][newX] === null) { break; } count++; } // 反方向检查 for (let i = 1; i < 6; i++) { const newX = x - dir.dx * i; const newY = y - dir.dy * i; if (newX < 0 || newX >= BOARD_SIZE || newY < 0 || newY >= BOARD_SIZE) { blockedEnds++; break; } if (board[newY][newX] === 'white') { blockedEnds++; break; } if (board[newY][newX] === null) { break; } count++; } // 活四或冲四条件:4个子,且有0或1个开放端 return count === 4 && blockedEnds <= 1; } // 放置棋子 function placePiece(x, y, isAI = false) { if (isGameOver || board[y][x] !== null || isAiThinking) return false; // 如果是AI模式且不是AI下棋,检查是否是轮到人类玩家 if (isAiMode && !isAI && currentColor === 'white') return false; // 检查禁手规则 if (isForbiddenRuleEnabled && currentColor === 'black' && checkForbidden(x, y)) { showForbiddenMessage(); return false; } // 记录历史 history.push({ x, y, previousValue: board[y][x], action: 'place' }); board[y][x] = isDrawingMode ? `${currentColor}-marker` : currentColor; drawBoard(); // 动画效果 const centerX = BOARD_PADDING + x * cellDimension; const centerY = BOARD_PADDING + y * cellDimension; let scale = 0; const animatePiece = () => { scale += 0.1; drawBoard(); if (isDrawingMode) { drawMarker(x, y, currentColor); } else { drawPiece(x, y, currentColor); } if (scale < 1) { requestAnimationFrame(animatePiece); } else { // 检查是否有玩家获胜 if (!isDrawingMode) { checkWin(x, y); } // 如果不是绘画模式且游戏未结束,切换玩家 if (!isGameOver && !isDrawingMode) { togglePlayer(); // 如果是AI模式且轮到AI,让AI下棋 if (isAiMode && currentColor === 'white') { setTimeout(() => { aiMakeMove(); }, 500); } } } }; animatePiece(); return true; } // 显示禁手提示 function showForbiddenMessage() { forbiddenMessage.style.opacity = '1'; setTimeout(() => { forbiddenMessage.style.opacity = '0'; }, 2000); } // 移除棋子 function removePiece(x, y) { if (isGameOver || board[y][x] === null) return false; // 记录历史 history.push({ x, y, previousValue: board[y][x], action: 'remove' }); // 动画效果 const centerX = BOARD_PADDING + x * cellDimension; const centerY = BOARD_PADDING + y * cellDimension; let scale = 1; const animateRemove = () => { scale -= 0.1; drawBoard(); if (scale > 0) { if (board[y][x].includes('marker')) { drawMarker(x, y, board[y][x].split('-')[0]); } else { drawPiece(x, y, board[y][x], scale); } requestAnimationFrame(animateRemove); } else { board[y][x] = null; drawBoard(); } }; animateRemove(); return true; } // 撤销操作 function undo() { if (isGameOver || history.length === 0) return; const lastAction = history.pop(); board[lastAction.y][lastAction.x] = lastAction.previousValue; drawBoard(); // 如果上一步是放置棋子且不是绘画模式,切换回上一个玩家 if (lastAction.action === 'place' && !isDrawingMode) { togglePlayer(); } } // 清空棋盘 function clearBoard() { // 记录历史 const currentState = JSON.parse(JSON.stringify(board)); history.push({ action: 'clear', previousState: currentState }); // 动画效果 let opacity = 1; const animateClear = () => { opacity -= 0.05; drawBoard(); // 绘制半透明遮罩 ctx.fillStyle = `rgba(230, 184, 124, ${1 - opacity})`; ctx.fillRect(0, 0, canvas.width, canvas.height); if (opacity > 0) { requestAnimationFrame(animateClear); } else { board = Array(BOARD_SIZE).fill().map(() => Array(BOARD_SIZE).fill(null)); isGameOver = false; winLine = []; winMessage.style.opacity = '0'; winMessage.style.pointerEvents = 'none'; drawBoard(); } }; animateClear(); } // 切换模式 function toggleMode() { if (isGameOver) return; isDrawingMode = !isDrawingMode; if (isDrawingMode) { toggleModeBtn.innerHTML = '<i class="fa-solid fa-chess-board"></i><span>下棋模式</span>'; toggleModeBtn.classList.remove('bg-secondary', 'hover:bg-secondary/90'); toggleModeBtn.classList.add('bg-blue-500', 'hover:bg-blue-600', 'text-white'); } else { toggleModeBtn.innerHTML = '<i class="fa-solid fa-pencil"></i><span>绘画模式</span>'; toggleModeBtn.classList.remove('bg-blue-500', 'hover:bg-blue-600', 'text-white'); toggleModeBtn.classList.add('bg-secondary', 'hover:bg-secondary/90', 'text-primary'); } } // 检查胜利 function checkWin(x, y) { const directions = [ {dx: 1, dy: 0}, // 水平 {dx: 0, dy: 1}, // 垂直 {dx: 1, dy: 1}, // 右下对角线 {dx: 1, dy: -1} // 右上对角线 ]; const color = board[y][x]; for (const dir of directions) { let count = 1; let line = [{x, y}]; // 正方向检查 for (let i = 1; i < 5; i++) { const newX = x + dir.dx * i; const newY = y + dir.dy * i; if (newX < 0 || newX >= BOARD_SIZE || newY < 0 || newY >= BOARD_SIZE) break; if (board[newY][newX] !== color) break; count++; line.push({x: newX, y: newY}); } // 反方向检查 for (let i = 1; i < 5; i++) { const newX = x - dir.dx * i; const newY = y - dir.dy * i; if (newX < 0 || newX >= BOARD_SIZE || newY < 0 || newY >= BOARD_SIZE) break; if (board[newY][newX] !== color) break; count++; line.push({x: newX, y: newY}); } // 五子连珠,游戏结束 if (count >= 5) { isGameOver = true; winLine = line; drawBoard(); // 保存游戏结果 const winner = color === 'black' ? '黑棋' : '白棋'; saveGameResult(winner); // 显示胜利信息 setTimeout(() => { winnerText.textContent = `${winner}胜利!`; winMessage.style.opacity = '1'; winMessage.style.pointerEvents = 'auto'; winMessage.querySelector('div').classList.remove('scale-90'); winMessage.querySelector('div').classList.add('scale-100'); }, 500); return true; } } return false; } // 开始新游戏 function startNewGame() { board = Array(BOARD_SIZE).fill().map(() => Array(BOARD_SIZE).fill(null)); isGameOver = false; winLine = []; currentColor = 'black'; currentPlayer.style.backgroundColor = currentColor; playerText.textContent = '黑棋'; winMessage.style.opacity = '0'; winMessage.style.pointerEvents = 'none'; winMessage.querySelector('div').classList.remove('scale-100'); winMessage.querySelector('div').classList.add('scale-90'); drawBoard(); } // 评估函数 - 增强版 function evaluateBoard() { let score = 0; // 检查所有可能的五个连续位置 for (let y = 0; y < BOARD_SIZE; y++) { for (let x = 0; x < BOARD_SIZE; x++) { score += evaluatePosition(x, y); } } // 根据难度调整AI的聪明程度 const difficultyMultiplier = { 'easy': 0.7, 'medium': 1.0, 'hard': 1.3 }; return score * difficultyMultiplier[aiDifficulty]; } // 评估单个位置的分数 function evaluatePosition(x, y) { if (board[y][x] !== EMPTY) return 0; // 只评估空位 let score = 0; // 检查AI可以形成的连子 board[y][x] = AI_COLOR; // 检查禁手 const isForbidden = isForbiddenRuleEnabled && AI_COLOR === 'black' && checkForbidden(x, y); if (isForbidden) { score -= 100000; // 禁手位置给予极低分数 } else { score -= evaluateLineForPlayer(x, y, AI_COLOR); } board[y][x] = EMPTY; // 检查人类可以形成的连子 board[y][x] = HUMAN_COLOR; score += evaluateLineForPlayer(x, y, HUMAN_COLOR); board[y][x] = EMPTY; return score; } // 评估特定玩家在特定位置的连子分数 function evaluateLineForPlayer(x, y, player) { const directions = [ {dx: 1, dy: 0}, // 水平 {dx: 0, dy: 1}, // 垂直 {dx: 1, dy: 1}, // 右下对角线
- [python画图板 ]
# -*- coding: utf-8 -*- #海龟画图 import pygame pygame.init() screen=pygame.display.set_mode([800,600]) pygame.display.set_caption("画画") radius=15 mousedown=False UnFinished=True white=255,255,255 red=255,0,0 yollow=255,255,0 black=0,0,0 blue=0,0,255 green=0,128,0 purple=128,0,128 cyan=0,255,255 orange=255,165,0 whiue=200,200,255 screen.fill(white) pygame.draw.rect(screen,white,(0,0,50,50),0) pygame.draw.rect(screen,red,(50,0,50,50),0) pygame.draw.rect(screen,green,(100,0,50,50),0) pygame.draw.rect(screen,yollow,(150,0,50,50),0) pygame.draw.rect(screen,blue,(200,0,50,50),0) pygame.draw.rect(screen,purple,(250,0,50,50),0) pygame.draw.rect(screen,cyan,(300,0,50,50),0) pygame.draw.rect(screen,black,(350,0,50,50),0) pygame.draw.rect(screen,orange,(400,0,50,50),0) pygame.draw.rect(screen,whiue,(450,0,50,50),0) color=black while UnFinished: for event in pygame.event.get(): if event.type==pygame.QUIT: UnFinished=False elif event.type==pygame.MOUSEBUTTONDOWN: mousedown=True elif event.type==pygame.MOUSEBUTTONUP: mousedown=False if mousedown: spot=pygame.mouse.get_pos() if spot[0]<=50 and spot[1]<=50: color=white elif spot[0]<=100 and spot[1]<=50: color=red elif spot[0]<=150 and spot[1]<=50: color=green elif spot[0]<=200 and spot[1]<=50: color=yollow elif spot[0]<=250 and spot[1]<=50: color=blue elif spot[0]<=300 and spot[1]<=50: color=purple elif spot[0]<=350 and spot[1]<=50: color=cyan elif spot[0]<=400 and spot[1]<=50: color=black elif spot[0]<=450 and spot[1]<=50: color=orange elif spot[0]<=500 and spot[1]<=50: color=whiue if spot[1]>=75: pygame.draw.circle(screen,color,spot,radius) pygame.display.update() pygame.quit()
#include<iostream> #include<ios> #include<cstring> using namespace std; char a[1000],n[1000]; int y,v,p; bool c=false; void mmc(){ char n[3]={'m','m','c'}; for(int j=0;j<3;j++){ if(a[j]==n[j]){ v++; } } if(v==3&&y==3){ cout<<"--C.mmc"<<endl; system("mmc"); c=!c; } v=0; } void help(){ char n[4]={'h','e','l','p'}; for(int j=0;j<4;j++){ if(a[j]==n[j]){ v++; } } if(v==4&&y==4){ cout<<"--C.help"<<endl; system("help"); c=!c; } v=0; } void assoc(){ char n[5]={'a','s','s','o','c'}; for(int j=0;j<5;j++){ if(a[j]==n[j]){ v++; } } if(v==5&&y==5){ cout<<"--C.assoc"<<endl; system("assoc"); c=!c; } v=0; } void attrib(){ char n[6]={'a','t','t','r','i','b'}; for(int j=0;j<6;j++){ if(a[j]==n[j]){ v++; } } if(v==6&&y==6){ cout<<"--C.attrib"<<endl; system("atrib"); c=!c; } v=0; } void pbreak(){ char n[5]={'b','r','e','a','k'}; for(int j=0;j<5;j++){ if(a[j]==n[j]){ v++; } } if(v==5&&y==5){ cout<<"--C.break"<<endl; system("break"); c=!c; } v=0; } int main(){ cout<<"Microsoft Windows [版本 10.0.22631.5335]\n(c) Microsoft Corporation。保留所有权利。\n\n"; while(true){ cout<<"C:\\Users\\kujj>"; cin.getline(a,100); y=strlen(a); for(int i=0;i<y;i++){ if(a[i]=='&'){ break; } } mmc(); help(); assoc(); attrib(); pbreak(); if(c==false){ cout<<"'"; for(int i=0;i<y;i++){ cout<<a[i]; } cout<<"'不是内部或外部命令,也不是可运行的程序或批处理文件\n"; } c=false; } }
-
-
通过的题目
-
最近活动
This person is lazy and didn't join any contests or homework.
题目标签
- 初窥门径
- 70
- 顺序结构
- 52
- 分支结构
- 12
- 循环结构
- 7
- 循环嵌套
- 4
- 其他
- 1
- 位运算
- 1
- 略有小成
- 1