예제 #1
0
    def test_7(self):
        # Arrange
        game = ChessGame('rnbqkbnr/ppp1p1p1/8/P1P1P3/3p1pPp/8/1P1P1P1P/RNBQKBNR b KQkq g3 0 7')
        move_str = 'b7b5'
        expected = 'rnbqkbnr/p1p1p1p1/8/PpP1P3/3p1pPp/8/1P1P1P1P/RNBQKBNR w KQkq b6 0 8'

        # Act
        game.move(move_str)

        # Assert
        self.assertEqual(expected, str(game.fen))
예제 #2
0
    def test_9(self):
        # Arrange
        game = ChessGame('1Q4r1/1bp1k1pp/4P3/8/2n5/2N3K1/1p2R1PP/8 b - - 3 30')
        move_str = 'b2b1r'
        expected = '1Q4r1/1bp1k1pp/4P3/8/2n5/2N3K1/4R1PP/1r6 w - - 0 31'

        # Act
        game.move(move_str)

        # Assert
        self.assertEqual(expected, str(game.fen))
예제 #3
0
    def test_11(self):
        # Arrange
        game = ChessGame('rnbqkbnr/1pppp1pp/p7/3P4/4Pp2/7P/PPP2PP1/RNBQKBNR b KQkq - 0 4')
        move_str = 'e7e5'
        expected = 'rnbqkbnr/1ppp2pp/p7/3Pp3/4Pp2/7P/PPP2PP1/RNBQKBNR w KQkq e6 0 5'

        # Act
        game.move(move_str)

        # Assert
        self.assertEqual(expected, str(game.fen))
예제 #4
0
    def test_13(self):
        # Arrange
        game = ChessGame('rnbqkbnr/pppp2pp/8/3Pp3/8/4p2P/PPP2PP1/RNBQKBNR w KQkq e6 0 5')
        move_str = 'd5e6'
        expected = 'rnbqkbnr/pppp2pp/4P3/8/8/4p2P/PPP2PP1/RNBQKBNR b KQkq - 0 5'

        # Act
        game.move(move_str)

        # Assert
        self.assertEqual(expected, str(game.fen))
예제 #5
0
    def test_0(self):
        # Arrange
        game = ChessGame('k7/r7/b7/q7/N7/B7/R7/K7 w - - 15 48')
        move_str = 'a2h2'
        expected = 'k7/r7/b7/q7/N7/B7/7R/K7 b - - 16 48'

        # Act
        game.move(move_str)

        # Assert
        self.assertEqual(expected, str(game.fen))
예제 #6
0
    def test_9(self):
        # Arrange
        game = ChessGame('rnbqkbnr/p1p1p1p1/8/PpP1P3/3p1pPp/8/1P1P1P1P/RNBQKBNR w KQkq b6 0 8')
        move_str = 'c5b6'
        expected = 'rnbqkbnr/p1p1p1p1/1P6/P3P3/3p1pPp/8/1P1P1P1P/RNBQKBNR b KQkq - 0 8'

        # Act
        game.move(move_str)

        # Assert
        self.assertEqual(expected, str(game.fen))
예제 #7
0
    def test_9(self):
        # Arrange
        game = ChessGame('r3k2r/pppppp1p/8/N7/8/8/PPPPPPpP/R3K2R b KQkq - 0 1')
        move_str = 'g2h1r'
        expected = 'r3k2r/pppppp1p/8/N7/8/8/PPPPPP1P/R3K2r w Qkq - 0 2'

        # Act
        game.move(move_str)

        # Assert
        self.assertEqual(expected, str(game.fen))
예제 #8
0
    def test_12(self):
        # Arrange
        game = ChessGame('rnbqkbnr/ppppp1pp/8/8/3PPp2/7P/PPP2PP1/RNBQKBNR b KQkq e3 0 3')
        move_str = 'f4e3'
        expected = 'rnbqkbnr/ppppp1pp/8/8/3P4/4p2P/PPP2PP1/RNBQKBNR w KQkq - 0 4'

        # Act
        game.move(move_str)

        # Assert
        self.assertEqual(expected, str(game.fen))
