Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
對戰三平棋
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
MarkFly
March 20, 2018
Programming
0
150
對戰三平棋
SIMPEI小遊戲實作分享 @ iOS Taipei
MarkFly
March 20, 2018
Tweet
Share
More Decks by MarkFly
See All by MarkFly
關於 Mobile Developer 用 Flutter 去寫 Web 這檔事
mark33699
0
10
關於我在 visionOS 上 寫影片貼圖 app 這檔事
mark33699
0
130
iOS、Android、Flutter超級比一比
mark33699
1
970
如何使用Swift遙控你的樂高
mark33699
0
62
直播簡單講
mark33699
1
86
多執行緒編程
mark33699
0
49
演算法到底是在演哪一齣
mark33699
0
67
Other Decks in Programming
See All in Programming
CSC307 Lecture 09
javiergs
PRO
1
840
Raku Raku Notion 20260128
hareyakayuruyaka
0
340
AI によるインシデント初動調査の自動化を行う AI インシデントコマンダーを作った話
azukiazusa1
1
740
AIと一緒にレガシーに向き合ってみた
nyafunta9858
0
250
「ブロックテーマでは再現できない」は本当か?
inc2734
0
1k
今から始めるClaude Code超入門
448jp
8
9k
IFSによる形状設計/デモシーンの魅力 @ 慶應大学SFC
gam0022
1
310
CSC307 Lecture 01
javiergs
PRO
0
690
Vibe Coding - AI 驅動的軟體開發
mickyp100
0
180
AI Agent の開発と運用を支える Durable Execution #AgentsInProd
izumin5210
7
2.3k
AIフル活用時代だからこそ学んでおきたい働き方の心得
shinoyu
0
140
Oxlintはいいぞ
yug1224
5
1.3k
Featured
See All Featured
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
190
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
76
sira's awesome portfolio website redesign presentation
elsirapls
0
150
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.4k
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
100
Being A Developer After 40
akosma
91
590k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
Rebuilding a faster, lazier Slack
samanthasiow
85
9.4k
Ethics towards AI in product and experience design
skipperchong
2
200
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
34k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
Transcript
對戰三平棋 ⼩遊戲實作分享 iOS@Taipei 2018/3/20
謝騰⾶ 前接案公司iOS⼯程師 前鼎新電腦ERP顧問 Line: ledway917 歡迎各種合作
https://www.youtube.com/watch?v=iGzv1t9rV0c
None
遊戲規則 • ⼈數: 2⼈ • 率先連成三⼦者獲勝 • 每⼈各4顆棋⼦ • 棋盤分成上下兩個世界
遊戲流程 1. 第⼀顆棋只能放在上界中間四個位置 2. 雙⽅輪流放⼦ 3. 雙⽅輪流走⼦(只能走到異界的相臨位置) 4. 若過程中我⽅在同⼀世界夾住對⽅棋⼦ 則我⽅可將該棋⼦移⾄任何位置
BUT • 連成四⼦不算 • 四⼦移走⼀顆也不算 • 吹走對⼿棋⼦連三還是不算 • ⾃⼰走到⼈家中間去被夾住................................不算
None
在圖片上疊⼀個透明的view view上⾯拉格⼦的imageView imageView⽤autoresize去配合圖片 棋盤是⼀張圖 如何在適應各種螢幕尺⼨的前提下 讓棋⼦可以對準裡⾯的格⼦
對棋⼦imageView加入⼿勢UIPanGestureRecognizer 拿到座標就去修改棋⼦imageView的center 如何讓棋⼦移動
遍歷所有的位置 去算該位置是否夠靠近(這邊要做誤差修正) 太遠則清空提⽰ 如何讓移動時格⼦出現提⽰
• 第⼀回合 • 寫死5,6,9,10 • 放⼦、吹⼦ • All You Can
Place 各階段如何判斷可不可下 showMoveHint
1. 先判斷天堂或地獄 2. 地獄:有公式 3. 天堂:四個⾓跟中間也有公式 4. 邊棋只好HardCode 5. PS.右圖x跟y顛倒了.......(懶得改圖了Orz)
比較難搞的是走⼦階段
1. 同⾊同界的棋⼦數⼤於3 1. 同界周圍(x或y相減絕對值為1)是否有同⾊棋(第⼆顆棋) 1. 有第三顆棋(註1) 1. 地獄 1. 贏了
2. 天堂 1. 沒有第四顆棋(註2) 1. 贏了 如何判斷是否連線 checkLink(currentChess:Chess)
思路:根據1號棋跟2號棋的相對位置推算3號棋的位置 1. 可能在中間、可能在旁邊 2. 從八個⽅向去發散 如何判斷有無第三顆棋 assign3rdChessXandY
思路:窮舉10條可能的路線, 是否都有同⾊的棋⼦ 1. 由現有棋盤上的棋⼦坐標算出序號(by公式) 2. [(0,1),(4,1),(8,1),(12,1),(0,4),(1,4),(2,4),(3,4),(0,5),(3,3)] //(從哪個開頭,遞增多少) 3. 展出每條路線的序號跟第⼀點比對 如何判斷有無第四顆棋
isLineFourChess
思路:跟找連線判斷類似 如何判斷是否夾⼦ checkBetween(currentChess:Chess) -> Chess?
對戰流程 1. 設定:開房間的⼈為主場, 主場⼀律紅棋 2. 若WaitingRoom裡無房就開房,反之加入 3. 有⼈加入有把房間移到MappedRoom(先刪後加) 4. 等⼈加入時,
取消或斷線要把WaitingRoom的資料刪除 5. 隨機決定誰先 6. 主場建立新比賽
Firebase function 1. Database.database().reference(withPath: ".info/connected") 2. onDisconnectRemoveValue 3. onDisconnectSetValue 4.
observeSingleEvent 1. childAdded 2. childRemoved 3. childChanged 4. childMoved 5. value 5. observe 6. removeAllObservers 7. childByAutoId 8. child 9. setValue 10. removeValue
監聽對象 1. 換⼿ 2. 對⼿走⼦ 3. 對⼿夾⼦ 4. 對⼿贏了 5.
對⼿投降 6. 續戰邀約 7. 建立新比賽
再來⼀碗
https://www.asovision.com/simpei/ 了解更多…
感謝聆聽 圖片來源http://en.aobo-shop.com/114-simpei-japanese.html