示例#1
0
def main():

    from modules.render import Render
    from modules.tree import Tree
    from time import time

    while True:

        render = Render(SIZE, FRONT, BACK, TRUNK, TRUNK_STROKE, GRAINS)
        render.ctx.set_source_rgba(*FRONT)
        render.ctx.set_line_width(ONE)

        # TODO :does not work with transparent bg. use operators
        #render.clear_canvas()

        tree = Tree(MID, 0.9, INIT_BRANCH, -pi * 0.5, ONE, ONE,
                    BRANCH_SPLIT_ANGLE, BRANCH_PROB_SCALE, BRANCH_DIMINISH,
                    BRANCH_SPLIT_DIMINISH, BRANCH_ANGLE_MAX, BRANCH_ANGLE_EXP)

        i = 1
        while tree.Q:

            i += 1
            tree.step()
            map(render.branch2, tree.Q)

            if not i % 200:
                print i, len(tree.Q)

        render.sur.write_to_png(
            '/media/var/andreas_tree/test_bp42_{:10.0f}.png'.format(time()))
示例#2
0
def remove_piece(board, boards, opponent):
    for field in board.value.dict.keys():
        if board.value.dict[field].middle is opponent:
            if not is_in_mill(field, opponent, board.value):
                new_board = deepcopy(board.value)
                new_board.dict[field].middle = "O"
                boards.append(Tree(new_board, board))
    return boards
示例#3
0
文件: main.py 项目: inconvergent/tree
def main():

  from modules.render import Render
  from modules.tree import Tree
  from time import time

  while True:

    render = Render(SIZE, FRONT, BACK, TRUNK, TRUNK_STROKE,GRAINS)
    render.ctx.set_source_rgba(*FRONT)
    render.ctx.set_line_width(ONE)

    # TODO :does not work with transparent bg. use operators
    #render.clear_canvas()

    tree = Tree(
      MID,
      0.9,
      INIT_BRANCH,
      -pi*0.5,
      ONE,
      ONE,
      BRANCH_SPLIT_ANGLE,
      BRANCH_PROB_SCALE,
      BRANCH_DIMINISH,
      BRANCH_SPLIT_DIMINISH,
      BRANCH_ANGLE_MAX,
      BRANCH_ANGLE_EXP
    )

    i = 1
    while tree.Q:

      i += 1
      tree.step()
      map(render.branch2,tree.Q)

      if not i%200:
        print i, len(tree.Q)

    render.sur.write_to_png('/media/var/andreas_tree/test_bp42_{:10.0f}.png'.format(time()))
示例#4
0
def stage3_moves(board, player):
    players = ["W", "B"]
    players.remove(player)
    opponent = players[0]
    boards = []

    playa = 0
    for field in board.value.dict.keys():
        if board.value.dict[field].middle is player:
            playa += 1
    for field in board.value.dict.keys():
        if board.value.dict[field].middle is player:
            if playa == 3:
                for pos in board.value.dict.keys():
                    if board.value.dict[pos].middle is "O":
                        board_clone = deepcopy(board.value)
                        board_clone = Tree(board_clone, board)
                        board_clone.value.dict[field].middle = "O"
                        board_clone.value.dict[pos].middle = player
                        if is_in_mill(pos, player, board_clone.value):
                            boards = remove_piece(board_clone, boards,
                                                  opponent)
                        else:
                            boards.append(board_clone)
            else:
                adjacent_list = adjacent(field, True)
                for cord in adjacent_list:
                    if board.value.dict[cord].middle is "O":
                        board_clone = deepcopy(board.value)
                        board_clone = Tree(board_clone, board)
                        board_clone.value.dict[field].middle = "O"
                        board_clone.value.dict[cord].middle = player
                        if is_in_mill(cord, player, board_clone.value):
                            boards = remove_piece(board_clone, boards,
                                                  opponent)
                        else:
                            boards.append(board_clone)
    for b in boards:
        b.parent = board
    board.children = boards
def main():

  from modules.render import Animate
  from modules.tree import Tree
  import gtk

  tree = Tree(
    MID,
    0.95,
    INIT_BRANCH,
    -pi*0.5,
    ONE,
    ONE,
    BRANCH_SPLIT_ANGLE,
    BRANCH_PROB_SCALE,
    BRANCH_DIMINISH,
    BRANCH_SPLIT_DIMINISH,
    BRANCH_ANGLE_MAX,
    BRANCH_ANGLE_EXP
  )

  def wrap(steps_itt,render):

    global i

    tree.step()
    map(render.branch2,tree.Q)

    if tree.Q:
      render.sur.write_to_png('{:05d}.png'.format(i))
      i += 1
      return True
    else:
      #tree.init()
      #render.clear_canvas()
      return False


  render = Animate(
    SIZE,
    FRONT,
    BACK,
    TRUNK,
    TRUNK_STROKE,
    GRAINS,
    STEPS_ITT, wrap
  )
  render.ctx.set_source_rgba(*FRONT)
  render.ctx.set_line_width(ONE)

  gtk.main()
class TestTree(unittest.TestCase):
    def setUp(self):
        self.tree = Tree()

    def test_add_child(self):
        self.tree.set_val('+')
        self.assertEqual(self.tree.get_val(), '+')
        
        self.tree.add_child('4')
        self.tree.add_child('5')
        self.assertEqual(self.tree.get_newborn_child().get_val(), '5')
示例#7
0
def stage1_moves(board, player):
    players = ["W", "B"]
    players.remove(player)
    opponent = players[0]
    boards = []

    for field in board.value.dict.keys():
        if board.value.dict[field].middle is "O":
            board_clone = deepcopy(board.value)
            board_clone = Tree(board_clone, board)
            board_clone.value.dict[field].middle = player
            if is_in_mill(field, player, board_clone.value):
                boards = remove_piece(board_clone, boards, opponent)
            else:
                boards.append(board_clone)
    for b in boards:
        b.parent = board
    board.children = boards
示例#8
0
from modules.utils import get_data
from modules.tree import Tree

filename = 'input'
data = get_data(filename)

tree = Tree(data)
total = tree.get_total()
print(f'total: {total}')

root_value = tree.get_root_value()
print(f'root value: {root_value}')
 def setUp(self):
     self.tree = Tree()