SlideShare uma empresa Scribd logo
1 de 16
Baixar para ler offline
#JULIALANG AND SHOGI(JAPANESE CHESS)
twitter: @kimrin	

Takeshi KIMURA
IN THIS PRESENTATION:
!

About us	

Why we choose #Julialang	

Shogi and Chess: differences between two games	

principles and technics of Shogi playing software
ABOUT US:

Mecha Lady Shogi team (twitter = @mechajyo, 5 members):	

the team of Shogi Program developers	

with 2 Lady Shogi Professionals, 2 ladies and a geek:)	

developing Japanese Chess Program written in #Julialang !
WHY WE CHOOSE #JULIALANG:
Speed	

most other Shogi programs are written in C/C++	

needed H/W resources: CPU and Memory access (not HDD
access)	

Maintenance	

dynamic language like code style is very useful for developing
Shogi programs
CHESS:
Chess:	

8x8=64 squares	

about 80 available moves in
middle game	

computer programs already
won by human professionals
SHOGI
Shogi	

9x9 = 81 squares	

can reuse captured pieces	

about160 available moves in
endgame	

most of pieces can promote in
enemy’s field	

computer programs NOT YET
win by human professionals!
PRINCIPLE AND TECHNICS IN
SHOGI PLAYING SOFTWARE

Alpha-Beta search	

bit board and magic board technics	

machine-learning evaluation functions
ALPHA-BETA SEARCH
problem:	

in the given Shogi board representation, find best move from
its available moves	

solution:	

search partial tree of game tree and find a best move and root
node’s tree value(Evaluation Value)	

Depth-first search by using a recursive function
function AlphaBeta( gs::GameStatus, WB, depth, alpha, beta)

if depth <= 0.0 

va = eval(gs, alpha, beta)

return va

end



moves = generate(gs)



for i = 1:length(moves)

makeMove( gs, moves[i], WB)



val = -AlphaBeta( gs, WB$1, depth-1.0, -beta, -alpha)



takeBack( gs, moves[i], WB)



if val > alpha # alpha-update

alpha = val



# save this move



if alpha >= beta # beta-cutoff

return beta

end

end

end

alpha

end


return eval	

(leaf node)
generate moves

(good move first)

pseudo code	

(simplified)

recursive

calls

find good moves
cutoff redundant

search
PSEUDO CODE SUMMARY
If node is leaf node, return the value of evaluation function	

Generate child node moves(=available moves)	

For each moves:	

Make move	

Call myself(=this function) in NegaMax manner	

Take back move	

If it’s good move, record this move(=Alpha Update)	

if very good move, cutoff subsequent child node’s search(Beta Cutoff)	

return beta	

return alpha
BITBOARD TECHNICS	

(IN MOVE GENERATION)
In chess programs, board representation is 64bit Unsigned Integer
value: each bit represents existence of pieces	

Pawn, Knight,…, King, for each piece kinds, there are 2 bitmap
values(one for White, another for Black)	

In Shogi programs, square of the board is 81. So in ordinal
programming languages(such as C++), we use 3x32bit Unsigned
Integer = 96bit bitmap values	

#Julialang’s 128bit Unsigned Integer is suitable for storing 81bit Shogi
bitmaps!
BASIC IDEAS OF BITBOARD
for each pieces of white side(for example: White King):	

get piece position that of move from	

dest = BitMapTable( piece, from, White) # available moves table	

dest &= (not White pieces) # with single bitwise AND!	

for each dest bits:	

generates Move and stores move buffers
SOURCE CODE OF WHITE KING
target = (~p.WhitePieces) & MaskOfBoard

!
bbp = p.bb[MJOU] #White King’s bitmap
while bbp > uint128(0)
from = trailing_zeros(bbp)
bbp $= BitSet[from+1]
dest::BitBoard = target & gs.AttackTableNonSlide[MJOU,from+1]
toru::BitBoard = dest & p.BlackPieces #captured pieces
while dest > uint128(0)
to = trailing_zeros(dest)
dest $= BitSet[to+1]
toriflag = ((toru & BitSet[to+1]) > 0)?FLAG_TORI:0
count += 1
out[count] = Move(MJOU,from,to,toriflag,p.square[to+1]&0x0f,0)::Move
InsertMoveAB(count,out,gs)
end
end
MJOU = White King(OU,王)	

