Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Onnx #112

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

Onnx #112

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@
**/*.bin
**/*.ckpt
archive/*
.coverage
.coverage
.eggs/
*.egg-info/
Empty file added animation/__init__.py
Empty file.
Empty file added board/__init__.py
Empty file.
4 changes: 2 additions & 2 deletions board/coordinate.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ def convert_from_gtp_format(self, pos: str) -> int:
x_coord = i
y_coord = self.board_size - int(pos[1:])

pos = x_coord + OB_SIZE + (y_coord + OB_SIZE) * self.board_size_with_ob
p = x_coord + OB_SIZE + (y_coord + OB_SIZE) * self.board_size_with_ob

return pos
return p

def convert_to_gtp_format(self, pos: int) -> str:
"""プログラム内部の座標からGTP形式に変換する。
Expand Down
20 changes: 10 additions & 10 deletions board/go_board.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""碁盤のデータ定義と操作処理。
"""
from typing import List, Tuple, NoReturn
from typing import Deque, List, Tuple
from collections import deque
import numpy as np

Expand Down Expand Up @@ -106,7 +106,7 @@ def get_cross4(pos: int) -> List[int]:
self.clear()


def clear(self) -> NoReturn:
def clear(self) -> None:
"""盤面の初期化
"""
self.moves = 1
Expand All @@ -128,7 +128,7 @@ def clear(self) -> NoReturn:
self.strings.clear()
self.record.clear()

def put_stone(self, pos: int, color: Stone) -> NoReturn:
def put_stone(self, pos: int, color: Stone) -> None:
"""指定された座標に指定された色の石を石を置く。

Args:
Expand Down Expand Up @@ -184,7 +184,7 @@ def put_stone(self, pos: int, color: Stone) -> NoReturn:
self.record.save(self.moves, color, pos, self.positional_hash)
self.moves += 1

def put_handicap_stone(self, pos: int, color: Stone) -> NoReturn:
def put_handicap_stone(self, pos: int, color: Stone) -> None:
"""指定された座標に指定された色の置き石を置く。

Args:
Expand Down Expand Up @@ -408,7 +408,7 @@ def get_all_legal_pos(self, color: Stone) -> List[int]:
"""
return [pos for pos in self.onboard_pos if self.is_legal(pos, color)]

def display(self, sym: int=0) -> NoReturn:
def display(self, sym: int=0) -> None:
"""盤面を表示する。
"""
print_err(self.get_board_string(sym=sym))
Expand Down Expand Up @@ -440,7 +440,7 @@ def get_board_string(self, sym: int=0) -> str:
return board_string


def display_self_atari(self, color: Stone) -> NoReturn:
def display_self_atari(self, color: Stone) -> None:
"""アタリに突っ込んだ時に取られる石の数を表示する。取られない場合は0。デバッグ用。

Args:
Expand All @@ -457,7 +457,7 @@ def display_self_atari(self, color: Stone) -> NoReturn:
self_atari_string += '\n'
print_err(self_atari_string)

def get_board_size(self) -> NoReturn:
def get_board_size(self) -> int:
"""碁盤の大きさを取得する。

Returns:
Expand Down Expand Up @@ -508,7 +508,7 @@ def get_symmetrical_coordinate(self, pos: int, sym: int) -> int:
"""
return self.sym_map[sym][pos]

def set_komi(self, komi: float) -> NoReturn:
def set_komi(self, komi: float) -> None:
"""コミを設定する。

Args:
Expand All @@ -535,7 +535,7 @@ def get_to_move(self) -> Stone:
last_move_color, _, _ = self.record.get(self.moves - 1)
return Stone.get_opponent_color(last_move_color)

def get_move_history(self) -> List[Tuple[Stone, int, np.array]]:
def get_move_history(self) -> List[Tuple[Stone, int, np.ndarray]]:
"""着手の履歴を取得する。

Returns:
Expand Down Expand Up @@ -579,7 +579,7 @@ def count_score(self) -> int: # pylint: disable=R0912
for pos in self.onboard_pos: # pylint: disable=R1702
if board[pos] is Stone.EMPTY:
pos_list = []
pos_queue = deque()
pos_queue: Deque[int] = deque()
pos_queue.append(pos)
color = Stone.EMPTY
while pos_queue:
Expand Down
4 changes: 2 additions & 2 deletions board/handicap.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""置き石の座標。
"""
from typing import List
from typing import List, Optional


handicap_coordinate_map = {
Expand Down Expand Up @@ -67,7 +67,7 @@
}


def get_handicap_coordinates(size: int, handicaps: int) -> List[int]:
def get_handicap_coordinates(size: int, handicaps: int) -> Optional[List[str]]:
"""置き石の座標リストを取得する。

Args:
Expand Down
12 changes: 6 additions & 6 deletions board/pattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
class Pattern:
"""配石パターンクラス。
"""
def __init__(self, board_size: int, pos_func: Callable[[int], int]):
def __init__(self, board_size: int, pos_func: Callable[[int, int], int]):
"""Patternクラスのコンストラクタ。

Args:
Expand Down Expand Up @@ -99,7 +99,7 @@ def __init__(self, board_size: int, pos_func: Callable[[int], int]):

self.clear()

def clear(self) -> NoReturn:
def clear(self) -> None:
"""周囲の石のパターンを初期状態にする。
"""
board_start = OB_SIZE
Expand All @@ -116,7 +116,7 @@ def clear(self) -> NoReturn:
self.pat3[self.POS(board_start, y_pos)] = \
self.pat3[self.POS(board_start, y_pos)] | 0x0cc3

def remove_stone(self, pos: int) -> NoReturn:
def remove_stone(self, pos: int) -> None:
"""周囲の石のパターンから石を取り除く。

Args:
Expand All @@ -125,7 +125,7 @@ def remove_stone(self, pos: int) -> NoReturn:
for i, shift in enumerate(self.update_pos):
self.pat3[pos + shift] = self.pat3[pos + shift] & pattern_mask[i][0]

def put_stone(self, pos: int, color: Stone) -> NoReturn:
def put_stone(self, pos: int, color: Stone) -> None:
"""周囲の石のパターンの石を追加する。

Args:
Expand Down Expand Up @@ -161,7 +161,7 @@ def get_eye_color(self, pos: int) -> Stone:
"""
return self.eye[self.pat3[pos]]

def display(self, pos: int) -> NoReturn:
def display(self, pos: int) -> None:
"""指定した座標の周囲の石のパターンを表示する。(デバッグ用)

Args:
Expand Down Expand Up @@ -299,7 +299,7 @@ def get_pat3_symmetry8(pat3: int) -> List[int]:
return symmetries


def copy_pattern(dst: Pattern, src: Pattern) -> NoReturn:
def copy_pattern(dst: Pattern, src: Pattern) -> None:
"""配石パターンのデータをコピーする。

Args:
Expand Down
18 changes: 9 additions & 9 deletions board/record.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""着手の履歴の保持。
"""
from typing import NoReturn, Tuple
from typing import Tuple
import numpy as np

from board.constant import PASS, MAX_RECORDS
Expand All @@ -19,15 +19,15 @@ def __init__(self):
self.hash_value = np.zeros(shape=MAX_RECORDS, dtype=np.uint64)
self.handicap_pos = []

def clear(self) -> NoReturn:
def clear(self) -> None:
"""データを初期化する。
"""
self.color = [Stone.EMPTY] * MAX_RECORDS
self.pos = [PASS] * MAX_RECORDS
self.hash_value.fill(0)
self.handicap_pos = []

def save(self, moves: int, color: Stone, pos: int, hash_value: np.array) -> NoReturn:
def save(self, moves: int, color: Stone, pos: int, hash_value: np.ndarray) -> None:
"""着手の履歴の記録する。

Args:
Expand All @@ -43,15 +43,15 @@ def save(self, moves: int, color: Stone, pos: int, hash_value: np.array) -> NoRe
else:
print_err("Cannot save move record.")

def save_handicap(self, pos: int) -> NoReturn:
def save_handicap(self, pos: int) -> None:
"""置き石の座標を記録する。

Args:
pos (int): 置き石の座標。
"""
self.handicap_pos.append(pos)

def has_same_hash(self, hash_value: np.array) -> bool:
def has_same_hash(self, hash_value: np.ndarray) -> bool:
"""同じハッシュ値があるかを確認する。

Args:
Expand All @@ -60,9 +60,9 @@ def has_same_hash(self, hash_value: np.array) -> bool:
Returns:
bool: 同じハッシュ値がある場合はTrue、なければFalse。
"""
return np.any(self.hash_value == hash_value)
return np.any(self.hash_value == hash_value).item()

def get(self, moves: int) -> Tuple[Stone, int, np.array]:
def get(self, moves: int) -> Tuple[Stone, int, np.ndarray]:
"""指定した着手を取得する。

Args:
Expand All @@ -73,7 +73,7 @@ def get(self, moves: int) -> Tuple[Stone, int, np.array]:
"""
return (self.color[moves], self.pos[moves], self.hash_value[moves])

def get_hash_history(self) -> np.array:
def get_hash_history(self) -> np.ndarray:
"""ハッシュ値の履歴を取得する。

Returns:
Expand All @@ -82,7 +82,7 @@ def get_hash_history(self) -> np.array:
return self.hash_value


def copy_record(dst: Record, src: Record) -> NoReturn:
def copy_record(dst: Record, src: Record) -> None:
"""着手履歴をコピーする。

Args:
Expand Down
Loading