예제 #9
0
    def test_3(self):
        # Arrange
        game = ChessGame('rnbqkbnr/ppp1pppp/8/4P3/2Pp4/8/PP1P1PPP/RNBQKBNR b KQkq c3 0 3')
        move_str = 'f7f6'
        expected = 'rnbqkbnr/ppp1p1pp/5p2/4P3/2Pp4/8/PP1P1PPP/RNBQKBNR w KQkq - 0 4'

        # Act
        game.move(move_str)

        # Assert
        self.assertEqual(expected, str(game.fen))
예제 #10
0
    def test_4(self):
        # Arrange
        game = ChessGame('r3k2r/pppppppp/8/N7/8/8/PPPPPPPP/R3K2R b KQkq - 0 16')
        move_str = 'e8f8'
        expected = 'r4k1r/pppppppp/8/N7/8/8/PPPPPPPP/R3K2R w KQ - 1 17'

        # Act
        game.move(move_str)

        # Assert
        self.assertEqual(expected, str(game.fen))
예제 #11
0
    def test_0(self):
        # Arrange
        game = ChessGame('r4rk1/pppppppp/8/N7/8/8/PPPPPPPP/R3K2R w KQ - 1 17')
        move_str = 'e1g1'
        expected = 'r4rk1/pppppppp/8/N7/8/8/PPPPPPPP/R4RK1 b - - 2 17'

        # Act
        game.move(move_str)

        # Assert
        self.assertEqual(expected, str(game.fen))
예제 #12
0
    def test_1(self):
        # Arrange
        game = ChessGame(
            'rnbqkbnr/pppppppp/8/8/8/2N5/PPPPPPPP/R1BQKBNR b KQkq - 1 1')
        move_str = 'b8c6'
        expected = 'rnbqkbnr/pppppppp/8/8/8/2N5/PPPPPPPP/R1BQKBNR w KQkq - 2 2'

        # Act
        game.move(move_str)

        # Assert
        self.assertEqual(expected, str(game.fen))
예제 #13
0
    def test_7(self):
        # Arrange
        game = ChessGame(
            'r1bqkb1r/pppppppp/5n2/6B1/3Q4/2N5/PPP1PPPP/R3KBNR b KQkq - 2 4')
        move_str = 'h8g8'
        expected = 'r1bqkb1r/pppppppp/5n2/6B1/3Q4/2N5/PPP1PPPP/R3KBNR w KQkq - 3 5'

        # Act
        game.move(move_str)

        # Assert
        self.assertEqual(expected, str(game.fen))
예제 #14
0
    def test_7(self):
        # Arrange
        game = ChessGame(
            'r1bq2nr/pppk1Ppp/2n5/2b1P3/1P6/5N2/P4PPP/RNBnKBR1 w Q - 1 10')
        move_str = 'f7f8N'
        expected = 'r1bq1Nnr/pppk2pp/2n5/2b1P3/1P6/5N2/P4PPP/RNBnKBR1 b Q - 0 10'

        # Act
        game.move(move_str)

        # Assert
        self.assertEqual(expected, str(game.fen))
예제 #15
0
    def test_5(self):
        # Arrange
        game = ChessGame(
            'r1bqkbnr/pppppppp/8/8/3Q4/2N5/PPP1PPPP/R1B1KBNR b KQkq - 0 3')
        move_str = 'g8f6'
        expected = 'r1bqkbnr/pppppppp/8/8/3Q4/2N5/PPP1PPPP/R1B1KBNR w KQkq - 1 4'

        # Act
        game.move(move_str)

        # Assert
        self.assertEqual(expected, str(game.fen))
예제 #16
0
    def test_9(self):
        # Arrange
        game = ChessGame(
            'r1bqkbr1/pppppppp/5n2/6B1/3Q4/2N5/PPP1PPPP/2KR1BNR b q - 4 5')
        move_str = 'h7h6'
        expected = 'r1bqkbr1/pppppppp/5n2/6B1/3Q4/2N5/PPP1PPPP/2KR1BNR w q - 0 6'

        # Act
        game.move(move_str)

        # Assert
        self.assertEqual(expected, str(game.fen))
