Esempio n. 1
0
    def __init__(self, frame_skip = 2):
        
        height = 400
        width = 600
        goal_length = 300
        self.scene =  Scene(width, height)
        self.frame_skip = frame_skip
        self.ball_idle = 0
        self.ball_idle_limit = 3

        self.action_space = ActionSpace([Action.up, Action.down, Action.nomoveshoot])
       
        self.box = Box(0, width, 0, height, 0)
        self.goal1 = Goal(leftright_margin, height / 2, Way.left, goal_length)

        self.player1 = Player(80, height / 2, player_radius, player_mass, \
                                     player_restitution, player_damping, player_kick_damping, player_kick_power, Side.red)
       
       
        self.ball = Ball(width - 100, height / 2, ball_radius, ball_mass, ball_restitution, ball_damping)
        self.penalty_spot = Disc(self.ball.center.x, self.ball.center.y, 4, 0, 0, 0, Color.green).make_ghost().make_hollow()
#        self.player_border_left = VerticalBorder(50, height / 2, height, 0, visible=True)
#        self.player_border_right = VerticalBorder(100, height / 2, height, 0, visible=True)
        
        self.scene.add_object(self.goal1)
        self.scene.add_object(self.player1)
        self.scene.add_object(self.ball)
        self.scene.add_object(self.penalty_spot)
        self.scene.add_object(self.box)
        self.reset()
Esempio n. 2
0
    def __init__(self,):
        # 石や番兵を配置
        self.discs = []
        for i in range(100):
            d = Disc()
            self.discs.append(d)

        # Initialize board
        self.Initialize()
Esempio n. 3
0
    def __init__(self, arguments):
        super().__init__(arguments)

        self.mainWindow = None

        self.setOrganizationName('QtHEP')
        self.setApplicationName('QtHEP')
        QStandardPaths.setTestModeEnabled(__DEVELOPEMENT__)

        preferencesPath = QStandardPaths.writableLocation(
            QStandardPaths.AppDataLocation)
        if (not os.path.exists(preferencesPath)):
            os.makedirs(preferencesPath)
        self.preferencesFilename = os.path.join(
            preferencesPath,
            '{}.preferences.xml'.format(self.applicationName()))

        self.preferences = Preferences()
        if (os.path.exists(self.preferencesFilename)):
            self.preferences.fromXML(self.preferencesFilename)
            self.preferences.logging.initializeLog()
        else:
            self.preferences.toXML(self.preferencesFilename)

        DiscFilenameTemplatesSingleton().set(
            self.preferences.filenameTemplates)
        DiscMixdownsSingleton().set(self.preferences.mixdowns.getMixdowns())
        DiscPresetsSingleton().set(self.preferences.presets.getNames())

        self.disc = Disc(self)

        TitleVisibleSingleton().set(
            self.preferences.autoTitle.minimumTitleSeconds,
            self.disc.hideShortTitles)

        self.defaultSessionFilename = "{}.state.xml".format(
            self.applicationName())

        if __DEVELOPEMENT__:
            # 	self.settingsFilename = os.path.join(os.getcwd(), "{}.settings.xml".format(APP_NAME))
            # 	self.fullDefaultSessionFilename = os.path.join(os.getcwd(), self.defaultSessionFilename)
            s = os.path.join(os.getcwd(), 'TestFiles')
            self.temporarySessionFilename = os.path.join(
                s, "temp.{}".format(self.defaultSessionFilename))
        # 	self.logFilename = os.path.join(os.getcwd(), "{}.log".format(APP_NAME))
        else:
            if (os.path.exists(self.standardPaths.GetUserDataDir()) == False):
                os.makedirs(self.standardPaths.GetUserDataDir())
                SingletonLog().writeline('{} created'.format(
                    self.standardPaths.GetUserDataDir()))

        # 	self.settingsFilename = os.path.join(self.standardPaths.GetUserDataDir(), "{}.settings.xml".format(APP_NAME))
        # 	self.fullDefaultSessionFilename = os.path.join(self.standardPaths.GetUserDataDir(), self.defaultSessionFilename)
            self.temporarySessionFilename = os.path.join(
                self.standardPaths.GetUserDataDir(),
                "temp.{}".format(self.defaultSessionFilename))
