91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 3KB
    文件類型: .zip
    金幣: 2
    下載: 1 次
    發布日期: 2021-06-06
  • 語言: Python
  • 標簽: python3??實驗樓??2048??

資源簡介

來自實驗樓的一個學習課程,不同之處在于這里用python3實現。

資源截圖

代碼片段和文件信息

#?-*-?coding:?utf-8?-*-
“““
Created?on?Wed?Jun?28?00:33:41?2017

@author:?dc
“““


import?numpy?as?np
import?curses
from?random?import?randrange?choice
from?collections?import?defaultdict

#?建立輸入-動作映射表
actions?=?[‘Up‘?‘Left‘?‘Down‘?‘Right‘?‘Restart‘?‘Exit‘]

letter_codes?=?[ord(ch)?for?ch?in?‘WASDRQwasdrq‘?]

actions_dict?=?dict(zip(letter_codesactions?*?2))

def?invert(qipan):
????
????return?[row[::-1]?for?row?in?qipan]

def?tran(qipan):
????
????return?list(np.array(qipan).T)

class?GameField(object):
????
????def?__init__(self?height?=?4?width?=?4?win_value?=?2048):
????????
????????self.height?=?height
????????
????????self.width?=?width
????????
????????self.score?=?0
????????
????????self.highscore?=?0
????????
????????self.win_value?=?win_value
????????
????????self.win?=?0
????????
????????self.gameover?=?0
????????
????????self.field?=?[[0?for?i?in?range(self.height)?]?for?j?in?range(self.width)]?
????????
????def?spawn(self):
????????
????????new_element?=?4?if?randrange(100)?>?89?else?2
????????
????????(iijj)?=?choice([(ij)?for?i?in?range(self.height)?for?j?in?range(self.width)?if?self.field[i][j]?==?0])
????????
????????self.field[ii][jj]?=?new_element
????
????def?get_field(self):
????????
????????#計算得到隨機產生的初始狀態下的field
????????self.field?=?[[0?for?i?in?range(self.width)?]?for?j?in?range(self.height)]
????????
????????num1?=?4?if?randrange(1100)?>?89?else?2
????????
????????num2?=?2?if?num1?==?4?else?4???????????????????
????????
????????(i1?j1)?=?choice([(i?j)?for?i?in?range(self.height)?for?j?in?range(self.width)?if?self.field[i][j]==0])
????????
????????(i2?j2)?=?choice([(i?j)?for?i?in?range(self.height)?for?j?in?range(self.width)?if?self.field[i][j]==0])
????????
????????self.field[i1][j1]?=?num1
?????????????
????????self.field[i2][j2]?=?num2

????????
????def?draw(self?screen):
?????????
????????help_string1?=?‘W(up)?S(down)?A(left)?D(right)‘
????????help_string2?=?‘??????R(restart)?Q(exit)‘
????????gameover_string?=?‘???????GAME?OVER‘
????????win_string?=?‘?????????You?Win‘
?????????
????????def?draw_line():
?????????????
????????????line?=?‘+‘?+?(‘+------‘?*?self.width?+?‘+‘)[1:]?
????????????
????????????separator?=?defaultdict(lambda?:?line)
????????????
????????????if?not?hasattr(draw_line?“counter“):
????????????????
????????????????draw_line.counter?=?0
????????????????
????????????screen.addstr(separator[draw_line.counter]?+?‘\n‘)
????????????
????????????draw_line.counter?+=?1

????????????#screen.addstr(‘+‘?+?“------+“?*?4?+?‘\n‘)
?????????
????????def?draw_nums(row_num):
?????????????
????????????#給定一行(默認4個)數字,如[0,?0,?0,?4],以列表存放,該函數將其畫在screen上
????????????screen.addstr(‘‘.join(‘|{:?^5}?‘.format(num)?if?num?>?0?else?‘|??????‘?for?num?in?row_num)?+?‘|‘??+?‘\n‘)
????????????????
????????#開始draw
????????screen.clear()
????????
????????screen.addstr(‘SCORE:?0‘?+??‘\n‘)
????????
????????for?row?in

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????9829??2017-06-28?00:34??2048_success.py

評論

共有 條評論