Exemple #1
0
    def on_response(self, widget, response):
        if response in (HINT, MOVE):
            if self.gamemodel.hint:
                if self.boardview.arrows:
                    self.boardview.arrows.clear()
                if self.boardview.circles:
                    self.boardview.circles.clear()

                hint = self.gamemodel.hint
                cord0 = Cord(hint[0], int(hint[1]), "G")
                cord1 = Cord(hint[2], int(hint[3]), "G")
                if response == HINT:
                    self.boardview.circles.add(cord0)
                    self.boardview.redrawCanvas()
                else:
                    self.boardview.arrows.add((cord0, cord1))
                    self.boardview.redrawCanvas()
            else:
                print("No hint available!")

        elif response == RETRY:
            if self.gamemodel.practice_game:
                self.gamemodel.undoMoves(2)
            elif self.gamemodel.lesson_game:
                self.boardview.setShownBoard(self.shown_board)
            self.your_turn()

        elif response == NEXT:
            if self.gamemodel.practice_game:
                if self.gamemodel.practice[0] == "puzzle":
                    start_puzzle_from(self.gamemodel.practice[1])
                elif self.gamemodel.practice[0] == "endgame":
                    start_endgame_from(self.gamemodel.practice[1])
            else:
                print("Next clicked!")
Exemple #2
0
    def learnClicked(self, button):
        perspective = perspective_manager.get_perspective("learn")
        perspective.activate()

        tree_iter = self.puzzle_combo.get_active_iter()
        if tree_iter is None:
            return
        else:
            model = self.puzzle_combo.get_model()
            filename = model[tree_iter][0]

        start_puzzle_from(filename)
    def learnClicked(self, button):
        perspective = perspective_manager.get_perspective("learn")
        perspective.activate()

        tree_iter = self.learn_combo.get_active_iter()
        if tree_iter is None:
            return
        else:
            model = self.learn_combo.get_model()
            source = model[tree_iter][0]

        if self.category == LECTURE:
            start_lecture_from(source)
        elif self.category == LESSON:
            start_lesson_from(source)
        elif self.category == PUZZLE:
            start_puzzle_from(source)
        elif self.category == ENDGAME:
            start_endgame_from(source)
    def learnClicked(self, button):
        perspective = perspective_manager.get_perspective("learn")
        perspective.activate()

        tree_iter = self.learn_combo.get_active_iter()
        if tree_iter is None:
            return
        else:
            model = self.learn_combo.get_model()
            source = model[tree_iter][0]

        if self.category == LECTURE:
            start_lecture_from(source)
        elif self.category == LESSON:
            start_lesson_from(source)
        elif self.category == PUZZLE:
            start_puzzle_from(source)
        elif self.category == ENDGAME:
            start_endgame_from(source)
Exemple #5
0
 def test4(self):
     """ Start next puzzle """
     filename = PUZZLES[0][0]
     start_puzzle_from(filename)
Exemple #6
0
    def on_response(self, widget, response):
        if response in (HINT, MOVE):
            if self.gamemodel.lesson_game:
                next_move = self.gamemodel.getMoveAtPly(
                    self.boardview.shown, self.boardview.shown_variation_idx)
                hints = {self.boardview.shown: ((next_move.as_uci(), ), )}
            else:
                hints = self.gamemodel.hints

            if self.boardview.shown in hints:
                if self.boardview.arrows:
                    self.boardview.arrows.clear()
                if self.boardview.circles:
                    self.boardview.circles.clear()

                hint = hints[self.boardview.shown][0][0]
                cord0 = Cord(hint[0], int(hint[1]), "G")
                cord1 = Cord(hint[2], int(hint[3]), "G")
                if response == HINT:
                    self.boardview.circles.add(cord0)
                    self.boardview.redrawCanvas()
                else:
                    self.boardview.arrows.add((cord0, cord1))
                    self.boardview.redrawCanvas()
            else:
                # TODO:
                print("No hint available yet!", self.gamemodel.ply,
                      self.boardview.shown)

        elif response == RETRY:
            self.your_turn()

            if self.gamemodel.practice_game:
                me_played_last_move = self.gamemodel.boards[
                    -1].color != self.gamemodel.boards[0].color
                moves = 1 if self.gamemodel.status in UNDOABLE_STATES and me_played_last_move else 2
                self.gamemodel.undoMoves(moves)

            elif self.gamemodel.lesson_game:
                prev_board = self.gamemodel.getBoardAtPly(
                    self.boardview.shown - 1,
                    variation=self.boardview.shown_variation_idx)

                self.annotation_panel.choices_enabled = False

                self.boardview.setShownBoard(prev_board)
                # We have to fix show_variation_index here, unless
                # after removing the variation it will be invalid!
                for vari in self.gamemodel.variations:
                    if prev_board in vari:
                        break
                self.boardview.shown_variation_idx = self.gamemodel.variations.index(
                    vari)

                self.annotation_panel.choices_enabled = True

            self.boardcontrol.game_preview = False

        elif response == CONTINUE:
            self.your_turn()
            self.boardview.showNext()
            self.boardcontrol.game_preview = False

        elif response == BACK_TO_MAINLINE:
            self.opp_turn()
            self.boardview.backToMainLine()
            self.boardcontrol.game_preview = False

        elif response == NEXT:
            if self.gamemodel.puzzle_game:
                if self.gamemodel.from_lesson:
                    start_lesson_from(self.gamemodel.source,
                                      self.gamemodel.current_index + 1)
                else:
                    start_puzzle_from(self.gamemodel.source,
                                      self.gamemodel.current_index + 1)
            elif self.gamemodel.end_game:
                start_endgame_from(self.gamemodel.source)
            elif self.gamemodel.lesson_game:
                start_lesson_from(self.gamemodel.source,
                                  self.gamemodel.current_index + 1)
            else:
                print(self.gamemodel.__dir__())