예제 #17
0
    def test_8(self):
        # Arrange
        game = ChessGame(
            'r1bqkbr1/pppppppp/5n2/6B1/3Q4/2N5/PPP1PPPP/R3KBNR w KQq - 3 5')
        move_str = 'e1c1'
        expected = 'r1bqkbr1/pppppppp/5n2/6B1/3Q4/2N5/PPP1PPPP/R3KBNR b KQq - 4 5'

        # Act
        game.move(move_str)

        # Assert
        self.assertEqual(expected, str(game.fen))
예제 #18
0
    def test_7(self):
        # Arrange
        game = ChessGame(
            'r3k2r/p1pppp1p/1pB2Bp1/8/8/1Pb2bP1/P1PPPP1P/3RK2R b Kkq - 6 50')
        move_str = 'e8f8'
        expected = 'r4k1r/p1pppp1p/1pB2Bp1/8/8/1Pb2bP1/P1PPPP1P/3RK2R w K - 7 51'

        # Act
        game.move(move_str)

        # Assert
        self.assertEqual(expected, str(game.fen))
예제 #19
0
    def test_5(self):
        # Arrange
        game = ChessGame(
            'r3k2r/p1pppp1p/1pB2Bp1/8/8/1Pb2bP1/P1PPPP1P/R3K2R w KQkq - 5 50')
        move_str = 'e1d1'
        expected = 'r3k2r/p1pppp1p/1pB2Bp1/8/8/1Pb2bP1/P1PPPP1P/R2K3R b kq - 6 50'

        # Act
        game.move(move_str)

        # Assert
        self.assertEqual(expected, str(game.fen))
예제 #20
0
    def test_2(self):
        # Arrange
        game = ChessGame(
            'r3k2r/p1pppp1p/1pB2Bp1/8/8/1Pb2bP1/P1PPPP1P/R3K2R w KQkq - 5 50')
        move_str = 'c6a8'
        expected = 'B3k2r/p1pppp1p/1p3Bp1/8/8/1Pb2bP1/P1PPPP1P/R3K2R b KQk - 0 50'

        # Act
        game.move(move_str)

        # Assert
        self.assertEqual(expected, str(game.fen))
예제 #21
0
    def test_9(self):
        # Arrange
        game = ChessGame(
            'rnb1kbnr/pp2pppp/2p5/8/8/2N5/PPPP1PBP/R1BQK1NR w KQkq - 0 5')
        move_str = 'g2c6'
        expected = 'rnb1kbnr/pp2pppp/2B5/8/8/2N5/PPPP1P1P/R1BQK1NR b KQkq - 0 5'

        # Act
        game.move(move_str)

        # Assert
        self.assertEqual(expected, str(game.fen))
예제 #22
0
    def test_4(self):
        # Arrange
        game = ChessGame(
            'rnbqkbnr/ppp1pppp/8/3P4/8/8/PPPP1PPP/RNBQKBNR b KQkq - 0 2')
        move_str = 'd8d5'
        expected = 'rnb1kbnr/ppp1pppp/8/3q4/8/8/PPPP1PPP/RNBQKBNR w KQkq - 0 3'

        # Act
        game.move(move_str)

        # Assert
        self.assertEqual(expected, str(game.fen))
예제 #23
0
    def test_3(self):
        # Arrange
        game = ChessGame(
            'r1bqkbnr/pppppppp/2n5/8/3P4/2N5/PPP1PPPP/R1BQKBNR b KQkq - 0 2')
        move_str = 'c6d4'
        expected = 'r1bqkbnr/pppppppp/2n5/8/3P4/2N5/PPP1PPPP/R1BQKBNR w KQkq - 0 3'

        # Act
        game.move(move_str)

        # Assert
        self.assertEqual(expected, str(game.fen))
예제 #24
0
    def test_8(self):
        # Arrange
        game = ChessGame(
            'B3k2r/p1pppp1p/1p3Bp1/8/8/1Pb2bP1/P1PPPP1P/R3K2R b KQk - 0 50')
        move_str = 'c3a1'
        expected = 'B3k2r/p1pppp1p/1p3Bp1/8/8/1P3bP1/P1PPPP1P/b3K2R w Kk - 0 51'

        # Act
        game.move(move_str)

        # Assert
        self.assertEqual(expected, str(game.fen))