Esempio n. 4
0
 def __init_movable(self):
     """
     MovablePos[Turns]とMovableDir[Turns]を再計算.
     """
     self.__movable_pos[self.__turns].clear()
     for y in range(1, Board.INFO.BOARD_SIZE+1):
         for x in range(1, Board.INFO.BOARD_SIZE+1):
             _disc = Disc(x, y, self.__current_color)
             _dir = self.__check_mobility(_disc)
             if _dir != Board.DIRECTION.NONE:
                 self.__movable_pos[self.__turns].append(_disc)
             self.__movable_dir[self.__turns][x][y] = _dir
Esempio n. 5
0
    def test_removing_disc_from_list(self):
        disc1 = Disc()
        length1 = len(discs)
        discs.append(disc1)
        index = discs.index(disc1)
        discs.pop(index)
        length2 = len(discs)
        discs.append(disc1)
        removing_disc_from_list(disc1)
        length3 = len(discs)

        self.assertEqual(length1, length2)
        self.assertEqual(length2, length3)
Esempio n. 6
0
    def __init__(self, random_start = True, step_limit = None, ball_idle_limit = None, state_output_mode = 'pixels', rendering = True, frame_skip=4):
        self.action_space = ActionSpace([Action.up, Action.down, Action.forward, Action.backward, Action.nomoveshoot, Action.nomove])
        self.step_limit = step_limit
        self.ball_idle_limit = ball_idle_limit
        self.state_output_mode = state_output_mode
        self.rendering = rendering
        self.ball_idle = 0
        self.step_limit = step_limit
        if state_output_mode == 'pixels': self.rendering = True
        self.step_count = 0
        self.random_start = random_start
        self.frame_skip = frame_skip
    
    
        self.scene =  Scene(c_width, c_height)
        self.scene.add_object(Box(5, c_width - 5, 5, c_height - 5, 0))
        self.scene.add_object(Disc(c_width / 2, c_height / 2, middle_field_radius, 10, 1, 1, Color.white).make_ghost().make_hollow().set_outer_color(Color.border))
        self.scene.add_object(VerticalBorder(c_width / 2, c_height / 2, c_height - 2 * topbottom_margin, None).make_ghost())


        self.scene.add_object(HorizontalBorder(c_width / 2, topbottom_margin, c_width - 2 * leftright_margin, border_restitution).extend_to(Way.up).set_collision_mask([Ball]))
        self.scene.add_object(HorizontalBorder(c_width / 2, c_height - topbottom_margin, c_width - 2 * leftright_margin, border_restitution).extend_to(Way.down).set_collision_mask([Ball]))
        self.scene.add_object(VerticalBorder(leftright_margin, (c_height / 2 - goal_length / 2 + topbottom_margin) / 2, c_height / 2 - topbottom_margin - goal_length / 2, border_restitution).extend_to(Way.left).set_collision_mask([Ball]))
        self.scene.add_object(VerticalBorder(leftright_margin, c_height - (c_height / 2 - goal_length / 2 + topbottom_margin) / 2, c_height / 2 - topbottom_margin - goal_length / 2, border_restitution).extend_to(Way.left).set_collision_mask([Ball]))
        self.scene.add_object(VerticalBorder(c_width - leftright_margin, (c_height / 2 - goal_length / 2 + topbottom_margin) / 2, c_height / 2 - topbottom_margin - goal_length / 2, border_restitution).extend_to(Way.right).set_collision_mask([Ball]))
        self.scene.add_object(VerticalBorder(c_width - leftright_margin, c_height - (c_height / 2 - goal_length / 2 + topbottom_margin) / 2, c_height / 2 - topbottom_margin - goal_length / 2, border_restitution).extend_to(Way.right).set_collision_mask([Ball]))
        
       
        self.goal1 = Goal(leftright_margin, c_height / 2, Way.left, goal_length)
        self.goal2 = Goal(c_width - leftright_margin, c_height / 2, Way.right, goal_length)
        
        self.player1 = Player(120, c_height / 2, player_radius, player_mass, \
                                     player_restitution, player_damping, player_kick_damping, player_kick_power, Side.red)
       
        self.player2 = Player(c_width - 120, c_height / 2, player_radius, player_mass, \
                                     player_restitution, player_damping, player_kick_damping, player_kick_power, Side.blue)
       
        self.ball = Ball(c_width / 2, c_height / 2, ball_radius, ball_mass, ball_restitution, ball_damping)
        
        self.scene.add_object(self.goal1)
        self.scene.add_object(self.goal2)
        self.scene.add_object(self.player1)
        self.scene.add_object(self.player2)
        self.scene.add_object(self.ball)
        
        
        self.sequence1 = StateSequence([84, 84, 4])
        self.sequence2 = StateSequence([84, 84, 4])
