def initialize_game(self, board=None): if board is None: board = hex.Hex() self.board = board self.root = mcts.MCTSNode(board, cpuct=self.cpuct) self.result = 0 self.result_string = None self.comments = [] self.searches_pi = [] self.qs = [] first_node = self.root.select_leaf() prob, val = self.net.run(first_node.board) first_node.incorporate_results(prob, val, first_node)
def makeHex(key): if key == "": # empty off-board locations h = None # hex.Hex(self, key="", type=None) elif key not in self.tiles.keys(): # 1st special case for basic cities to make # writing map files easier... h = hex.Hex(self, key=key, label=key, **self.tiles["base-city"]) elif "label:" == key[:6]: # 2nd special case for basic cities to make # writing map files easier... h = hex.Hex(self, key=key[6:], label=key[6:], **self.tiles[key]) else: # normally described tiles h = hex.Hex(self, key=key, **self.tiles[key]) return h
def clear(self): self.board = hex.Hex()
def __init__(self, net, board=None): self.net = net if board is None: board = hex.Hex() self.board = board
def main(): pygame.init() game_font = pygame.font.SysFont('arial', 38) screen = pygame.display.set_mode(screen_size) hexes = pygame.sprite.Group() hex_positions = get_hex_positions() for position in hex_positions: new_hex = hex.Hex('add') new_hex.position(position[0], position[1]) hexes.add(new_hex) # make middle hex start as something # hexes.sprites()[18].cycle_type(True) buttons_x = 990 + 180 buttons_y = 70 buttons = {} loop_x = 0 for button_item in [ 'add-piece', 'edit-tiles', 'view-map', 'view-resources' ]: buttons[button_item] = button.Button(button_item, loop_x + buttons_x, buttons_y) loop_x += 170 current_mode = 'view-map' ever_rendered = False while current_mode != 'quit': screen.fill((255, 255, 255)) to_render = False # event handling for event in pygame.event.get(): if event.type == pygame.QUIT: current_mode = 'quit' if event.type == pygame.MOUSEBUTTONDOWN: to_render = True x, y = event.pos for tile in hexes: if abs(x - tile.x) < 65 and abs(y - tile.y) < 70: if current_mode == 'edit-tiles' and tile.should_draw( current_mode): if event.button == 1: tile.cycle_type(True) elif event.button == 3: tile.cycle_type(False) elif event.button == 4: tile.increase_value() elif event.button == 5: tile.decrease_value() for button_item in buttons.keys(): if buttons[button_item].rect.collidepoint(x, y): current_mode = button_item if event.type == pygame.MOUSEMOTION: to_render = True if to_render or not ever_rendered: ever_rendered = True # rendering for tile in hexes: if tile.should_draw(current_mode): screen.blit(tile.surf, tile.rect) if tile.token != 0: if tile.token == 6 or tile.token == 8: text_surf = game_font.render( str(tile.token), True, (255, 0, 0)) else: text_surf = game_font.render( str(tile.token), True, (0, 0, 0)) text_rect = text_surf.get_rect() text_rect.center = (tile.x, tile.y) pygame.draw.circle(screen, (255, 255, 255), (round(tile.x), round(tile.y)), 35) screen.blit(text_surf, text_rect) # if current_mode == 'view-resources': if True: xy = [1485, 155] for resource in ['brick', 'wood', 'ore', 'sheep', 'wheat']: resource_sum = 0 for tile in hexes: if tile.type == resource: resource_sum += tile.get_weight() text_surf = game_font.render(f'{resource}: {resource_sum}', True, (0, 0, 0)) text_rect = text_surf.get_rect() text_rect.center = xy screen.blit(text_surf, text_rect) xy[1] += 48 for butt in buttons.values(): screen.blit(butt.surf, butt.rect) pygame.display.flip() pygame.quit()
# Generate Info for a Hex # Use Welsh-Piper approach, plus additional OSR/web finds import random import hex import HexPrint as hexp TABLE_FILENAMES = ('data/encounterstables.json', 'data/settlementtables.json', 'data/fortresstables.json', 'data/ruintables.json') # Global/Argument set up - this will be changed later when I learn about arguments to a python script argTerrainType = "Grassland" # Build the hex and determine encounters newHex = hex.Hex(TABLE_FILENAMES, argTerrainType) #hexp.printHex(hex) #Debug print("\nGenerated hex\n----------") print(newHex)