예제 #25
0
    def test_2(self):
        # Arrange
        game = ChessGame(
            'rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq - 0 1')
        move_str = 'd7d5'
        expected = 'rnbqkbnr/ppp1pppp/8/3p4/4P3/8/PPPP1PPP/RNBQKBNR w KQkq - 0 2'

        # Act
        game.move(move_str)

        # Assert
        self.assertEqual(expected, str(game.fen))
예제 #26
0
    def test_0(self):
        # Arrange
        game = ChessGame(
            'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1')
        move_str = 'b1f3'
        expected = 'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR b KQkq - 1 1'

        # Act
        game.move(move_str)

        # Assert
        self.assertEqual(expected, str(game.fen))
예제 #27
0
class ConsoleUserInterface:
    def __init__(self):
        player1 = Player('Helen', 'P')
        player2 = Player('Bob', 'M')
        self.game = ChessGame(player1, player2)
        self.output = sys.stdout
        self.input = sys.stdin

    # Draw self.game.board and the state of the game
    def show(self):
        print(HORIZONTAL_BORDER, file=self.output)
        for y in range(BOARD_SIZE, 0, -1):
            print(y, '|', end='', sep='', file=self.output)
            for x in range(BOARD_SIZE):
                if self.game.board.is_empty(x, y-1):
                    print("  |", end='', file=self.output)
                else:
                    piece = self.game.board.get_piece(x, y-1)
                    print(piece.get_color().get_short_name(), end='', file=self.output)
                    print(piece.get_type().get_short_name(), end='|', file=self.output)
            if y > 1:
                print('\n '+"+--"*8+"+", file=self.output)
        print('\n', HORIZONTAL_BORDER, sep='', file=self.output)
        print(' ', '  '.join(LETTERS_ON_BOARD), file=self.output)
        print(self.game.whose_turn(), 'turn', file=self.output)

    def loop(self):
        print('Please, use the international notation for game and magic word \'exit\', if you want finish', file=self.output)
        while 1:
            self.show()
            # next_step = input('What is next step?\n')
            print('What is the next step?', file=self.output)
            next_step = self.input.readline().rstrip()
            print(next_step)
            if len(next_step) == 5:
                try:
                    (source_x, source_y, destination_x, destination_y) = check_good_input(next_step, 0, 1, 3, 4)
                except ChessException as e:
                    print('Error:', e, file=self.output)
            if 5 < len(next_step) < 8:
                try:
                    (source_x, source_y, destination_x, destination_y) = check_good_input(next_step, 1, 2, 4, 5)
                except ChessException as e:
                    print('Error:', e, file=self.output)
            if next_step == 'exit':
                break
            if self.game.whose_turn() == self.game.board.get_piece(source_x, source_y).get_color():
                try:
                    self.game.move(source_x, source_y, destination_x, destination_y)
                except ChessException as e:
                    print('Error:', e, file=self.output)
            else:
                print('To turn!', file=self.output)
예제 #28
0
    def test_6(self):
        # Arrange
        game = ChessGame(
            'r1bqkb1r/pppppppp/5n2/8/3Q4/2N5/PPP1PPPP/R1B1KBNR w KQkq - 1 4')
        move_str = 'c1g5'
        expected = 'r1bqkb1r/pppppppp/5n2/8/3Q4/2N5/PPP1PPPP/R1B1KBNR b KQkq - 2 4'

        # Act
        game.move(move_str)

        # Assert
        self.assertEqual(expected, str(game.fen))
예제 #29
0
    def test_5(self):
        # Arrange
        game = ChessGame(
            'rnb1kbnr/ppp1pppp/8/3q4/8/8/PPPP1PPP/RNBQKBNR w KQkq - 0 3')
        move_str = 'b1f3'
        expected = 'rnb1kbnr/ppp1pppp/8/3q4/8/5N2/PPPP1PPP/R1BQKBNR b KQkq - 1 3'

        # Act
        game.move(move_str)

        # Assert
        self.assertEqual(expected, str(game.fen))
