Skip to content

Latest commit

 

History

History
58 lines (50 loc) · 1.55 KB

README.md

File metadata and controls

58 lines (50 loc) · 1.55 KB

baduk

Fast baduk (go, weiqi) game logic for Python.

macfergus

Quick example

>>> from baduk import GameState, Player, Move, Point, print_board
>>> game = GameState.new_game(9)
>>> print(game.next_player)
Player.black
>>> print_board(game.board)
 9 .........
 8 .........
 7 .........
 6 .........
 5 .........
 4 .........
 3 .........
 2 .........
 1 .........
   ABCDEFGHJ
>>> game = game.apply_move(Move.play(Point(3, 3)))
>>> print(game.next_player)
Player.white
>>> game = game.apply_move(Move.play(Point(4, 3)))
>>> game = game.apply_move(Move.play(Point(4, 3)))
>>> game = game.apply_move(Move.play(Point(4, 4)))
>>> game = game.apply_move(Move.play(Point(5, 3)))
>>> print_board(game.board)
 9 .........
 8 .........
 7 .........
 6 .........
 5 ..o......
 4 ..ox.....
 3 ..x......
 2 .........
 1 .........
   ABCDEFGHJ

Notes

  • Rows and columns are 1-indexed, not 0-indexed. So the 1-1 point is the lower left corner of the board.
  • The largest supported board size is 19x19.

Other features

  • Dead stone removal (remove_dead_stones function). Based on a Monte Carlo method. Not very sophisticated, but usually gets the easy cases right.
  • Encoding feature planes for machine learning. The Board class has several functions that return board properties as numpy arrays:
    • black_stones_as_array
    • white_stone_as_array
    • stones_with_n_liberties_as_array
    • stones_with_min_liberties_as_array
    • liberties_as_array