def random_game(): inputs = {'destroyer': ('C', 2, 'r'), 'submarine': ('F', 3, 'c'), 'cruiser': ('B', 5, 'r'), 'battleship': ('F', 6, 'c'), 'carrier': ('F', 1, 'r')} game = Board(inputs) game.render_board() agent = RandomAgent() while not game.is_won(): r, c = agent.get_action() logger.log('attempt : ' + str(agent.get_iterator()), Color.cyan) game.play(r, c) game.is_sunk_ship() game.render_board()
def step(self, board: Board, action: int): done = False num, let = unravel_index(action, [BOARD_SIZE, BOARD_SIZE]) res = board.play(num, let) if board.is_sunk_ship(): res = SUNK_SHIP if board.is_won(): res = WON done = True reward = get_reward(res) reward = torch.tensor([reward], device=self.device) next_state = board.get_current_board() return next_state, reward, done,