https://ar.anyone.tech/QkHIWrCSy3iXoP_fS-2snSKIdPYBqGHNmPDya89lWHE#QE8jBZoNz... https://ar.anyone.tech/ExicPTy-13WSydg1y-DHVOPtR8L6IMDMiMc7ZAGt2_Q
once upon a time my logging proxy us-- anyway uh whup ahh uhm ahhm ... errr uhm uh ahm .. ok here's the go code. it has a bug. this is my first go code ever! warning: i mean the game with black and white stones, not the language sadly import numpy as np class Go: EMPTY = ' ' BLACK = 'X' WHITE = 'O' EDGE = '#' MARK = '\0' NEIGHBORS = np.array([[-1,0],[0,-1],[1,0],[0,1]]) def __init__(self, size=10): self.clear(size) @property def board(self): return self.edged_board[1:-1,1:-1] @property def size(self): return self.board.shape[0] def __repr__(self): return str(self.board.T) def clear(self, size = None): if size is not None: self.edged_board = np.full((size+2, size+2), Go.EDGE) self.board[:] = Go.EMPTY self.turn = Go.WHITE self.passes = 0 def pass_(self, player): if player != self.turn: raise ValueError(f"It is {self.turn}'s turn, not {player}'s") self.turn = Go.BLACK if player == Go.WHITE else Go.WHITE self.passes += 1 def move(self, col, row, player): if player != self.turn: raise ValueError(f"It is {self.turn}'s turn, not {player}'s") try: if row < 0 or col < 0: raise IndexError() if self.board[col, row] != Go.EMPTY: raise ValueError(f"{self.board[col, row]} has already moved there.") except IndexError: raise ValueError(f"{col}, {row} is off the board.") try: self.board[col, row] = player members, liberties = self.liberties_needslock(col, row) if len(liberties) == 0: raise ValueError(f"No liberties: {members}.") except: self.board[col, row] = Go.EMPTY raise self.turn = Go.BLACK if player == Go.WHITE else Go.WHITE for neighbor in Go.NEIGHBORS: colrow = neighbor + [col, row] if self.board[*colrow] == self.turn: members, liberties = self.liberties_needslock(*colrow) if len(liberties) == 0: self.board[*members.T] = Go.EMPTY self.passes = 0 def play(self): while self.passes < 2: print(self) move = input(f'{self.turn}: ') if move: try: move = [int(x) for x in move.split(' ')] self.move(*move, self.turn) except Exception as e: print(type(e),e) else: self.pass_(self.turn) def liberties_needslock(self, col, row): colrow = np.array([col, row]) player = self.board[*colrow] members = [colrow] liberties = [] next_index = 0 try: while next_index < len(members): colrow = members[next_index] next_index += 1 self.board[*colrow] = Go.MARK neighbor_colrows = Go.NEIGHBORS + colrow[None] neighbors = self.edged_board[*(neighbor_colrows.T + 1)] liberties.extend(neighbor_colrows[neighbors == Go.EMPTY]) new_members = neighbor_colrows[neighbors == player] members.extend(new_members) self.board[new_members] = Go.MARK finally: self.board[*np.array(members).T] = player assert (self.edged_board != Go.MARK).all() return np.array(members), np.array(liberties) if __name__ == '__main__': def main(): go = Go(5) go.move(0,0,go.turn) go.pass_(go.turn) assert(go.board[0,0] == go.turn) go.pass_(go.turn) go.move(1,0,go.turn) go.move(1,1,go.turn) go.move(0,1,go.turn) assert(go.board[0,0] == Go.EMPTY) go.pass_(go.turn) go.move(0,0,go.turn) go.pass_(go.turn) assert(go.board[0,0] == go.turn) go.clear() go.move(0,0,go.turn) go.move(1,1,go.turn) go.move(0,1,go.turn) go.pass_(go.turn) assert(go.board[0,1] == go.turn) main() what's nice is [[[[[[[[[i've been starting to accomplish a t--]]]]]]]]] also i've b-- here's what the tests are for right now: $ python3 go.py Traceback (most recent call last): File "/data/data/com.termux/files/home/go/go.py", line 113, in <module> main() ~~~~^^ File "/data/data/com.termux/files/home/go/go.py", line 103, in main go.move(0,0,go.turn) ~~~~~~~^^^^^^^^^^^^^ File "/data/data/com.termux/files/home/go/go.py", line 43, in move members, liberties = self.liberties_needslock(col, row) ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^ File "/data/data/com.termux/files/home/go/go.py", line 88, in liberties_needslock assert (self.edged_board != Go.MARK).all() ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^ AssertionError https://ar.anyone.tech/ELH4g_MtmIp76iolJ-Dhvt8iIv26YpOnL4lq1HzQr-I#d9HTHkvo2... https://ar.anyone.tech/M--JZ_7_HwlQrbc0JDWdtAIBYW48WU2zn3itspcrPvE I am not affiliated with https://ar.anyone.tech .