Esempio n. 7
0
    def is_game_over(self) -> bool:
        """
        ゲームが終了していればTrueを,終了していなければFalseを返す.

        Return:
            (bool) ゲームが終了しているか.
        """
        # 60手に達していたらゲーム終了
        if self.__turns == Board.INFO.MAX_TURNS:
            return True
        # 打てる手があるならゲーム終了ではない
        if len(self.__movable_pos[self.__turns]) != 0:
            return False

        # 現在の手番と逆の色が打てるかどうかを調べる
        for x in range(1, Board.INFO.MAX_TURNS+1):
            for y in range(1, Board.INFO.MAX_TURNS+1):
                disc = Disc(x, y, -self.__current_color)
                if self.__check_mobility(disc) != Board.DIRECTION.NONE:
                    return False
        return True
Esempio n. 8
0
    def __gameInit(self):
        if self.__discs is not None:
            self.__discs.clear()
        if self.__discStates is not None:
            self.__discStates.clear()

        for x in range(8):
            self.__discs.append(list())
            self.__discStates.append(list())
            for y in range(8):
                self.__discs[x].append(
                    Disc(self.__main,
                         width=94,
                         height=94,
                         bg="Green4",
                         highlightthickness=1,
                         highlightbackground="GRAY20"))
                self.__discs[x][y].grid(column=x, row=y)
                self.__discs[x][y].SetPoint(x, y)
                self.__discStates[x].append(
                    DiscState(self.__discs[x][y].getRelease(),
                              self.__discs[x][y].getFill()))

        self.__turn = True

        # BLACK
        self.__systemPlacing(4, 3)
        self.__systemPlacing(3, 4)

        self.__nextTurn()

        # WHITE
        self.__systemPlacing(3, 3)
        self.__systemPlacing(4, 4)

        self.__nextTurn()
