本文來源電子發燒友社區,作者:李先生, 帖子地址:https://bbs.elecfans.com/jishu_2300837_1_1.html
前言
板子本身安裝了python開發環境
使用以下指令查看版本
python --version
root@localhost:~# python --version
Python 3.6.9
配置SSH登錄
電腦和開發板使用以太網連接。這里使用J5的網口對應eno0.
電腦設置對應網卡的IP。我這里是192.168.137.1。
串口登錄開發板
設置開發板IP為192.168.137.2.
ifconfig eno0 192.168.137.2
電腦ping開發板,開發板ping電腦。
雙向能ping通。如果不能ping通關閉電腦的防火墻。
vi /etc/ssh/sshd_config
添加一行PermitRootLogin yes
允許ssh root用戶登錄,否則ssh不能以root用戶登錄。
使用crt ssh登錄
輸入密碼root
ftp傳文件
右鍵點擊ssh的窗口,點擊連接SFTP標簽頁
lls查看本地目錄
lcd跳轉本地目錄
ls查看遠程開飯啊目錄
cd跳轉遠程開發板目錄
put 發送文件到開發板
get獲取開發板的文件到本地
binary 二進制方式船速和文件推薦使用
Python開發體驗 2048小游戲
將以下2048.py文件導入到開發板
# -*- coding:UTF-8 -*-
#!/usr/bin/python2
import random
import os, sys
v = [[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0]]
def display(v, score):
print ("%4d %4d %4d %4d" % (v[0][0], v[0][1], v[0][2], v[0][3]))
print ("%4d %4d %4d %4d" % (v[1][0], v[1][1], v[1][2], v[1][3]))
print ("%4d %4d %4d %4d" % (v[2][0], v[2][1], v[2][2], v[2][3]))
print ("%4d %4d %4d %4d" % (v[3][0], v[3][1], v[3][2], v[3][3]))
print ("Total score: %d" % score)
def init(v):
for i in range(4):
v[i] = [random.choice([0, 0, 0, 2, 2, 4]) for x in range(4)]
def align(vList, direction):
for i in range(vList.count(0)):
vList.remove(0)
zeros = [0 for x in range(4 - len(vList))]
if direction == 'left':
vList.extend(zeros)
else:
vList[:0] = zeros
def addSame(vList, direction):
score = 0
if direction == 'left':
for i in [0, 1, 2]:
align(vList, direction)
if vList[i] == vList[i+1] != 0:
vList[i] *= 2
vList[i+1] = 0
score += vList[i]
return {'bool':True, 'score':score}
else:
for i in [3, 2, 1]:
align(vList, direction)
if vList[i] == vList[i-1] != 0:
vList[i] *= 2
vList[i-1] = 0
score += vList[i]
return {'bool':True, 'score':score}
return {'bool':False, 'score':score}
def handle(vList, direction):
totalScore = 0
align(vList, direction)
result = addSame(vList, direction)
while result['bool'] == True:
totalScore += result['score']
align(vList, direction)
result = addSame(vList, direction)
return totalScore
def operation(v):
totalScore = 0
gameOver = False
direction = 'left'
op = input('operator:')
if op in ['a','A']:
direction = 'left'
for row in range(4):
totalScore += handle(v[row], direction)
elif op in ['d','D']:
direction = 'right'
for row in range(4):
totalScore += handle(v[row], direction)
elif op in ['w', 'W']:
direction = 'left'
for col in range(4):
vList = [v[row][col] for row in range(4)]
totalScore += handle(vList, direction)
for row in range(4):
v[row][col] = vList[row]
elif op in ['s', 'S']:
direction = 'right'
for col in range(4):
vList = [v[row][col] for row in range(4)]
totalScore += handle(vList, direction)
for row in range(4):
v[row][col] = vList[row]
else:
print ("Invalid input,please enter a charactor in [W,S,A,D] or the lower")
gameOver = True
return {'gameOver':gameOver,'score':totalScore}
N = 0
for q in v:
N += q.count(0)
if N == 0:
gameOver = True
return {'gameover':gameOver,'score':totalScore}
num = random.choice([2,2,2,4])
k = random.randrange(1, N+1)
n = 0
for i in range(4):
for j in range(4):
if v[i][j] == 0:
n += 1
if n == k:
v[i][j] = num
break
return {'gameOver':gameOver, 'score':totalScore}
init(v)
score = 0
print ("Input:W(Up) S(Down) A(Left) D(Right), press .")
while True:
os.system("clear")
display(v, score)
result = operation(v)
print (result)
if result['gameOver'] == True:
print ("Game Over, You failed!")
print ("Your total score %d" % (score))
sys.exit(1)
else:
score += result['score']
if score >= 2048:
print ("Game Over, You Win!!!")
print ("Your total score: %d" % (score))
sys.exit(0)
put 2048.py
python 2048.py運行
w s a d回車控制上下左右移動的方向
總結
可以看到使用使用python進行腳本開發非常便捷。
-
米爾科技
+關注
關注
5文章
227瀏覽量
21209 -
MYD-J1028X
+關注
關注
1文章
16瀏覽量
289
發布評論請先 登錄
相關推薦
基于瑞芯微米爾RK3576開發板創建機器學習環境
如何安裝模擬器玩nes小游戲-基于米爾瑞芯微RK3576開發板
【米爾-Xilinx XC7A100T FPGA開發板試用】測試一
FacenetPytorch人臉識別方案--基于米爾全志T527開發板

【米爾-Xilinx XC7A100T FPGA開發板試用】+01.開箱(zmj)
基于OPENCV的相機捕捉視頻進行人臉檢測--米爾NXP i.MX93開發板

米爾基于NXP iMX.93開發板的M33處理器應用開發筆記

米爾NXP i.MX 93開發板的Qt開發指南

評論