예제 #1
0
def draw():
    if STATMODE:
        return  # ART IS FOR SILLY HUMANITIES MAJORS, NOT STATMODE!
    if USING_PYGAME:
        import pygame

        global screen

        # Draw screen
        screen.fill(color_green)
        for x in range(0, SW, floor(SW / 8)):
            pygame.draw.line(screen, color_black, (x, 0), (x, SH))
        for y in range(0, SH, floor(SH / 8)):
            pygame.draw.line(screen, color_black, (0, y), (SW, y))

        # Draw pieces
        for (x, y) in [(x, y) for x in range(8) for y in range(8)]:
            {
                Game.NONE: lambda: None,
                Game.BLACK: lambda: pygame.draw.circle(
                    screen, color_black, (x * SP + SP // 2, y * SP + SP // 2), SP // 2
                ),
                Game.WHITE: lambda: pygame.draw.circle(
                    screen, color_white, (x * SP + SP // 2, y * SP + SP // 2), SP // 2
                ),
            }[game.state[x][y]]()

        # Draw liberties
        for (x, y) in Game.liberties(game.current_player, game.state):
            pygame.draw.circle(screen, color_white, (x * SP + SP // 2, y * SP + SP // 2), 4)

        # Update
        pygame.display.update()
    else:
        main_widget.draw(game)
예제 #2
0
 def make_move(self, x=None, y=None):
     Player.make_move(self, x, y)
     # Calculate move
     liberties = Game.liberties(self.player, self.state)
     #def apply_strat(strategy, mult=1, heur=None):
     #    return strategy.apply(self.player, self.state, liberties, mult, heuristic=heur)
     heur = None
     for strat, mult in self.strats:
         heur = strat.apply(self.player, self.state, liberties, mult, heur)
     x, y = Strategy.run(heur)
     self.game.move(x, y)
예제 #3
0
def update():
    event()
    if game.is_running:
        # Tell bots to do stuff
        for player in players:
            if game.current_player == player.player:
                if len(Game.liberties(player.player, game.state)) == 0:
                    game.pass_move()
                else:
                    player.make_move()
                draw()
                check_win()
                break
    draw()
예제 #4
0
 def apply(player, state, liberties, mult=1, heuristic=None):
     if heuristic == None:
         heuristic = [(pos, 1) for pos in liberties[:]]
     libs = []
     # TODO Someone make this not inefficient
     for i in range(len(heuristic)):
         pos, heur = heuristic[i]
         x, y = pos
         newstate = Game.simulate_move(x, y, player, state)
         lib = len(Game.liberties(Game.other(player), newstate))
         libs.append((pos, lib))
     minl = min([l for _, l in libs])
     for i in range(len(libs)):
         pos, heur = heuristic[i]
         _, lib = libs[i]
         v = 1 / ((lib - minl) + 1)
         heuristic[i] = (pos, heur * v ** mult)
     return heuristic
예제 #5
0
    def draw(self, game=None):
        self.context.setFillStyle(Color.Color("#00AA00"))
        self.context.fillRect(0, 0, self.SW, self.SH)

        SP = self.SW // 8

        for x in range(0, self.SW, SP):
            self.context.beginPath()
            self.context.setStrokeStyle(Color.BLACK)
            self.context.setLineWidth(1)
            self.context.moveTo(x, 0)
            self.context.lineTo(x, self.SH)
            self.context.closePath()
            self.context.stroke()
        for y in range(0, self.SH, SP):
            self.context.beginPath()
            self.context.setStrokeStyle(Color.BLACK)
            self.context.setLineWidth(1)
            self.context.moveTo(0, y)
            self.context.lineTo(self.SW, y)
            self.context.closePath()
            self.context.stroke()

        # Draw pieces
        for (x, y) in [(x, y) for x in range(8) for y in range(8)]:
            if game.state[x][y] != Game.NONE:
                if game.state[x][y] == Game.BLACK:
                    self.context.setFillStyle(Color.BLACK)
                elif game.state[x][y] == Game.WHITE:
                    self.context.setFillStyle(Color.WHITE)
                self.context.beginPath()
                self.context.arc(x * SP + SP // 2, y * SP + SP // 2, SP // 2, 0, 2 * pi)
                self.context.closePath()
                self.context.fill()
    
        # Draw liberties
        for (x, y) in Game.liberties(game.current_player, game.state):
            self.context.setFillStyle(Color.WHITE)
            self.context.beginPath()
            self.context.arc(x * SP + SP // 2, y * SP + SP // 2, 4, 0, 2 * pi)
            self.context.closePath()
            self.context.fill()