赞
踩
下载安装ollama 客户端: https://ollama.com/download/windows 安装完成后 后台运行
【1】. 普通7B版 安装指令:(适合8G显存)
ollama run gemma:7b
如果你是第一次部署,它会自动下载!
【2】. 7B的全量版本:(需要16G左右的显存)
ollama run gemma:7b-instruct-fp16
【3】. 2B轻量版:(适合CPU会低配电脑安装)
ollama run gemma:2b
安装完成后在cmd输入对应的run命令即可启动
访问地址: https://huggingface.co/chat/
// 定义蛇的结构 var Snake = function() { this.x = []; this.y = []; this.direction = 'right'; // 默认向右移动 }; Snake.prototype.addBody = function(x, y) { this.x.unshift(x); this.y.unshift(y); }; Snake.prototype.removeBody = function() { this.x.pop(); this.y.pop(); }; // 创建画布 var canvas = document.createElement('canvas'); canvas.width = 400; canvas.height = 400; document.body.appendChild(canvas); var ctx = canvas.getContext('2d'); // 设置蛇的初始位置 var snake = new Snake(); snake.addBody(150, 180); snake.addBody(140, 180); snake.addBody(130, 180); // 设置食物的随机位置 var foodX = Math.floor(Math.random() * (canvas.width / 20)) * 20; var foodY = Math.floor(Math.random() * (canvas.height / 20)) * 20; // 监听键盘按下事件 window.addEventListener('keydown', function(e) { switch (e.code) { case 'ArrowUp': if (snake.direction !== 'down') { snake.direction = 'up'; } break; case 'ArrowDown': if (snake.direction !== 'up') { snake.direction = 'down'; } break; case 'ArrowLeft': if (snake.direction !== 'right') { snake.direction = 'left'; } break; case 'ArrowRight': if (snake.direction !== 'left') { snake.direction = 'right'; } break; } }); // 渲染函数 function draw() { ctx.clearRect(0, 0, canvas.width, canvas.height); // 绘制背景 ctx.fillStyle = '#ddd'; ctx.fillRect(0, 0, canvas.width, canvas.height); // 绘制边界 ctx.strokeStyle = '#999'; ctx.lineWidth = 2; ctx.strokeRect(1, 1, canvas.width - 2, canvas.height - 2); // 绘制食物 ctx.fillStyle = '#f00'; ctx.fillRect(foodX, foodY, 20, 20); // 记录蛇头的位置 var headX = snake.x[0]; var headY = snake.y[0]; // 根据方向移动蛇身体 for (let i = 1; i < snake.x.length; i++) { snake.x[i - 1] = snake.x[i]; snake.y[i - 1] = snake.y[i]; } // 根据当前方向移动蛇头 switch (snake.direction) { case 'up': snake.y[0] -= 20; break; case 'down': snake.y[0] += 20; break; case 'left': snake.x[0] -= 20; break; case 'right': snake.x[0] += 20; break; } // 检查是否撞到自己或者边界 if (headX === -1 || headY === -1 || headX >= canvas.width || headY >= canvas.height || isCollide()) { return alert('Game Over!'); } // 检测是否吃到食物 if (headX === foodX && headY === foodY) { snake.addBody(headX, headY); foodX = Math.floor(Math.random() * (canvas.width / 20)) * 20; foodY = Math.floor(Math.random() * (canvas.height / 20)) * 20; } else { snake.removeBody(); } // 绘制蛇身体 ctx.fillStyle = '#6c6'; for (let x of snake.x) { for (let y of snake.y) { ctx.fillRect(x, y, 20, 20); } } } // 判断是否碰撞到自己 function isCollide() { for (let i = 1; i < snake.x.length; i++) { if (snake.x[0] === snake.x[i] && snake.y[0] === snake.y[i]) { return true; } } return false; } setInterval(draw, 100);
你对于程序员这个工作的未来发展方向持怎样的看法呢?
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。