Exemple #7
0
 def test4(self):
     """ Start next puzzle """
     filename = PUZZLES[0][0]
     start_puzzle_from(filename)
Exemple #8
0
    def on_response(self, widget, response):
        if response in (HINT, MOVE):
            if self.gamemodel.lesson_game:
                next_move = self.gamemodel.getMoveAtPly(self.boardview.shown, self.boardview.shown_variation_idx)
                hints = {self.boardview.shown: ((next_move.as_uci(),),)}
            else:
                hints = self.gamemodel.hints

            if self.boardview.shown in hints:
                if self.boardview.arrows:
                    self.boardview.arrows.clear()
                if self.boardview.circles:
                    self.boardview.circles.clear()

                hint = hints[self.boardview.shown][0][0]
                cord0 = Cord(hint[0], int(hint[1]), "G")
                cord1 = Cord(hint[2], int(hint[3]), "G")
                if response == HINT:
                    self.boardview.circles.add(cord0)
                    self.boardview.redrawCanvas()
                else:
                    self.boardview.arrows.add((cord0, cord1))
                    self.boardview.redrawCanvas()
            else:
                # TODO:
                print("No hint available yet!", self.gamemodel.ply, self.boardview.shown)

        elif response == RETRY:
            self.your_turn()

            if self.gamemodel.practice_game:
                me_played_last_move = self.gamemodel.boards[-1].color != self.gamemodel.boards[0].color
                moves = 1 if self.gamemodel.status in UNDOABLE_STATES and me_played_last_move else 2
                self.gamemodel.undoMoves(moves)

            elif self.gamemodel.lesson_game:
                prev_board = self.gamemodel.getBoardAtPly(
                    self.boardview.shown - 1,
                    variation=self.boardview.shown_variation_idx)

                self.annotation_panel.choices_enabled = False
                self.boardview.setShownBoard(prev_board)
                # We have to fix show_variation_index here, unless
                # after removing the variation it will be invalid!
                for vari in self.gamemodel.variations:
                    if prev_board in vari:
                        break
                self.boardview.shown_variation_idx = self.gamemodel.variations.index(vari)

                self.annotation_panel.choices_enabled = True

            self.boardcontrol.game_preview = False

        elif response == CONTINUE:
            self.your_turn()
            self.boardview.showNext()
            self.boardcontrol.game_preview = False

        elif response == BACK_TO_MAINLINE:
            self.opp_turn()
            self.boardview.backToMainLine()
            self.boardcontrol.game_preview = False

        elif response == NEXT:
            if self.gamemodel.puzzle_game:
                if self.gamemodel.from_lesson:
                    start_lesson_from(self.gamemodel.source, self.gamemodel.current_index + 1)
                else:
                    start_puzzle_from(self.gamemodel.source, self.gamemodel.current_index + 1)
            elif self.gamemodel.end_game:
                start_endgame_from(self.gamemodel.source)
            elif self.gamemodel.lesson_game:
                start_lesson_from(self.gamemodel.source, self.gamemodel.current_index + 1)
            else:
                print(self.gamemodel.__dir__())