Skip to main content

[中] 零儲 - My Childhood Game Programmed in Python

在小弟介紹今日主題之前,請各位看看下面數張在討論區的截圖:



若果你開始有似曾相識的感覺,也許你跟我都是香港同一年代的人。「零儲 (俗音: cou5)」、「007入子彈」、「儲波擋」這一個家族的遊戲,在我小學的時代幾乎每個同學都懂得玩。小息時,我走到朋友仔面前,只要雙手一拍,對方馬上會意,開展激戰。甚至到我唸高中時,偶爾一次重提這遊戲,不少同學都有共鳴。

雖則奇蹟地「零儲」滲透港九新界各小學的程度極高、幾乎人人懂玩,但是它的遊戲細則似乎是到處不同。小朋友玩遊戲時,不服輸就隨口自創招式,硬說自己贏了,使到「零儲」的規則時常突變。「零儲」就似成了一個物種,它的基因在物競天擇的小學世界中進化成數個物種,使到這種人傳人的遊戲,規則在以訛傳訛下竟在各小學發展出不同「門派」。

在我的小學中,「零儲」是單挑遊戲,但亦有網民分享了多人混戰的版本;我記憶中,當玩家受到任何傷害時就馬上死亡,但網上亦有變異版新增了「血量」之概念以增加遊戲長度。當然,招式的名稱及效果亦各有不同,甚至有「寵物小精靈」、「龍珠」等主題,可謂百花齊放,可見小學生的創意力非同小可。

雖然各派有別,但核心規則是一樣的:用招式擊敗對手。玩家會而回合制同時出招,但出招會消耗「氣」。玩家可以選擇在任意回合放棄攻擊、改作「儲氣」以增加自身「氣」量,可是如果這樣做,玩家將有機會暴露於對手的攻擊下。隨攻擊或儲氣,玩家亦可防守:不但自身不受傷害,更變相消耗了對方的「氣」。

規則

下面是我的小學最流行的版本:

單對單遊戲,開始時雙方「氣」量為0。每回合雙方同時出招,先以任何招式成功攻擊對方者勝。可用招式如下:


招式種類 招式名稱 所耗「氣」量 效果
儲氣類 儲氣 0 自身「氣」量 +1
防守類 保護 0 防止「開槍」及「龜波氣功」所造成的傷害
攻擊類 開槍 1 攻擊對方
同等攻擊互相抵消,高等攻擊則會壓倒低等攻擊

唯一例外:
開槍」雖為最低等攻擊,但可壓倒「封印」
(引用小學生的語言:「開槍射爆個封印」)
龜波氣功 2
降龍十八掌 3
封印 4
如來神掌 5

注:記憶中,亦有「反彈」、「上天堂」(6氣攻擊)、「落地獄」(7氣攻擊)、「超級儲氣」(自身「氣」量 +1000)等招式,但它們普遍認受性不大,亦不常見。

高中時我已曾用計算機自定程式功能,按以上規則寫了一個遊戲程式,可以跟AI對打。所以今天我用Python再寫一次亦非難事。不過為了改善遊戲平衡及刺激感,我對規則有以下小修改:

  • 開始時,每位玩家有5點生命值及5點「氣」。生命值先跌至零者為輸。
  • 如果「開槍」、「龜波氣功」或「降龍十八掌」成功擊中對手,會造成1點傷害;「封印」及「如來神掌」則造成2點傷害。任何被成功防禦、抵消或壓倒的招式不會造成傷害,但所需「氣」量仍會被消耗。
    • 當玩家一用「開槍」而玩家二用「封印」,玩家一會消耗1點「氣」而不受傷害;反之玩家二不但會消耗4點「氣」,更會受到「開槍」帶來的1點傷害。
  • 當任何玩家生命值等於1時,他用「儲氣」會有自身「氣」量 +2 的效果。

Code

The following code is written in Python 3.7.4:
程式有四大模式:
  • 正常(雙玩家)模式:按螢幕指示按enter則可進入,每位玩家輪流輸入指令。
  • 單打/AI模式: 開始程式時輸入「AI mode」後按enter,玩家會與一個簡單AI對局。
  • 觀察模式:開始程式時輸入「Observer mode」後按enter,可觀察兩個簡單AI對局。
  • 經典模式:開始程式時輸入「Classic mode」後按enter,程式會改用小學經典規則。

Directions for future research

Back to English baby.

As a case study in Game Theory (Analysis of Sequential Game)

The longer I look into this programme, the more I think about it in Game Theory. It is a finite sequential game, each round involving a simultaneous game – by Nash’s Existence Theorem, of course there should be a Nash Equilibrium somewhere.

Problem arises when you actually try to solve the game in textbook approaches, and you will find that it is an enormous complicated job. I might write on that in the future, and explore whether there is a systematic approach to solve this kind of sequential game where the action opportunity expands and shrinks as the game goes on (due to the existence of the MP system).

As a subject in Evolutionary Machine Learning 

The AI coded here is a dumb AI. It rolls a dice then acts accordingly, with no rational strategy to follow. Could machine learning be applied to write an AI that can beat humans using strategies? Could I code such that in a natural-selection manner, hundreds of thousands of dumb AI fight each other and evolutionarily mutate along the way, until one comes out on top with a supreme strategy that it can beat all its peers? How would that strategy be supported in a Nash Equilibrium? I am still very new to the field of machine learning, and I might return to this topic in the future.

明日百變,我沒有芳心能許

Comments

Popular posts from this blog

Simulating a Lift with Python Part 1A: the Curse of the Basement Floors

The Curse of the Basement Floors Tired of waiting for lifts? I am! In my University, there’s a building  that’s (in-)famous for its four painfully slow lifts. The ground floor is crowded everyday with students who want to attend lectures. However, it is not a simple lifting job. The twist is there are two basement levels under the ground floor. While most of the students are waiting on the ground floor and want to go UP, the lifts are often called DOWN, against the majority’s wills, by a few people on the basement floors. That often means an extra few minutes of standing, sighing, and complaining. I am always frustrated by this. I mean yeah, of course those people down there also need a lift, but I can’t help but think if there exists no basement floor at all, it got to be faster now that the majority the lift system is serving are initialized on the ground floor. If it is not that the lift must make a detour every time it comes back down to the ground floor, the whole sy...