일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- GT-S80
- Splunk
- Button
- SPL
- install
- Series
- RNN
- pip
- LSTM
- DFS
- imread
- synology
- SciPy
- pycharm
- E-P1
- pandas
- 삼성소프트웨어멤버십
- 알고리즘
- CNN
- mean
- mariadb
- index
- keras
- javascript
- Python
- ipad
- Numpy
- GitHub
- Lotto
- dataframe
Archives
- Today
- Total
잠토의 잠망경
[python] 딥러닝과 바둑 본문
gotypes.py
import enum
#tag::color[]
class Player(enum.Enum):
black = 1
white = 2
@property
def other(self):
return Player.black if self == Player.white else Player.white
#end::color[]
#tag::points[]
from collections import namedtuple
class Point(namedtuple('Point', 'row col')):
def neighbors(self):
return[
Point(self.row-1, self.col), # A A
Point(self.row+1, self.col), # B C X D
Point(self.row, self.col-1), # C B
Point(self.row, self.col+1) # D
]
#end::points[]
goboard_slow.py
import copy
from dlgo.gotypes import Player
class Move():
def __init__(self, point=None, is_pass=False, is_resign=False):
assert(point is not None) ^ is_pass ^ is_resign
self.point = point
self.is_play = (self.point is not None)
self.is_pass = is_pass
self.is_resign = is_resign
# 바둑판에 돌을 놓는다.
@classmethod
def play(cls, point):
return Move(point=point)
# 차례를 넘긴다.
@classmethod
def pass_turn(cls):
return Move(is_pass=True)
# 현재 대국을 포기한다.
@classmethod
def resign(cls):
return Move(is_resign=True)
# tag::strings[]
class GoString():
def __init__(self, color, stones, liberties):
self.color = color
self.stones = set(stones)
self.liberties = set(liberties)
def remove_liberty(self, point):
self.liberties.remove(point)
def add_liberty(self, point):
self.liberties.add(point)
def merged_with(self, go_string):
assert go_string.color == self.color
combined_stones = self.stones | go_string.stones
return GoString(self.color, combined_stones, (self.liberties | go_string.liberties) - combined_stones)
@property
def num_liberties(self):
return len(self.liberties)
def __eq__(self, other):
return isinstance(other, GoString) and \
self.color == other.color and \
self.stones == other.stones and \
self.liberties == other.liberties
# end::strings[]
대표
Comments