Esempio n. 9
0
    def __flip_discs(self, point: Point):
        """
        pointで指定された位置に石を打ち,挟み込めるすべての石を裏返す.
        「打った石」と「裏返した石」をUpdateLogに挿入する.

        Args:
            point (Point): point
        """
        _dir = self.__movable_dir[self.__turns][point.x][point.y]
        update = []
        self.__raw_board[point.x][point.y] = self.__current_color
        update.append(Disc(point.x, point.y, self.__current_color))

        # 上
        if (_dir & Board.DIRECTION.UPPER) != Board.DIRECTION.NONE:
            _y = point.y - 1
            while self.__raw_board[point.x][_y] != self.__current_color:
                self.__raw_board[point.x][_y] = self.__current_color
                update.append(Disc(point.x, _y, self.__current_color))
                _y -= 1

        # 下
        if (_dir & Board.DIRECTION.LOWER) != Board.DIRECTION.NONE:
            _y = point.y + 1
            while self.__raw_board[point.x][_y] != self.__current_color:
                self.__raw_board[point.x][_y] = self.__current_color
                update.append(Disc(point.x, _y, self.__current_color))
                _y += 1

        # 左
        if (_dir & Board.DIRECTION.LEFT) != Board.DIRECTION.NONE:
            _x = point.x - 1
            while self.__raw_board[_x][point.y] != self.__current_color:
                self.__raw_board[_x][point.y] = self.__current_color
                update.append(Disc(_x, point.y, self.__current_color))
                _x -= 1

        # 右
        if (_dir & Board.DIRECTION.RIGHT) != Board.DIRECTION.NONE:
            _x = point.x + 1
            while self.__raw_board[_x][point.y] != self.__current_color:
                self.__raw_board[_x][point.y] = self.__current_color
                update.append(Disc(_x, point.y, self.__current_color))
                _x += 1

        # 右上
        if (_dir & Board.DIRECTION.UPPER_RIGHT) != Board.DIRECTION.NONE:
            _x, _y = point.x + 1, point.y - 1
            while self.__raw_board[_x][_y] != self.__current_color:
                self.__raw_board[_x][_y] = self.__current_color
                update.append(Disc(_x, _y, self.__current_color))
                _x, _y = _x + 1, _y - 1

        # 左上
        if (_dir & Board.DIRECTION.UPPER_LEFT) != Board.DIRECTION.NONE:
            _x, _y = point.x - 1, point.y - 1
            while self.__raw_board[_x][_y] != self.__current_color:
                self.__raw_board[_x][_y] = self.__current_color
                update.append(Disc(_x, _y, self.__current_color))
                _x, _y = _x - 1, _y - 1

        # 左下
        if (_dir & Board.DIRECTION.LOWER_LEFT) != Board.DIRECTION.NONE:
            _x, _y = point.x - 1, point.y + 1
            while self.__raw_board[_x][_y] != self.__current_color:
                self.__raw_board[_x][_y] = self.__current_color
                update.append(Disc(_x, _y, self.__current_color))
                _x, _y = _x - 1, _y + 1

        # 右下
        if (_dir & Board.DIRECTION.LOWER_RIGHT) != Board.DIRECTION.NONE:
            _x, _y = point.x + 1, point.y + 1
            while self.__raw_board[_x][_y] != self.__current_color:
                self.__raw_board[_x][_y] = self.__current_color
                update.append(Disc(_x, _y, self.__current_color))
                _x, _y = _x + 1, _y + 1

        disc_diff = len(update)

        self.__discs[self.__current_color] += disc_diff
        self.__discs[-self.__current_color] -= disc_diff - 1
        self.__discs[COLOR.EMPTY] -= 1

        self.__update_log.append(update)
Esempio n. 10
0
pygame.display.set_caption(TITLE)

screen = pygame.display.set_mode((WIDTH, HEIGHT), 0, 32)

bg = pygame.image.load(BG_PATH).convert()
bg_instruction = pygame.image.load(BG_INSTRUCTION_PATH).convert()

clock = pygame.time.Clock()
chrono = Chrono(0, 0, 0)

player1 = Mallet(PLAYER1_START, MALLET_MASS, MALLET_RED_PATH, MALLET_MAX_SPEED,
                 MALLET_ACCELERATION, MALLET_FRICTION, 1)
player2 = Mallet(PLAYER2_START, MALLET_MASS, MALLET_BLUE_PATH,
                 MALLET_MAX_SPEED, MALLET_ACCELERATION, MALLET_FRICTION, 2)

disc = Disc(DISC_START_POS, DISC_START_ANGLE, DISC_START_SPEED, DISC_MASS,
            DISC_PATH, DISC_MAX_SPEED, DISC_FRICTION)

posts = []
posts.append(
    Goalpost((BORDER_LEFT, GOAL_START), (-1, -1), GOALPOST_MASS,
             GOALPOST_PATH))
posts.append(
    Goalpost((BORDER_LEFT, GOAL_END), (-1, 1), GOALPOST_MASS, GOALPOST_PATH))
posts.append(
    Goalpost((WIDTH - BORDER_RIGHT, GOAL_START), (1, -1), GOALPOST_MASS,
             GOALPOST_PATH))
posts.append(
    Goalpost((WIDTH - BORDER_RIGHT, GOAL_END), (1, 1), GOALPOST_MASS,
             GOALPOST_PATH))

font1 = pygame.font.SysFont("Verdana", 24, True)
Esempio n. 11
0
 def _prepare_discs():
     disc1 = Disc()
     disc2 = Disc()
     disc1.disc_pos = [3, 5]
     disc2.disc_pos = [2, 4]
     return disc1, disc2