#julialang and computer shogi (japanese chess)
TRANSCRIPT
![Page 1: #Julialang and Computer Shogi (Japanese Chess)](https://reader034.vdocuments.us/reader034/viewer/2022042607/55a2c0ff1a28abfe3e8b47b7/html5/thumbnails/1.jpg)
#JULIALANG AND SHOGI(JAPANESE CHESS)twitter: @kimrin Takeshi KIMURA
![Page 2: #Julialang and Computer Shogi (Japanese Chess)](https://reader034.vdocuments.us/reader034/viewer/2022042607/55a2c0ff1a28abfe3e8b47b7/html5/thumbnails/2.jpg)
IN THIS PRESENTATION:
!
About us
Why we choose #Julialang
Shogi and Chess: differences between two games
principles and technics of Shogi playing software
![Page 3: #Julialang and Computer Shogi (Japanese Chess)](https://reader034.vdocuments.us/reader034/viewer/2022042607/55a2c0ff1a28abfe3e8b47b7/html5/thumbnails/3.jpg)
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 !
![Page 4: #Julialang and Computer Shogi (Japanese Chess)](https://reader034.vdocuments.us/reader034/viewer/2022042607/55a2c0ff1a28abfe3e8b47b7/html5/thumbnails/4.jpg)
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
![Page 5: #Julialang and Computer Shogi (Japanese Chess)](https://reader034.vdocuments.us/reader034/viewer/2022042607/55a2c0ff1a28abfe3e8b47b7/html5/thumbnails/5.jpg)
CHESS:
Chess:
8x8=64 squares
about 80 available moves in middle game
computer programs already won by human professionals
![Page 6: #Julialang and Computer Shogi (Japanese Chess)](https://reader034.vdocuments.us/reader034/viewer/2022042607/55a2c0ff1a28abfe3e8b47b7/html5/thumbnails/6.jpg)
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!
![Page 7: #Julialang and Computer Shogi (Japanese Chess)](https://reader034.vdocuments.us/reader034/viewer/2022042607/55a2c0ff1a28abfe3e8b47b7/html5/thumbnails/7.jpg)
PRINCIPLE AND TECHNICS IN SHOGI PLAYING SOFTWARE
Alpha-Beta search
bit board and magic board technics
machine-learning evaluation functions
![Page 8: #Julialang and Computer Shogi (Japanese Chess)](https://reader034.vdocuments.us/reader034/viewer/2022042607/55a2c0ff1a28abfe3e8b47b7/html5/thumbnails/8.jpg)
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
![Page 9: #Julialang and Computer Shogi (Japanese Chess)](https://reader034.vdocuments.us/reader034/viewer/2022042607/55a2c0ff1a28abfe3e8b47b7/html5/thumbnails/9.jpg)
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)
recursivecalls
find good moves
cutoff redundantsearch
pseudo code (simplified)
![Page 10: #Julialang and Computer Shogi (Japanese Chess)](https://reader034.vdocuments.us/reader034/viewer/2022042607/55a2c0ff1a28abfe3e8b47b7/html5/thumbnails/10.jpg)
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
![Page 11: #Julialang and Computer Shogi (Japanese Chess)](https://reader034.vdocuments.us/reader034/viewer/2022042607/55a2c0ff1a28abfe3e8b47b7/html5/thumbnails/11.jpg)
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!
![Page 12: #Julialang and Computer Shogi (Japanese Chess)](https://reader034.vdocuments.us/reader034/viewer/2022042607/55a2c0ff1a28abfe3e8b47b7/html5/thumbnails/12.jpg)
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
![Page 13: #Julialang and Computer Shogi (Japanese Chess)](https://reader034.vdocuments.us/reader034/viewer/2022042607/55a2c0ff1a28abfe3e8b47b7/html5/thumbnails/13.jpg)
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
![Page 14: #Julialang and Computer Shogi (Japanese Chess)](https://reader034.vdocuments.us/reader034/viewer/2022042607/55a2c0ff1a28abfe3e8b47b7/html5/thumbnails/14.jpg)
MJOU = White King(OU,王)
tori/toru = capture
!
Magic board (More advanced technics):
calculate dest bitmap by multiples MAGIC numbers(one direction hash)
![Page 15: #Julialang and Computer Shogi (Japanese Chess)](https://reader034.vdocuments.us/reader034/viewer/2022042607/55a2c0ff1a28abfe3e8b47b7/html5/thumbnails/15.jpg)
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
![Page 16: #Julialang and Computer Shogi (Japanese Chess)](https://reader034.vdocuments.us/reader034/viewer/2022042607/55a2c0ff1a28abfe3e8b47b7/html5/thumbnails/16.jpg)
CONCLUSION:
We will attend WCSC24 (The 24th World Computer Shogi Championship)
Mecha Lady Shogi (メカ女子将棋, @mechajyo) is using #Julialangfor 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!