Exemplo n.º 1
0
def PageFour():
    try:
        window = tk.Tk()
        club_name = simpledialog.askstring(":::club name:::",
                                           "입장하고자 하는 클럽명을 입력해주세요")
        TopFrame = tk.Frame(window, width=500, height=500)
        TopFrame.pack(side="top")
        BottomFrame = tk.Frame(window, width=500, height=300)
        BottomFrame.pack(side="bottom")
        controller = BoardController()
        board_list = controller.get_all_board(
            club_name)  #`id`, `content`,`title`,`member_email`   반환
        print(board_list)
        title_list = tk.Listbox(TopFrame, selectmode='extended', height=0)
        for i, board in enumerate(board_list):
            board_list.insert(i, board[i]["title"])
        title_list.pack()
        label1 = tk.Label(BottomFrame, text="삭제하고 싶은 게시글의 제목을 적어주세요")
        label1.pack(side="left")
        title = tk.StringVar()
        entry1 = tk.Entry(BottomFrame, textvariable=title)
        entry1.pack(side="left")
        button1 = tk.Button(BottomFrame,
                            text="검색",
                            command=lambda: delete_by_email(title, board_list))
        button1.pack(side="left")
        homebutton = tk.Button(window, text="home", command=to_home(window))
        homebutton.pack()
        window.mainloop()
    except:
        tkinter.messagebox.showerror(
            "error", "error : 죄송합니다. error가 발생했습니다. 빠른 정비 후 찾아뵙도록 하겠습니다.")
Exemplo n.º 2
0
def show_text(title, club_name):
    controller = BoardController()
    board_list = controller.get_all_board(club_name)
    # borad_view(따로 생성한 view창)
    # title만 필요하다.
    # 이거 나중에 title로 검색해서 내용 출력할 예정이다.
    titles = []
    for board in board_list:
        if board["title"] == title:
            titles.append(board["content"])
    if not len(titles):
        tkinter.messagebox.showinfo("::결과창::", "검색한 제목의 글이 없어요")
    else:
        tkinter.messagebox.showinfo("::결과창::", titles)
Exemplo n.º 3
0
def delete_by_email(title, board_list):
    # todo 고냥 sql문으로 받아와서 in keys( )로 돌려버리기
    controller = BoardController()
    list_of_titles = []
    for board in board_list:
        list_of_titles.append(board["title"])
    if title in list_of_titles:
        for i, value in enumerate(list_of_titles):
            if title == value:
                message = controller.delete_board(board_list[i]["id"],
                                                  board_list[i]["email"],
                                                  board_list[i]["club_name"])
                tkinter.messagebox.showinfo("::result::", message)
    else:
        tkinter.messagebox.showinfo("::result::", "삭제할 글을 찾지 못하였습니다.")
Exemplo n.º 4
0
def PageOne():
    controller = BoardController()
    window = tk.Tk()
    title_font = Font(family="나눔고딕 ExtraBold", size="20", weight="bold")
    text_font = Font(family="나눔스퀘어 Light", size="16")
    club_name = simpledialog.askstring("::입장할 클럽명::", "입장할 클럽명을 적어주세요")
    result_board_entity = controller.board_view_all(club_name)
    print(result_board_entity)
    # 이제 다 가져옴
    manager_email = result_board_entity[0]["manager_email"]
    TopFrame = tk.Frame(window)
    TopFrame.pack(side="top")
    BottomFrame = tk.Frame(window)
    BottomFrame.pack(side="bottom")
    #top에 클럽 게시글 작성 entity
    title = tk.StringVar()
    writer = tk.StringVar()
    label1 = tk.Label(TopFrame, text="제목", font=title_font)
    label1.pack(side="left")
    entry1 = tk.Entry(TopFrame, textvariable=title)
    entry1.pack(side="left")
    label2 = tk.Label(TopFrame, text="작성자(community email)", font=text_font)
    label2.pack(side="left")
    entry2 = tk.Entry(TopFrame, textvariable=writer)
    entry2.pack(side="left")
    label2 = tk.Label(BottomFrame,
                      text="content \n (3000자 이내)",
                      font=text_font)
    label2.pack()
    textExample = tk.Text(BottomFrame, height=15)
    textExample.pack()
    btnRead=tk.Button(BottomFrame, height=1, width=10, text="등록하기",
                    command=lambda:register_board(BoardEntity((title.get()+str(random.randint(1,100))+writer.get()),title.get(),\
                    textExample.get("1.0","end"),writer.get(), manager_email, club_name)))
    btnRead.pack(side="right")
    homebutton = tk.Button(BottomFrame,
                           text="home",
                           command=lambda: to_home(window))
    homebutton.pack(side="right")
    window.mainloop()