tori/toru = capture	

!

Magic board (More advanced technics):	

calculate dest bitmap by multiples MAGIC numbers(one
direction hash)
MACHINE LEARNING

EVALUATION FUNCTIONS
This technic is established by Hoki-san’s “Bonanza” program	

Evaluation function value = dot(WeightVector, FeatureVector)	

Val = w1*f1 + w2*f2 + … + wn*fn	

Hoki-san established the way of learning Weight Vectors by Machine Learning(reinforcement
learning)	

King - OpponentKing - another piece relationships	

King - piece - and another piece relationships	

(Three pieces relationships)	

We use Hoki-san’s fv.bin for calculation function values
CONCLUSION:
We will attend WCSC24 (The 24th World Computer Shogi Championship)	

Mecha Lady Shogi (メカ女子将棋, @mechajyo) is using #Julialang

for her programming language	

メカ=Mecha, 女子=Girl, Lady	

But actually, playing ability of mechajyo is not so strong :(	

We will also attend DenOu Sen tournament (電王戦トーナメント) may will be hold in Nov. 2014	

電王=Electrical King	

Thank you!

Mais conteúdo relacionado

Semelhante a #Julialang and Computer Shogi (Japanese Chess)

Need to make a ReversiOthello Board game in JAVAThe board size ca.pdf
Need to make a ReversiOthello Board game in JAVAThe board size ca.pdfNeed to make a ReversiOthello Board game in JAVAThe board size ca.pdf
Need to make a ReversiOthello Board game in JAVAThe board size ca.pdf
flashfashioncasualwe
 
ACI-Webinar-3-MinMaxAlphaBetaPruning-TicTacToe.pptx
ACI-Webinar-3-MinMaxAlphaBetaPruning-TicTacToe.pptxACI-Webinar-3-MinMaxAlphaBetaPruning-TicTacToe.pptx
ACI-Webinar-3-MinMaxAlphaBetaPruning-TicTacToe.pptx
ssuser1eba67
 
19012011102_Nayan Oza_Practical-7_AI.pdf
19012011102_Nayan Oza_Practical-7_AI.pdf19012011102_Nayan Oza_Practical-7_AI.pdf
19012011102_Nayan Oza_Practical-7_AI.pdf
NayanOza
 
«Python на острие бритвы: PyPy project» Александр Кошкин, Positive Technologies
«Python на острие бритвы: PyPy project» Александр Кошкин, Positive Technologies«Python на острие бритвы: PyPy project» Александр Кошкин, Positive Technologies
«Python на острие бритвы: PyPy project» Александр Кошкин, Positive Technologies
it-people
 
Objectives Create a Java program using programming fundamentals (fi.docx
Objectives Create a Java program using programming fundamentals (fi.docxObjectives Create a Java program using programming fundamentals (fi.docx
Objectives Create a Java program using programming fundamentals (fi.docx
amit657720
 
JAVA- need help with my code! Need help updating the GUI part of my co.docx
JAVA- need help with my code! Need help updating the GUI part of my co.docxJAVA- need help with my code! Need help updating the GUI part of my co.docx
JAVA- need help with my code! Need help updating the GUI part of my co.docx
olsenlinnea427
 

Semelhante a #Julialang and Computer Shogi (Japanese Chess) (20)

Need to make a ReversiOthello Board game in JAVAThe board size ca.pdf
Need to make a ReversiOthello Board game in JAVAThe board size ca.pdfNeed to make a ReversiOthello Board game in JAVAThe board size ca.pdf
Need to make a ReversiOthello Board game in JAVAThe board size ca.pdf
 
[Ultracode Munich #4] Demo on Animatron by Anton Kotenko
[Ultracode Munich #4] Demo on Animatron by Anton Kotenko[Ultracode Munich #4] Demo on Animatron by Anton Kotenko
[Ultracode Munich #4] Demo on Animatron by Anton Kotenko
 
ACI-Webinar-3-MinMaxAlphaBetaPruning-TicTacToe.pptx
ACI-Webinar-3-MinMaxAlphaBetaPruning-TicTacToe.pptxACI-Webinar-3-MinMaxAlphaBetaPruning-TicTacToe.pptx
ACI-Webinar-3-MinMaxAlphaBetaPruning-TicTacToe.pptx
 
19012011102_Nayan Oza_Practical-7_AI.pdf
19012011102_Nayan Oza_Practical-7_AI.pdf19012011102_Nayan Oza_Practical-7_AI.pdf
19012011102_Nayan Oza_Practical-7_AI.pdf
 
Music as data
Music as dataMusic as data
Music as data
 
«Python на острие бритвы: PyPy project» Александр Кошкин, Positive Technologies
«Python на острие бритвы: PyPy project» Александр Кошкин, Positive Technologies«Python на острие бритвы: PyPy project» Александр Кошкин, Positive Technologies
«Python на острие бритвы: PyPy project» Александр Кошкин, Positive Technologies
 
Ai
AiAi
Ai
 
Artificial intelligence games
Artificial intelligence gamesArtificial intelligence games
Artificial intelligence games
 
[SI] Ada Lovelace Day 2014 - Tampon Run
[SI] Ada Lovelace Day 2014  - Tampon Run[SI] Ada Lovelace Day 2014  - Tampon Run
[SI] Ada Lovelace Day 2014 - Tampon Run
 
(Alpha) Zero to Elo (with demo)
(Alpha) Zero to Elo (with demo)(Alpha) Zero to Elo (with demo)
(Alpha) Zero to Elo (with demo)
 
AI.ppt
AI.pptAI.ppt
AI.ppt
 
Artificial intelligence - python
Artificial intelligence - pythonArtificial intelligence - python
Artificial intelligence - python
 
Objectives Create a Java program using programming fundamentals (fi.docx
Objectives Create a Java program using programming fundamentals (fi.docxObjectives Create a Java program using programming fundamentals (fi.docx
Objectives Create a Java program using programming fundamentals (fi.docx
 
Python Puzzlers
Python PuzzlersPython Puzzlers
Python Puzzlers
 
Speeding up bowtie2 by improving cache-hit rate
Speeding up bowtie2 by improving cache-hit rateSpeeding up bowtie2 by improving cache-hit rate
Speeding up bowtie2 by improving cache-hit rate
 
Swift for tensorflow
Swift for tensorflowSwift for tensorflow
Swift for tensorflow
 
Atari 2600 VCS Programming
Atari 2600 VCS ProgrammingAtari 2600 VCS Programming
Atari 2600 VCS Programming
 
The Ring programming language version 1.7 book - Part 53 of 196
The Ring programming language version 1.7 book - Part 53 of 196The Ring programming language version 1.7 book - Part 53 of 196
The Ring programming language version 1.7 book - Part 53 of 196
 
API Python Chess: Distribution of Chess Wins based on random moves
API Python Chess: Distribution of Chess Wins based on random movesAPI Python Chess: Distribution of Chess Wins based on random moves
API Python Chess: Distribution of Chess Wins based on random moves
 
JAVA- need help with my code! Need help updating the GUI part of my co.docx
JAVA- need help with my code! Need help updating the GUI part of my co.docxJAVA- need help with my code! Need help updating the GUI part of my co.docx
JAVA- need help with my code! Need help updating the GUI part of my co.docx
 

Último

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Último (20)

[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 

#Julialang and Computer Shogi (Japanese Chess)

  • 1. #JULIALANG AND SHOGI(JAPANESE CHESS) twitter: @kimrin Takeshi KIMURA
  • 2. IN THIS PRESENTATION: ! About us Why we choose #Julialang Shogi and Chess: differences between two games principles and technics of Shogi playing software
  • 3. ABOUT US: Mecha Lady Shogi team (twitter = @mechajyo, 5 members): the team of Shogi Program developers with 2 Lady Shogi Professionals, 2 ladies and a geek:) developing Japanese Chess Program written in #Julialang !
  • 4. WHY WE CHOOSE #JULIALANG: Speed most other Shogi programs are written in C/C++ needed H/W resources: CPU and Memory access (not HDD access) Maintenance dynamic language like code style is very useful for developing Shogi programs
  • 5. CHESS: Chess: 8x8=64 squares about 80 available moves in middle game computer programs already won by human professionals
  • 6. SHOGI Shogi 9x9 = 81 squares can reuse captured pieces about160 available moves in endgame most of pieces can promote in enemy’s field computer programs NOT YET win by human professionals!
  • 7. PRINCIPLE AND TECHNICS IN SHOGI PLAYING SOFTWARE Alpha-Beta search bit board and magic board technics machine-learning evaluation functions
  • 8. ALPHA-BETA SEARCH problem: in the given Shogi board representation, find best move from its available moves solution: search partial tree of game tree and find a best move and root node’s tree value(Evaluation Value) Depth-first search by using a recursive function
  • 9. function AlphaBeta( gs::GameStatus, WB, depth, alpha, beta) if depth <= 0.0 va = eval(gs, alpha, beta) return va end moves = generate(gs) for i = 1:length(moves) makeMove( gs, moves[i], WB) val = -AlphaBeta( gs, WB$1, depth-1.0, -beta, -alpha) takeBack( gs, moves[i], WB) if val > alpha # alpha-update alpha = val # save this move if alpha >= beta # beta-cutoff return beta end end end alpha end return eval (leaf node) generate moves
 (good move first) pseudo code (simplified) recursive
 calls find good moves cutoff redundant
 search
  • 10. PSEUDO CODE SUMMARY If node is leaf node, return the value of evaluation function Generate child node moves(=available moves) For each moves: Make move Call myself(=this function) in NegaMax manner Take back move If it’s good move, record this move(=Alpha Update) if very good move, cutoff subsequent child node’s search(Beta Cutoff) return beta return alpha
  • 11. BITBOARD TECHNICS (IN MOVE GENERATION) In chess programs, board representation is 64bit Unsigned Integer value: each bit represents existence of pieces Pawn, Knight,…, King, for each piece kinds, there are 2 bitmap values(one for White, another for Black) In Shogi programs, square of the board is 81. So in ordinal programming languages(such as C++), we use 3x32bit Unsigned Integer = 96bit bitmap values #Julialang’s 128bit Unsigned Integer is suitable for storing 81bit Shogi bitmaps!
  • 12. BASIC IDEAS OF BITBOARD for each pieces of white side(for example: White King): get piece position that of move from dest = BitMapTable( piece, from, White) # available moves table dest &= (not White pieces) # with single bitwise AND! for each dest bits: generates Move and stores move buffers
  • 13. SOURCE CODE OF WHITE KING target = (~p.WhitePieces) & MaskOfBoard ! bbp = p.bb[MJOU] #White King’s bitmap while bbp > uint128(0) from = trailing_zeros(bbp) bbp $= BitSet[from+1] dest::BitBoard = target & gs.AttackTableNonSlide[MJOU,from+1] toru::BitBoard = dest & p.BlackPieces #captured pieces while dest > uint128(0) to = trailing_zeros(dest) dest $= BitSet[to+1] toriflag = ((toru & BitSet[to+1]) > 0)?FLAG_TORI:0 count += 1 out[count] = Move(MJOU,from,to,toriflag,p.square[to+1]&0x0f,0)::Move InsertMoveAB(count,out,gs) end end
  • 14. MJOU = White King(OU,王) tori/toru = capture ! Magic board (More advanced technics): calculate dest bitmap by multiples MAGIC numbers(one direction hash)
  • 15. MACHINE LEARNING
 EVALUATION FUNCTIONS This technic is established by Hoki-san’s “Bonanza” program Evaluation function value = dot(WeightVector, FeatureVector) Val = w1*f1 + w2*f2 + … + wn*fn Hoki-san established the way of learning Weight Vectors by Machine Learning(reinforcement learning) King - OpponentKing - another piece relationships King - piece - and another piece relationships (Three pieces relationships) We use Hoki-san’s fv.bin for calculation function values
  • 16. CONCLUSION: We will attend WCSC24 (The 24th World Computer Shogi Championship) Mecha Lady Shogi (メカ女子将棋, @mechajyo) is using #Julialang
 for her programming language メカ=Mecha, 女子=Girl, Lady But actually, playing ability of mechajyo is not so strong :( We will also attend DenOu Sen tournament (電王戦トーナメント) may will be hold in Nov. 2014 電王=Electrical King Thank you!