예제 #30
0
    def test_7(self):
        # Arrange
        game = ChessGame(
            'rnb1kbnr/ppp1pppp/8/8/8/2N5/PPPP1PqP/R1BQKBNR w KQkq - 0 4')
        move_str = 'f1g2'
        expected = 'rnb1kbnr/ppp1pppp/8/8/8/2N5/PPPP1PBP/R1BQK1NR b KQkq - 0 4'

        # Act
        game.move(move_str)

        # Assert
        self.assertEqual(expected, str(game.fen))
예제 #31
0
class WindowUserInterface:
    def __init__(self):
        player1 = Player('Helen', 'P')
        player2 = Player('Bob', 'M')
        self.font_color = 'AntiqueWhite2'
        self.game = ChessGame(player1, player2)
        self.main_window = Tk()
        self.main_window.configure(background=self.font_color)
        self.main_window.title("Chess")
        self.CHESS_PIECE_IMAGES = {}
        self.empty_image = ImageTk.PhotoImage(Image.open('Empty_Image.png'))
        for piece_type in ChessPieceType:
            for color in ChessColor:
                self.CHESS_PIECE_IMAGES[str(color)+'_'+str(piece_type)] = Image.open(str(color)+'_'+str(piece_type)+'.png')
        self.first_chose_was_done = False
        self.source_coordinates = None
        self.check_shown = False
        # self.result_notation_text = ''

    def get_image(self, chess_piece):
        return self.CHESS_PIECE_IMAGES[str(chess_piece)]

    def get_square_tk_color(self, i, j):
        if self.game.board.get_square_color(i, j) == ChessColor.Black:
            return 'sienna'
        else:
            return 'khaki'

    def set_boards(self):
        for x in range(1, BOARD_SIZE+1):
            top_letter = Label(self.main_window, text=LETTERS_ON_BOARD[x-1], bg=self.font_color)
            top_letter.grid(row=0, column=x)
            down_letter = Label(self.main_window, text=LETTERS_ON_BOARD[x-1], bg=self.font_color)
            down_letter.grid(row=9, column=x)
        for y in range(BOARD_SIZE, 0, -1):
            left_letter = Label(self.main_window, text=y, bg=self.font_color)
            left_letter.grid(row=abs(y-BOARD_SIZE)+1, column=0)
            right_letter = Label(self.main_window, text=y, bg=self.font_color)
            right_letter.grid(row=abs(y-BOARD_SIZE)+1, column=BOARD_SIZE+1)

    def set_or_destroy_check_message(self):
        if self.was_mate():
            return 0
        for color in ChessColor:
            if self.game.is_check(color) and self.check_shown == False:
                self.check_message = Label(self.frame_for_data, text='Check for '+str(color), bg=self.font_color, width=20, height=1, font="Verdana 13 bold")
                self.check_message.grid(row=0, column=1)
                self.check_shown = True
        if self.check_shown and not (self.game.is_white_check or self.game.is_black_check):
            self.check_message.destroy()
            self.check_shown = False

    def was_mate(self):
        for color in ChessColor:
            if self.game.is_mate(color):
                self.end_of_game(color.get_another_color())
                return True

    def save_notation(self):
        # with open("notation.txt", "w") as out:
        #     print(self.game.result_notation_text, file=out)
        self.save_file(self.game.result_notation_text)

    def open_new_game(self):
        self.main_window.destroy()
        new = WindowUserInterface()
        new.show()

    def end_of_game(self, winner_color):
        frame_for_mate_message = Frame(self.main_window, bg='', height=50)
        frame_for_mate_message.grid(row=1, column=1, columnspan=8, rowspan=8)

        mate_message = Label(frame_for_mate_message, text=str(winner_color)+' win!', padx=80, font="Verdana 40 bold")
        mate_message.pack(side='top')

        # save_button = Button(frame_for_mate_message, text='Save notation', command=self.save_notation)
        # save_button.pack(side='left')
        #
        # new_game_button = Button(frame_for_mate_message, text='New game', command=self.open_new_game)
        # new_game_button.pack(side='right')

        for i in range(BOARD_SIZE):
            for j in range(BOARD_SIZE):
                self.labels[i+1][j+1].unbind("<Button 1>")

    def click_handler(self, x, y):
        if self.first_chose_was_done:
            (source_x, source_y) = self.source_coordinates
            destination_x, destination_y = (x, y)

            if (source_x, source_y) == (destination_x, destination_y):
                self.source_coordinates = None
                self.first_chose_was_done = False
                return 0

            if not (self.game.board.is_empty(source_x, source_y) or self.game.board.is_empty(destination_x, destination_y)):
                if self.game.board.get_piece(source_x, source_y).get_color() == self.game.board.get_piece(destination_x, destination_y).get_color():
                    self.source_coordinates = (destination_x, destination_y)
                    self.first_chose_was_done = True
                    return 0

            if self.game.is_move_correct(source_x, source_y, destination_x, destination_y):
                self.first_chose_was_done = False
                self.game.previous_board = copy.deepcopy(self.game.board)
                self.game.move(source_x, source_y, destination_x, destination_y)
                self.set_or_destroy_check_message()
                self.show_this_squares(self.game.squares_changed_last_move())
                self.show_whose_turn()
                # print('From '+str(source_x)+str(source_y)+'to'+str(destination_x)+str(destination_y))
            else:
                self.source_coordinates = None
                self.first_chose_was_done = False
                self.show_mistake('Wrong move!')
        else:
            if self.game.board.is_empty(x, y):
                self.show_mistake('You can\'t go from empty square')
            else:
                if self.game.whose_turn() != self.game.board.get_piece(x, y).get_color():
                    self.show_mistake(str(self.game.whose_turn())+' player\'s turn!')
                else:
                    self.first_chose_was_done = True
                    self.source_coordinates = (x, y)

    def show_mistake(self, message):
        mistake_window = Toplevel()
        mistake_message = Label(mistake_window, text=message)
        mistake_message.pack()
        mistake_window.geometry('200x90+700+355')

    def show_whose_turn(self):
        self.area_whose_turn['text'] = 'Turn for ' + str(self.game.whose_turn())

    def save_file(self, saving_text):
        file = tkFileDialog.SaveAs(self.main_window, filetypes=[('*.txt files', '.txt')]).show()
        if file == '':
            return
        if not file.endswith(".txt"):
            file += ".txt"
        open(file, 'wt').write(saving_text)

    def save_game(self):
        encoded_game = jsonpickle.encode(self.game)
        # file = tkFileDialog.SaveAs(self.main_window, filetypes=[('*.txt files', '.txt')]).show()
        # if file == '':
        #     return
        # if not file.endswith(".txt"):
        #     file += ".txt"
        # open(file, 'wt').write(encoded_game)
        self.save_file(encoded_game)

    def recursive_function_for_fields(self, pending_object, object_in_normal_game):
        a = {}
        try:
            a = object_in_normal_game.__dict__.keys()
        except AttributeError:
            pass
        for field in a:
            if field.startswith('__') and field.endswith('__'):
                continue
            try:
                if type(getattr(pending_object, field)) != type(getattr(object_in_normal_game, field)):
                    print('False1')
                    return False
            except AttributeError:
                print('False2')
                return False
            print(field)
            if not self.recursive_function_for_fields(getattr(pending_object, field), getattr(object_in_normal_game, field)):
                return False
        return True

    def check_board(self, pending_board):
        for i in range(BOARD_SIZE):
            for j in range(BOARD_SIZE):
                if not pending_board.is_empty(i, j):
                    pending_piece = pending_board.get_piece(i, j)
                    if not self.recursive_function_for_fields(pending_piece, ChessPiece(ChessColor.White, ChessPieceType.Bishop)):
                        print('False8')
                        return False
        return True

    def loaded_game_is_correct(self):
        game_for_check = ChessGame(Player('A', 'B'), Player('C', 'D'))
        if type(self.game) != ChessGame:
            return False

        if not self.recursive_function_for_fields(self.game, game_for_check):
            return False

        if not self.check_board(self.game.board):
            return False

        if type(self.game.board) != ChessBoard or type(self.game.previous_board) != ChessBoard:
            print('False5')
            return False
        if type(self.game.player_black) != Player or type(self.game.player_white) != Player:
            print('False6')
            return False
        return True

    def load_game(self):
        encoded_game = self.load_file()
        if encoded_game is None:
            return
        try:
            self.game = jsonpickle.decode(encoded_game)
        except Exception:
            self.show_mistake('Can\'t open game file')
            return
        if not self.loaded_game_is_correct():
            self.show_mistake('Object in file is not a chess game')
            return
        try:
            self.start_frame.destroy()
        except AttributeError:
            pass

        self.show()

    def load_file(self):
        file = tkFileDialog.Open(self.main_window, filetypes=[('*.txt files', '.txt')]).show()
        if file == '':
            return
        return open(file, 'r').read()

    def place_main_window(self, width, height):
        screen_width = self.main_window.winfo_screenwidth()
        screen_height = self.main_window.winfo_screenheight()
        x_coordinate = screen_width/2-width/2
        y_coordinate = screen_height/2 - height/2-20
        self.main_window.geometry('%dx%d+%d+%d' % (width, height, x_coordinate, y_coordinate))

    def show_this_squares(self, array):
        for (i, j) in array:
            if not self.game.board.is_empty(i, j):
                piece = self.game.board.get_piece(i, j)
                img = self.get_image(piece)
                img = ImageTk.PhotoImage(img)
                self.labels[i+1][j+1]['image'] = img
                self.labels[i+1][j+1].image = img
            else:
                self.labels[i+1][j+1]['image'] = self.empty_image
                self.labels[i+1][j+1].image = self.empty_image

    def show(self):
        self.frames = [[Frame(self.main_window, height=SQUARE_SIZE, width=SQUARE_SIZE, bd=0) for j in range(BOARD_SIZE + 1)] for i in
                      range(BOARD_SIZE + 1)]
        self.labels = [[Label(self.frames[i][j], width=SQUARE_SIZE-10, height=SQUARE_SIZE-10) for j in range(BOARD_SIZE + 1)] for i in range(BOARD_SIZE+1)]
        self.set_boards()
        for i in range(BOARD_SIZE):
            for j in range(BOARD_SIZE):
                handler = lambda g, ii=i, jj=j: self.click_handler(ii, jj)

                self.frames[i+1][j+1]['bg'] = self.get_square_tk_color(i, j)
                self.frames[i+1][j+1].bind("<Button-1>", handler)
                self.frames[i+1][j+1].grid(row=abs(j+1-BOARD_SIZE)+1, column=i+1, sticky=S+W+N+E)

                self.labels[i+1][j+1]['bg'] = self.get_square_tk_color(i, j)
                self.labels[i+1][j+1].bind("<Button-1>", handler)
                self.labels[i+1][j+1].pack(fill='both')

        self.frame_for_data = Frame(self.main_window, bd=1, bg=self.font_color)
        self.frame_for_data.grid(column=1, row=10, columnspan=12, sticky=N)

        self.area_whose_turn = Label(self.frame_for_data, text='Turn for ' + str(self.game.whose_turn()), bg=self.font_color, width=59)
        self.area_whose_turn.grid(row=1, column=1, rowspan=1)

        self.save_button = Button(self.frame_for_data, text='Save game', command=self.save_game, width=11)
        self.save_button.grid(row=0, column=2)

        self.open_new_button = Button(self.frame_for_data, text='Open new game', command=self.open_new_game)
        self.open_new_button.grid(row=1, column=0, rowspan=1)

        self.place_main_window(618, 720)

        self.load_game_button = Button(self.frame_for_data, text='Load game', command=self.load_game, width=11)
        self.load_game_button.grid(row=1, column=2)

        self.save_notation_button = Button(self.frame_for_data, text='Save notation', command=self.save_notation, width=11)
        self.save_notation_button.grid(row=2, column=2)

        squares_array = []
        for i in range(BOARD_SIZE):
            for j in range(BOARD_SIZE):
                squares_array.append((i, j))
        self.show_this_squares(squares_array)

    def show_start_view(self):
        self.start_frame = Frame(self.main_window, bg=self.font_color, bd=16)
        self.place_main_window(220, 60)
        self.start_frame.grid(row=0, column=0)
        load_button = Button(self.start_frame, text='load saved game', command=self.load_game)
        load_button.grid(row=1, column=2)
        new_game_button = Button(self.start_frame, text='start new game', command=self.open_new_game)
        new_game_button.grid(row=1, column=1)

    def loop(self):
        self.main_window.mainloop()
        pass