Exemplo n.º 5
0
 def __init__(self,
              parent=None,
              x=0,
              y=0,
              width=0,
              height=0,
              cell_size=5,
              color=PG_COLORS.get('black'),
              living_cell_color=PG_COLORS.get('white')):
     super().__init__(parent=parent,
                      x=x,
                      y=y,
                      width=width,
                      height=height,
                      color=color)
     self.__cell_size = cell_size
     self.__living_cell_color = living_cell_color
     self.__model = BoardModel(floor(self._width / cell_size),
                               floor(self._height / cell_size))
     self.__controller = BoardController(self.__model, 0.01)
     self.__welcome_message = 'Press play to start !'
     self.__current_strategy_text = 'Current strategy is: '
     self.__instruction_text = 'Press number from 1 to 4 to change strategy.'
Exemplo n.º 6
0
 def restart(self):
     view = views.BoardView()
     controller = BoardController()
     view = CmderView()
     controller.bind_view(view)
     model = Board(size=size)
     controller.bind_board(model)
     self.ai = MonteCarloAI(controller, ai_color, 20)
     self.start()
Exemplo n.º 7
0
    def __init__(self):
        controller = BoardController()
        size_get = False
        blank_color = 0
        white_color = 1
        black_color = 2
        while not size_get:
            size = input("Please enter the board size( 10-20 ): ")
            size_get = True
            try:
                size = int(size)
            except ValueError as e:
                print("Invalid input type, please enter a digital number.")
                size_get = False

        if size > 20:
            print("Board size too large, set to maximum size :20")
            size = 20
        if size < 10:
            print("Board size too small, set to minimun size: 10")
            size = 10

        player_color = 0
        while player_color == 0:
            color = input(
                "Please enter the piece color( black or white, black is the offensive color ): "
            )
            color = color.strip()
            if color == "white":
                player_color = white_color
                self.player_color_text = color
            elif color == 'black':
                player_color = black_color
                self.player_color_text = color
            else:
                print(
                    "Invalid color, please reenter the color 'black' or 'white'."
                )

        self.player_color = player_color
        self.ai_color = black_color if player_color == white_color else white_color
        view = CmderView(white_color=white_color, black_color=black_color)
        controller.bind_view(view)
        model = Board(size=size,
                      white_color=white_color,
                      black_color=black_color,
                      blank_color=blank_color)
        controller.bind_board(model)
        self.controller = controller
        self.ai = MonteCarloAI(controller,
                               self.ai_color,
                               simulation_num=15,
                               time_limit=20)
Exemplo n.º 8
0
def PageTwo():
    window = tk.Tk()
    club_name = simpledialog.askstring(":::club name:::",
                                       "입장하고자 하는 클럽명을 입력해주세요")
    # 클럽명에 따라 manager email 가져오는 함수
    controller = BoardController()
    board_list = controller.get_all_board(club_name)
    if not bool(board_list):
        tkinter.messagebox.showerror("error", "죄송합니다. 해당 클럽은 존재하지 않습니다.")
    else:
        print("deguging gui")
        TopFrame = tk.Frame(window, width=500, height=500)
        TopFrame.pack(side="top")
        BottomFrame = tk.Frame(window, width=500, height=300)
        BottomFrame.pack(side="bottom")

        treeview = ttk.Treeview(
            TopFrame,
            columns=["one", "two"])  #, displaycolumns =["three","two","one"])
        treeview.pack(side="left")

        treeview.column("one", width=350, anchor="center")
        treeview.heading("one", text="작성자", anchor="center")

        treeview.column("two", width=100, anchor="center")
        treeview.heading("two", text="제목", anchor="center")

        controller = BoardController()
        board_list = controller.get_all_board(club_name)
        print(board_list)
        for i, board in enumerate(board_list):
            treeview.insert('',
                            'end',
                            values=(board['title'], board['member_email']))

        label1 = tk.Label(BottomFrame, text="확인하고 싶은 게시판 글의 제목")
        label1.pack(side="left")
        title = tk.StringVar(window)
        entry1 = tk.Entry(BottomFrame, textvariable=title)
        entry1.pack(side="left")
        button = tk.Button(BottomFrame,
                           text="검색",
                           command=lambda: show_text(title.get(), club_name))
        button.pack()
        homebutton = tk.Button(BottomFrame,
                               text="home",
                               command=lambda: to_home(window))
        homebutton.pack(side="right")
        window.mainloop()
