学好 Python 不论是就业还是做副业赚钱都不错,但要学会 Python 还是要有一个学习规划。最后大家分享一份全套的 Python 学习资料,给那些想学习 Python 的小伙伴们一点帮助!
一、Python所有方向的学习路线
Python所有方向路线就是把Python常用的技术点做整理,形成各个领域的知识点汇总,它的用处就在于,你可以按照上面的知识点去找对应的学习资源,保证自己学得较为全面。
二、学习软件
工欲善其事必先利其器。学习Python常用的开发软件都在这里了,给大家节省了很多时间。
三、全套PDF电子书
书籍的好处就在于权威和体系健全,刚开始学习的时候你可以只看视频或者听某个人讲课,但等你学完之后,你觉得你掌握了,这时候建议还是得去看一下书籍,看权威技术书籍也是每个程序员必经之路。
四、入门学习视频
我们在看视频学习的时候,不能光动眼动脑不动手,比较科学的学习方法是在理解之后运用它们,这时候练手项目就很适合了。
五、实战案例
光学理论是没用的,要学会跟着一起敲,要动手实操,才能将自己的所学运用到实际当中去,这时候可以搞点实战案例来学习。
六、面试资料
我们学习Python必然是为了找到高薪的工作,下面这些面试题是来自阿里、腾讯、字节等一线互联网大厂最新的面试资料,并且有阿里大佬给出了权威的解答,刷完这一套面试资料相信大家都能找到满意的工作。
网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
new_safes = set()
new_mines = set()
for sentence in self.knowledge:
if len(sentence.cells) == 0:
self.knowledge.remove(sentence)
else:
tmp_new_safes = sentence.known_safes()
tmp_new_mines = sentence.known_mines()
if type(tmp_new_safes) is set:
new_safes |= tmp_new_safes
if type(tmp_new_mines) is set:
new_mines |= tmp_new_mines
for safe in new_safes:
self.mark_safe(safe)
for mine in new_mines:
self.mark_mine(mine)
prev_sentence = new_sentence
new_inferences = []
for sentence in self.knowledge:
if len(sentence.cells) == 0:
self.knowledge.remove(sentence)
elif prev_sentence == sentence:
break
elif prev_sentence.cells <= sentence.cells:
inf_cells = sentence.cells - prev_sentence.cells
inf_count = sentence.count - prev_sentence.count
new_inferences.append(Sentence(inf_cells, inf_count))
prev_sentence = sentence
self.knowledge += new_inferences
def make_safe_move(self):
**返回一个安全的单元格以在扫雷板上选择。必须知道该移动是安全的,而不是已经做出的移动。
该函数可以使用 self.mines、self.safes 和 self.moves_made 中的知识,但不应修改任何这些值。**
def make_safe_move(self):
safe_moves = self.safes.copy()
safe_moves -= self.moves_made
if len(safe_moves) == 0:
return None
return safe_moves.pop()
def make_random_move(self):
返回在扫雷板上进行的移动。应该在以下单元格中随机选择:
**1) 尚未被选中
- 不知道是地雷**
def make_random_move(self):
if len(self.moves_made) == 56:
return None
random_move = random.randrange(self.height), random.randrange(self.height)
not_safe_moves = self.moves_made | self.mines
while random_move in not_safe_moves:
random_move = random.randrange(self.height), random.randrange(self.height)
return random_move
============================================================================
颜色
BLACK = (0, 0, 0)
GRAY = (180, 180, 180)
WHITE = (255, 255, 255)
创建游戏
pygame.init()
size = width, height = 600, 400
screen = pygame.display.set_mode(size)
字体
字体可以在自己电脑中C:\Windows\Fonts
的位置选择自己喜欢的复制到项目中 assets/fonts目录下即可,我用的是楷体
OPEN_SANS = “assets/fonts/simkai.ttf”
smallFont = pygame.font.Font(OPEN_SANS, 20)
mediumFont = pygame.font.Font(OPEN_SANS, 28)
largeFont = pygame.font.Font(OPEN_SANS, 40)
计算面板尺寸
BOARD_PADDING = 20
board_width = ((2 / 3) * width) - (BOARD_PADDING * 2)
board_height = height - (BOARD_PADDING * 2)
cell_size = int(min(board_width / WIDTH, board_height / HEIGHT))
board_origin = (BOARD_PADDING, BOARD_PADDING)
添加图片
这里我们只用了两张图,一个是地雷,一个是用来标记地雷的旗帜
flag = pygame.image.load(“assets/images/flag.png”)
flag = pygame.transform.scale(flag, (cell_size, cell_size))
mine = pygame.image.load(“assets/images/mine.png”)
mine = pygame.transform.scale(mine, (cell_size, cell_size))
创建游戏和 AI 代理
game = Minesweeper(height=HEIGHT, width=WIDTH, mines=MINES)
ai = MinesweeperAI(height=HEIGHT, width=WIDTH)
跟踪显示的单元格、标记的单元格以及是否被地雷击中
revealed = set()
flags = set()
lost = False
最初显示游戏说明
instructions = True
while True:
检查游戏是否退出
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
screen.fill(BLACK)
显示游戏说明
if instructions:
标题
title = largeFont.render(“海拥 | 扫雷”, True, WHITE)
titleRect = title.get_rect()
titleRect.center = ((width / 2), 50)
screen.blit(title, titleRect)
Rules
rules = [
“单击一个单元格以显示它”,
“右键单击一个单元格以将其标记为地雷”,
“成功标记所有地雷以获胜!”
]
for i, rule in enumerate(rules):
line = smallFont.render(rule, True, WHITE)
lineRect = line.get_rect()
lineRect.center = ((width / 2), 150 + 30 * i)
screen.blit(line, lineRect)
开始游戏按钮
buttonRect = pygame.Rect((width / 4), (3 / 4) * height, width / 2, 50)
buttonText = mediumFont.render(“开始游戏”, True, BLACK)
buttonTextRect = buttonText.get_rect()
buttonTextRect.center = buttonRect.center
pygame.draw.rect(screen, WHITE, buttonRect)
screen.blit(buttonText, buttonTextRect)
检查是否点击播放按钮
click, _, _ = pygame.mouse.get_pressed()
if click == 1:
mouse = pygame.mouse.get_pos()
if buttonRect.collidepoint(mouse):
instructions = False
time.sleep(0.3)
pygame.display.flip()
continue
画板
cells = []
for i in range(HEIGHT):
row = []
for j in range(WIDTH):
为单元格绘制矩形
rect = pygame.Rect(
board_origin[0] + j * cell_size,
board_origin[1] + i * cell_size,
cell_size, cell_size
)
pygame.draw.rect(screen, GRAY, rect)
pygame.draw.rect(screen, WHITE, rect, 3)
如果需要,添加地雷、旗帜或数字
if game.is_mine((i, j)) and lost:
screen.blit(mine, rect)
elif (i, j) in flags:
screen.blit(flag, rect)
elif (i, j) in revealed:
neighbors = smallFont.render(
str(game.nearby_mines((i, j))),
True, BLACK
)
neighborsTextRect = neighbors.get_rect()
neighborsTextRect.center = rect.center
screen.blit(neighbors, neighborsTextRect)
row.append(rect)
cells.append(row)
AI 移动按钮
aiButton = pygame.Rect(
(2 / 3) * width + BOARD_PADDING, (1 / 3) * height - 50,
(width / 3) - BOARD_PADDING * 2, 50
)
buttonText = mediumFont.render(“AI 移动”, True, BLACK)
buttonRect = buttonText.get_rect()
buttonRect.center = aiButton.center
pygame.draw.rect(screen, WHITE, aiButton)
screen.blit(buttonText, buttonRect)
重置按钮
resetButton = pygame.Rect(
(2 / 3) * width + BOARD_PADDING, (1 / 3) * height + 20,
(width / 3) - BOARD_PADDING * 2, 50
)
buttonText = mediumFont.render(“重置”, True, BLACK)
buttonRect = buttonText.get_rect()
buttonRect.center = resetButton.center
pygame.draw.rect(screen, WHITE, resetButton)
screen.blit(buttonText, buttonRect)
显示文字
text = “失败” if lost else “获胜” if game.mines == flags else “”
text = mediumFont.render(text, True, WHITE)
textRect = text.get_rect()
textRect.center = ((5 / 6) * width, (2 / 3) * height)
screen.blit(text, textRect)
move = None
left, _, right = pygame.mouse.get_pressed()
检查右键单击以切换标记
if right == 1 and not lost:
mouse = pygame.mouse.get_pos()
for i in range(HEIGHT):
for j in range(WIDTH):
if cells[i][j].collidepoint(mouse) and (i, j) not in revealed:
if (i, j) in flags:
flags.remove((i, j))
else:
flags.add((i, j))
time.sleep(0.2)
elif left == 1:
mouse = pygame.mouse.get_pos()
如果单击 AI 按钮,则进行 AI 移动
if aiButton.collidepoint(mouse) and not lost:
move = ai.make_safe_move()
if move is None:
move = ai.make_random_move()
if move is None:
flags = ai.mines.copy()
print(“No moves left to make.”)
else:
print(“No known safe moves, AI making random move.”)
else:
print(“AI making safe move.”)
time.sleep(0.2)
重置游戏状态
elif resetButton.collidepoint(mouse):
game = Minesweeper(height=HEIGHT, width=WIDTH, mines=MINES)
ai = MinesweeperAI(height=HEIGHT, width=WIDTH)
revealed = set()
flags = set()
lost = False
continue
用户自定义动作
elif not lost:
for i in range(HEIGHT):
for j in range(WIDTH):
if (cells[i][j].collidepoint(mouse)
and (i, j) not in flags
and (i, j) not in revealed):
move = (i, j)
行动起来,更新AI知识
if move:
if game.is_mine(move):
lost = True
else:
nearby = game.nearby_mines(move)
revealed.add(move)
ai.add_knowledge(move, nearby)
pygame.display.flip()
以上就是本篇文章的全部内容
这里放了项目的完整源码:CSDN下载:https://download.csdn.net/download/qq_44273429/20681780 如果大家能给我的 Github 存储库上添一些星星就更好了😊。
一、Python所有方向的学习路线
Python所有方向的技术点做的整理,形成各个领域的知识点汇总,它的用处就在于,你可以按照下面的知识点去找对应的学习资源,保证自己学得较为全面。
二、Python必备开发工具
工具都帮大家整理好了,安装就可直接上手!
三、最新Python学习笔记
当我学到一定基础,有自己的理解能力的时候,会去阅读一些前辈整理的书籍或者手写的笔记资料,这些笔记详细记载了他们对一些技术点的理解,这些理解是比较独到,可以学到不一样的思路。
四、Python视频合集
观看全面零基础学习视频,看视频学习是最快捷也是最有效果的方式,跟着视频中老师的思路,从基础到深入,还是很容易入门的。
五、实战案例
纸上得来终觉浅,要学会跟着视频一起敲,要动手实操,才能将自己的所学运用到实际当中去,这时候可以搞点实战案例来学习。
六、面试宝典
简历模板
网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!