SlideShare a Scribd company logo
1 of 17
Download to read offline
Go, Kotlin Go!
Go is an abstract strategy board game for
two players, in which the aim is to surround
more territory than the opponent.
The game was invented in ancient China more
than 2,500 years ago and is believed to be
the oldest board game continuously played
today.
The game reached Japan in the 7th century CE
—where it is called go ( 碁 ) or igo ( 囲碁 ).
The modern version of the game as we know it
today was formalized in Japan in the 15th
century.
AlphaGo Zero
Rules
At the beginning of the game, the
board is empty.
One player takes the black
stones, the other player the
white ones.
The player with the black stones
makes the first move.
A move is made by placing a stone
on an interesection.
A player can play on any
unoccupied intersection he wants
to.
A stone does not move after being
played, unless it is captured and
taken off the board.
The previous board position
cannot be recreated.
Eyes and false eyes
There is no special rule for life and death of
groups, they just emerge from capture rule.
How cool is that?
Diagrams from https://senseis.xmp.net/
Computer Go
Nice client
https://sabaki.yichuanshen.de/
Strongest Open Source Go program
http://pachi.or.cz/
DeepLearning Open Source
https://github.com/gcp/leela-zero
Strongest commercial Go program
https://www.remi-coulom.fr/CrazyStone/
Old generation Open Source
https://www.gnu.org/software/gnugo/
Deep Learning and the Game of Go opens
up the world of deep learning and AI by
teaching you to build your own Go-
playing machine. You'll explore key deep
learning ideas like neural networks and
reinforcement learning and maybe even
step up your Go game a notch or two. AI
experts and Go enthusiasts Max Pumperla
and Kevin Ferguson take you every step
of the way as you build your Go bot and
train it from eternal loser to hardened
Go player.
https://github.com/uberto/kakomu
I think that this Python code
would look better in Kotlin...
KAKOMU ( 囲む )
https://github.com/uberto/kakomu
In Japanese it means “to surround” and the
ideogram is the same that in the game of Go
First commit 2nd Jan 2018
42 classes and about 700 loc (excluding tests)
It’s able to play at a intermediate level on a
9x9 board
Next big feature will be DeepLearning support
Lessons Learned
●
Don’t fear the ?
●
Avoid !! at any cost
●
Immutability is nice but…
●
Algebraic Data Types to
avoid if
●
Premature Optimization
is...
●
Kotlin is awesome!
How to capture?
Stone: each position on the board can be empty|white|black
String: a set of stones which are in contact
Liberties: the empty positions touched by a string
Group: a group of strings that “work together”. Computer
don’t care about it.
Look at code Board.placeStone()
How to decide who won?
A B C D E F G H J
9 . x x x o . o . o 9
8 x x x o o o o o . 8
7 . x x x o o . o o 7
6 x x x o o o o . o 6
5 . x x x x x o o o 5
4 x x x x x o o o . 4
3 x . x . x x o o o 3
2 x x . x x x x x o 2
1 x . x x . x o o o 1
A B C D E F G H J
Final score black: 45 white: 36
Minimax
Minimax algorithm with
alternate moves. A minimax
algorithm is a recursive
algorithm for choosing the
next move in an n-player
game, usually a two-player
game. A value is associated
with each position or state
of the game.
AlphaBeta pruning
The benefit of alpha–beta
pruning lies in the fact that
branches of the search tree can
be eliminated. This way, the
search time can be limited to
the 'more promising' subtree,
and a deeper search can be
performed in the same time.
The optimization reduces the
effective depth to slightly more
than half that of simple minimax
if the nodes are evaluated in an
optimal or near optimal order
(best choice for side on move
ordered first at each node).
Monte Carlo Tree Search
The focus of Monte Carlo tree search is on the analysis of the most
promising moves, expanding the search tree based on random sampling
of the search space. The application of Monte Carlo tree search in
games is based on many playouts. In each playout, the game is played
out to the very end by selecting moves at random. The final game
result of each playout is then used to weight the nodes in the game
tree so that better nodes are more likely to be chosen in future
playouts.
Performance
Timings for a complete rollout from start single thread
on my laptop i7 2Ghz (in millisec on 9x9 and 19x19)
10 160 validmove without deepcopy
6 65 immutable goStrings
3.5 38 neighbors map
1.5 31 faster isAnEye
1.3 27 simpleKo
1.25 25 selectMove returning State
0.7 12 remove System.nanotime
0.5 4.5 RandomBot evaluating single move
0.33 2.4 single swap instead of shuffle
0.27 2.1 array instead of map for winCount
`
Next step

More Related Content

Similar to Go kotlin, Go!

Learning to Play Complex Games
Learning to Play Complex GamesLearning to Play Complex Games
Learning to Play Complex Games
butest
 
TornadoBrickSmasherUserManual
TornadoBrickSmasherUserManualTornadoBrickSmasherUserManual
TornadoBrickSmasherUserManual
Clayton Schembri
 

Similar to Go kotlin, Go! (20)

MONTE-CARLO TREE SEARCH FOR THE “MR JACK” BOARD GAME
MONTE-CARLO TREE SEARCH FOR THE “MR JACK” BOARD GAME MONTE-CARLO TREE SEARCH FOR THE “MR JACK” BOARD GAME
MONTE-CARLO TREE SEARCH FOR THE “MR JACK” BOARD GAME
 
Monte carlo tree search for the
Monte carlo tree search for theMonte carlo tree search for the
Monte carlo tree search for the
 
MONTE-CARLO TREE SEARCH FOR THE “MR JACK” BOARD GAME
MONTE-CARLO TREE SEARCH FOR THE “MR JACK” BOARD GAME MONTE-CARLO TREE SEARCH FOR THE “MR JACK” BOARD GAME
MONTE-CARLO TREE SEARCH FOR THE “MR JACK” BOARD GAME
 
OthelloFinal.pptx
OthelloFinal.pptxOthelloFinal.pptx
OthelloFinal.pptx
 
Artificial Intelligence
Artificial IntelligenceArtificial Intelligence
Artificial Intelligence
 
research for game dave
 research for game dave  research for game dave
research for game dave
 
Learning to Play Complex Games
Learning to Play Complex GamesLearning to Play Complex Games
Learning to Play Complex Games
 
0-miniproject sem 4 review 1(1)(2).pptx
0-miniproject sem 4 review 1(1)(2).pptx0-miniproject sem 4 review 1(1)(2).pptx
0-miniproject sem 4 review 1(1)(2).pptx
 
3. research
3. research3. research
3. research
 
Adversarial search
Adversarial searchAdversarial search
Adversarial search
 
Topic - 6 (Game Playing).ppt
Topic - 6 (Game Playing).pptTopic - 6 (Game Playing).ppt
Topic - 6 (Game Playing).ppt
 
quarto
quartoquarto
quarto
 
Endless vision gdd_revised_1214
Endless vision gdd_revised_1214Endless vision gdd_revised_1214
Endless vision gdd_revised_1214
 
International journal of engineering issues vol 2015 - no 2 - paper1
International journal of engineering issues   vol 2015 - no 2 - paper1International journal of engineering issues   vol 2015 - no 2 - paper1
International journal of engineering issues vol 2015 - no 2 - paper1
 
2. initial plans
2. initial plans2. initial plans
2. initial plans
 
TornadoBrickSmasherUserManual
TornadoBrickSmasherUserManualTornadoBrickSmasherUserManual
TornadoBrickSmasherUserManual
 
Space Brawl Game Design Document
Space Brawl Game Design DocumentSpace Brawl Game Design Document
Space Brawl Game Design Document
 
Dave
DaveDave
Dave
 
Game Playing In A I Final
Game  Playing In  A I  FinalGame  Playing In  A I  Final
Game Playing In A I Final
 
Games.4
Games.4Games.4
Games.4
 

More from Uberto Barbini

When Tdd Goes Awry (IAD 2013)
When Tdd Goes Awry (IAD 2013)When Tdd Goes Awry (IAD 2013)
When Tdd Goes Awry (IAD 2013)
Uberto Barbini
 
Boost your-oop-with-fp
Boost your-oop-with-fpBoost your-oop-with-fp
Boost your-oop-with-fp
Uberto Barbini
 

More from Uberto Barbini (9)

CQRS with Event Source in Functional sauce served by Kotlin
CQRS with Event Source in Functional sauce served by Kotlin CQRS with Event Source in Functional sauce served by Kotlin
CQRS with Event Source in Functional sauce served by Kotlin
 
It's All About Morphisms
It's All About MorphismsIt's All About Morphisms
It's All About Morphisms
 
Legacy is Good
Legacy is GoodLegacy is Good
Legacy is Good
 
The Role of Testing in DevOps
The Role of Testing in DevOpsThe Role of Testing in DevOps
The Role of Testing in DevOps
 
When Tdd Goes Awry (IAD 2013)
When Tdd Goes Awry (IAD 2013)When Tdd Goes Awry (IAD 2013)
When Tdd Goes Awry (IAD 2013)
 
When Tdd Goes Awry
When Tdd Goes AwryWhen Tdd Goes Awry
When Tdd Goes Awry
 
Boost your-oop-with-fp
Boost your-oop-with-fpBoost your-oop-with-fp
Boost your-oop-with-fp
 
The Effective Team
The Effective TeamThe Effective Team
The Effective Team
 
Develop Gwt application in TDD
Develop Gwt application in TDDDevelop Gwt application in TDD
Develop Gwt application in TDD
 

Recently uploaded

Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
amitlee9823
 
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
amitlee9823
 
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
amitlee9823
 
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night StandCall Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
amitlee9823
 
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night StandCall Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
amitlee9823
 
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
amitlee9823
 
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al BarshaAl Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
AroojKhan71
 
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
amitlee9823
 
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get CytotecAbortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Riyadh +966572737505 get cytotec
 

Recently uploaded (20)

Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
 
Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -
Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -
Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -
 
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Predicting Loan Approval: A Data Science Project
Predicting Loan Approval: A Data Science ProjectPredicting Loan Approval: A Data Science Project
Predicting Loan Approval: A Data Science Project
 
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
 
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
 
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 nightCheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
 
April 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's AnalysisApril 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's Analysis
 
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
 
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night StandCall Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
 
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night StandCall Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
 
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
 
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al BarshaAl Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
 
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
 
Generative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and MilvusGenerative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and Milvus
 
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get CytotecAbortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
 
Midocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFxMidocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFx
 
Capstone Project on IBM Data Analytics Program
Capstone Project on IBM Data Analytics ProgramCapstone Project on IBM Data Analytics Program
Capstone Project on IBM Data Analytics Program
 
Anomaly detection and data imputation within time series
Anomaly detection and data imputation within time seriesAnomaly detection and data imputation within time series
Anomaly detection and data imputation within time series
 
Mature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptxMature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptx
 

Go kotlin, Go!

  • 1. Go, Kotlin Go! Go is an abstract strategy board game for two players, in which the aim is to surround more territory than the opponent. The game was invented in ancient China more than 2,500 years ago and is believed to be the oldest board game continuously played today. The game reached Japan in the 7th century CE —where it is called go ( 碁 ) or igo ( 囲碁 ). The modern version of the game as we know it today was formalized in Japan in the 15th century.
  • 2.
  • 4. Rules At the beginning of the game, the board is empty. One player takes the black stones, the other player the white ones. The player with the black stones makes the first move. A move is made by placing a stone on an interesection. A player can play on any unoccupied intersection he wants to. A stone does not move after being played, unless it is captured and taken off the board. The previous board position cannot be recreated.
  • 5. Eyes and false eyes There is no special rule for life and death of groups, they just emerge from capture rule. How cool is that? Diagrams from https://senseis.xmp.net/
  • 6. Computer Go Nice client https://sabaki.yichuanshen.de/ Strongest Open Source Go program http://pachi.or.cz/ DeepLearning Open Source https://github.com/gcp/leela-zero Strongest commercial Go program https://www.remi-coulom.fr/CrazyStone/ Old generation Open Source https://www.gnu.org/software/gnugo/
  • 7. Deep Learning and the Game of Go opens up the world of deep learning and AI by teaching you to build your own Go- playing machine. You'll explore key deep learning ideas like neural networks and reinforcement learning and maybe even step up your Go game a notch or two. AI experts and Go enthusiasts Max Pumperla and Kevin Ferguson take you every step of the way as you build your Go bot and train it from eternal loser to hardened Go player. https://github.com/uberto/kakomu I think that this Python code would look better in Kotlin...
  • 8. KAKOMU ( 囲む ) https://github.com/uberto/kakomu In Japanese it means “to surround” and the ideogram is the same that in the game of Go First commit 2nd Jan 2018 42 classes and about 700 loc (excluding tests) It’s able to play at a intermediate level on a 9x9 board Next big feature will be DeepLearning support
  • 9. Lessons Learned ● Don’t fear the ? ● Avoid !! at any cost ● Immutability is nice but… ● Algebraic Data Types to avoid if ● Premature Optimization is... ● Kotlin is awesome!
  • 10. How to capture? Stone: each position on the board can be empty|white|black String: a set of stones which are in contact Liberties: the empty positions touched by a string Group: a group of strings that “work together”. Computer don’t care about it. Look at code Board.placeStone()
  • 11.
  • 12. How to decide who won? A B C D E F G H J 9 . x x x o . o . o 9 8 x x x o o o o o . 8 7 . x x x o o . o o 7 6 x x x o o o o . o 6 5 . x x x x x o o o 5 4 x x x x x o o o . 4 3 x . x . x x o o o 3 2 x x . x x x x x o 2 1 x . x x . x o o o 1 A B C D E F G H J Final score black: 45 white: 36
  • 13. Minimax Minimax algorithm with alternate moves. A minimax algorithm is a recursive algorithm for choosing the next move in an n-player game, usually a two-player game. A value is associated with each position or state of the game.
  • 14. AlphaBeta pruning The benefit of alpha–beta pruning lies in the fact that branches of the search tree can be eliminated. This way, the search time can be limited to the 'more promising' subtree, and a deeper search can be performed in the same time. The optimization reduces the effective depth to slightly more than half that of simple minimax if the nodes are evaluated in an optimal or near optimal order (best choice for side on move ordered first at each node).
  • 15. Monte Carlo Tree Search The focus of Monte Carlo tree search is on the analysis of the most promising moves, expanding the search tree based on random sampling of the search space. The application of Monte Carlo tree search in games is based on many playouts. In each playout, the game is played out to the very end by selecting moves at random. The final game result of each playout is then used to weight the nodes in the game tree so that better nodes are more likely to be chosen in future playouts.
  • 16. Performance Timings for a complete rollout from start single thread on my laptop i7 2Ghz (in millisec on 9x9 and 19x19) 10 160 validmove without deepcopy 6 65 immutable goStrings 3.5 38 neighbors map 1.5 31 faster isAnEye 1.3 27 simpleKo 1.25 25 selectMove returning State 0.7 12 remove System.nanotime 0.5 4.5 RandomBot evaluating single move 0.33 2.4 single swap instead of shuffle 0.27 2.1 array instead of map for winCount