Exemplo n.º 9
0
def register_board(board_entity):
    controller = BoardController()
    result = controller.register_board(board_entity)
    tkinter.messagebox.showinfo("::결과창::", result)
    print(result)
Exemplo n.º 10
0
from board import Board
from controller import BoardController
from montecarlo import MonteCarloAI
from cmder_view import CmderView
import pickle, os, datetime
'''
This file is a demo where you can simulate ai combating with each other,
the simulation results will be saved in the "save_dir" dir
'''

size = 10
ai1_color = 1
ai2_color = 2
view = CmderView(white_color=ai1_color, black_color=ai2_color)
controller = BoardController()
controller.bind_view(view)
ai1 = MonteCarloAI(controller,
                   ai1_color,
                   verbose=False,
                   simulation_num=12,
                   time_limit=180,
                   critical_area=1)
ai2 = MonteCarloAI(controller,
                   ai2_color,
                   verbose=False,
                   simulation_num=12,
                   time_limit=180,
                   critical_area=1)
save_freq = 100
save_file = "simulation"
save_dir = "simulation_results"
Exemplo n.º 11
0
class Board(AbstractControllableWidget):
    def __init__(self,
                 parent=None,
                 x=0,
                 y=0,
                 width=0,
                 height=0,
                 cell_size=5,
                 color=PG_COLORS.get('black'),
                 living_cell_color=PG_COLORS.get('white')):
        super().__init__(parent=parent,
                         x=x,
                         y=y,
                         width=width,
                         height=height,
                         color=color)
        self.__cell_size = cell_size
        self.__living_cell_color = living_cell_color
        self.__model = BoardModel(floor(self._width / cell_size),
                                  floor(self._height / cell_size))
        self.__controller = BoardController(self.__model, 0.01)
        self.__welcome_message = 'Press play to start !'
        self.__current_strategy_text = 'Current strategy is: '
        self.__instruction_text = 'Press number from 1 to 4 to change strategy.'

    def show(self):
        screen = display.get_surface()
        draw.rect(screen, self._color,
                  (self._x, self._y, self._width, self._height))

        if not self.__controller.stopped:

            cell_x = self._x
            cell_y = self._y

            for line in self.__model.data:
                for cell in line:
                    if cell == 1:
                        draw.rect(screen, self.__living_cell_color,
                                  (cell_x, cell_y, self.__cell_size,
                                   self.__cell_size))
                    cell_x = cell_x + self.__cell_size
                cell_y = cell_y + self.__cell_size
                cell_x = self._x

            for child in self._children:
                child.show()
        else:
            font = SysFont('', 60)

            current_strategy_text = self.__current_strategy_text + self.__controller.strategy

            welcome_text = font.render(self.__welcome_message, True,
                                       PG_COLORS.get('white'))
            current_strategy = font.render(current_strategy_text, True,
                                           PG_COLORS.get('white'))
            instruction_text = font.render(self.__instruction_text, True,
                                           PG_COLORS.get('white'))

            text_width, text_height = font.size(self.__welcome_message)
            cs_text_width, cs_text_height = font.size(current_strategy_text)
            i_text_width, i_text_height = font.size(self.__instruction_text)

            screen.blit(welcome_text,
                        (self._x + self._width / 2 - text_width / 2,
                         self._y + self._height / 2 - text_height * 2.5))
            screen.blit(instruction_text,
                        (self._x + self._width / 2 - i_text_width / 2,
                         self._y + self._height / 2 - text_height))
            screen.blit(current_strategy,
                        (self._x + self._width / 2 - cs_text_width / 2,
                         self._y + self._height / 2 + text_height / 2))

    def play(self):
        self.__controller.play()

    def pause(self):
        self.__controller.pause()

    def stop(self):
        self.__controller.stop()

    def process_event(self, new_event):
        if self.__controller.stopped and new_event.type == pg_constants.KEYDOWN:
            if new_event.key == pg_constants.K_1:
                self.__controller.strategy = RandomInitArrayStrategy()
            elif new_event.key == pg_constants.K_2:
                self.__controller.strategy = ButterflyInitArrayStrategy()
            elif new_event.key == pg_constants.K_3:
                self.__controller.strategy = ExplosionInitArrayStrategy()
            elif new_event.key == pg_constants.K_4:
                self.__controller.strategy = ExpansionInitArrayStrategy()
        else:
            for child in self._children:
                child.process_event(new_event)