def get_test_board_2(cls): _ = Board.EMPTY B = Board.BLACK W = Board.WHITE bo = Board(19) bo._array = [ [B, B, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _], [_, _, _, _, W, _, _, _, _, _, _, W, B, _, _, _, _, _, _], [_, W, _, W, _, W, _, B, _, _, W, _, W, B, _, _, _, _, _], [_, W, _, _, W, _, _, B, B, _, _, W, B, _, _, _, _, _, _], [_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _], [_, W, W, W, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _], [_, B, B, W, _, W, _, _, _, _, _, _, _, _, _, _, _, _, _], [W, B, B, W, W, W, _, _, _, _, _, _, _, _, _, _, _, _, _], [_, W, W, W, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _], [_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _], [_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _], [_, _, _, _, _, _, _, _, _, _, _, _, _, B, B, B, _, _, _], [_, _, _, _, _, _, _, _, _, _, B, B, B, W, W, W, B, _, _], [_, _, _, _, _, _, _, _, _, _, B, _, B, W, _, W, B, _, _], [_, _, _, _, _, _, _, _, _, _, B, B, B, W, B, W, B, _, _], [_, _, _, _, _, _, _, _, _, _, B, B, W, W, B, W, W, B, _], [_, _, _, _, _, _, _, _, _, _, B, B, B, B, B, W, B, _, _], [_, _, _, _, _, _, _, _, _, _, B, _, B, B, B, W, W, B, _], [_, _, _, _, _, _, _, _, _, _, B, _, B, B, W, W, W, B, _], ] return bo, _, B, W
def __init__(self, size): self.board = Board(size) self.size = size self.np_random = None self.action_size = 2 self.state_size = (size, size, 2) self.seed() self.viewer = None self.steps_beyond_done = None
def main(): index: int = 0 board: Board = Board(9, 9) while True: sys.stdout.flush() sys.stdout.write(str(board)) sys.stdout.write("Input A1 - I9 or ! \r\n") input: str = sys.stdin.readline() if (0 <= input.find("!")): break else: extracted = Board.extractRowCol(input) row: int = extracted[0] col: int = extracted[1] if (0 <= row and row <= 9) and (0 <= col and col <= 9): board.setState( row, col, BoardState.BLACK if index % 2 == 0 else BoardState.WHITE) index += 1 pass
def test_Board_init_001(self): b: Board = Board(3, 3) b.setState(1, 1, BoardState.WHITE) print("\r\n" + str(b)) self.assertTrue(True)
def setUp(self): self.bo = Board(5)
def __init__(self, size:int): self.board = Board(size,size)
def reset(self): self.board = Board(self.size) return self.__getstate__()
def setUp(self): self.b = Board(9) self.v = View(self.b)
def main(): # Get arguments parser = argparse.ArgumentParser(description='Starts a game of go in the terminal.') parser.add_argument('-s', '--size', type=int, default=19, help='size of board') args = parser.parse_args() if args.size < 7 or args.size > 19: sys.stdout.write('Board size must be between 7 and 19!\n') sys.exit(0) # Initialize board and view board = Board(args.size) view = View(board) err = None # User actions def move(): """ Makes a move at the current position of the cursor for the current turn. """ board.move(*view.cursor) view.redraw() def undo(): """ Undoes the last move. """ board.undo() view.redraw() def redo(): """ Redoes an undone move. """ board.redo() view.redraw() def exit(): """ Exits the game. """ sys.exit(0) # Action keymap KEYS = { 'w': view.cursor_up, 's': view.cursor_down, 'a': view.cursor_left, 'd': view.cursor_right, ' ': move, 'u': undo, 'r': redo, '\x1b': exit, } # Main loop while True: # Print board clear() sys.stdout.write('{0}\n'.format(view)) sys.stdout.write('Black: {black} <===> White: {white}\n'.format(**board.score)) sys.stdout.write('{0}\'s move... '.format(board.turn)) if err: sys.stdout.write('\n' + err + '\n') err = None # Get action key c = getch() try: # Execute selected action KEYS[c]() except BoardError as be: # Board error (move on top of other piece, suicidal move, etc.) err = be.message except KeyError: # Action not found, do nothing pass
def main(): # Get arguments """ parser = argparse.ArgumentParser(description='Starts a game of go in the terminal.') parser.add_argument('-s', '--size', type=int, default=19, help='size of board') args = parser.parse_args() if args.size < 7 or args.size > 19: sys.stdout.write('Board size must be between 7 and 19!\n') sys.exit(0) """ # Initialize board and view board = Board(7) view = View(board) err = None board_history = deque(maxlen=8) # User actions def move(): """ Makes a move at the current position of the cursor for the current turn. """ print("Getting our input for x and y") x = input("Input x:") y = input("Input y:") view.set_coordinates(x,y) board.move(*view.cursor) view.redraw() print("Board state") #print(*board._state) #This is list board_state = [] #Creating the board state for item in board._state[0]: row = [] for elem in item: #print(type(elem)) if elem == Location('empty'): row.append(0) elif elem == Location('black'): row.append(1) else: row.append(2) board_state.append(row) board_history.append(board_state) print(board_state) ctr = 0 for item in board_history: print(ctr," ",item) ctr = ctr + 1 #print("\n".join(board_history)) def undo(): """ Undoes the last move. """ board.undo() view.redraw() def redo(): """ Redoes an undone move. """ board.redo() view.redraw() def exit(): """ Exits the game. """ sys.exit(0) # Action keymap KEYS = { 'w': view.cursor_up, 's': view.cursor_down, 'a': view.cursor_left, 'd': view.cursor_right, ' ': move, 'u': undo, 'r': redo, '\x1b': exit, } # Main loop while True: # Print board #clear() sys.stdout.write('{0}\n'.format(view)) sys.stdout.write('Black: {black} <===> White: {white}\n'.format(**board.score)) sys.stdout.write('{0}\'s move... '.format(board.turn)) if err: sys.stdout.write('\n' + err + '\n') err = None # Get action key # c = getch() try: # Execute selected action #KEYS[c]() move() except BoardError as be: # Board error (move on top of other piece, suicidal move, etc.) print("Illegal Move") #err = be.message except KeyError: # Action not found, do nothing pass
from go import Board b = Board(19) b.play((0, 0)) b.play((1, 0)) b.play((0, 1)) b.play((-1, -1)) b.play((-1, -1)) #dic = dict() #dic[(1,1)] = 0 #dic[(1,2)] = 3 #dic[(2,2)] = 5 #del dic[(2,2)] #for x in dic: # print(x, dic[x]) #print(254 ^ 128 ^ 128)